Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Animowany committed Sep 22, 2024
1 parent 669823c commit 1c94d45
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@

public class ComposedHP888Transformer extends ComposedTransformer {

public ComposedHP888Transformer(String packedEndOfFile) {
super(
HP888StringTransformer::new,
() -> new HP888PackerTransformer(packedEndOfFile),
HP888StringTransformer::new,
ComposedGeneralCleanTransformer::new,
ComposedGeneralRepairTransformer::new,
HP888StringTransformer::new,
UniversalNumberTransformer::new,
ComposedGeneralFlowTransformer::new,
DeadCodeCleanTransformer::new
);
}
public ComposedHP888Transformer(String packedEndOfFile) {
super(
HP888StringTransformer::new,
() -> new HP888PackerTransformer(packedEndOfFile),
HP888StringTransformer::new,
ComposedGeneralCleanTransformer::new,
ComposedGeneralRepairTransformer::new,
UniversalNumberTransformer::new,
ComposedGeneralFlowTransformer::new,
DeadCodeCleanTransformer::new
);
}

public ComposedHP888Transformer() {
super(
HP888StringTransformer::new,
ComposedGeneralCleanTransformer::new,
ComposedGeneralRepairTransformer::new,
HP888StringTransformer::new,
UniversalNumberTransformer::new,
ComposedGeneralFlowTransformer::new,
DeadCodeCleanTransformer::new
);
}
public ComposedHP888Transformer() {
super(
HP888StringTransformer::new,
ComposedGeneralCleanTransformer::new,
ComposedGeneralRepairTransformer::new,
UniversalNumberTransformer::new,
ComposedGeneralFlowTransformer::new,
DeadCodeCleanTransformer::new
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,49 @@

public class HP888PackerTransformer extends Transformer {

private final String endOfEncryptedFile;
private final String endOfEncryptedFile;

public HP888PackerTransformer(String endOfEncryptedFile) {
this.endOfEncryptedFile = endOfEncryptedFile;
}
public HP888PackerTransformer(String endOfEncryptedFile) {
this.endOfEncryptedFile = endOfEncryptedFile;
}

@Override
protected void transform(ClassWrapper scope, Context context) throws Exception {
Set<String> toRemove = new HashSet<>();
HashMap<String, ClassWrapper> newClasses = new HashMap<>();
Cipher cipher = Cipher.getInstance("AES");
AtomicReference<String> key = new AtomicReference<>();
@Override
protected void transform(ClassWrapper scope, Context context) throws Exception {
Set<String> toRemove = new HashSet<>();
HashMap<String, ClassWrapper> newClasses = new HashMap<>();
Cipher cipher = Cipher.getInstance("AES");

Check failure

Code scanning / SonarCloud

Encryption algorithms should be used with secure mode and padding scheme High

Use a secure padding scheme. See more on SonarCloud
AtomicReference<String> key = new AtomicReference<>();
/* Firstly you must use HP888StringTransformer, so key would be decrypted,
and it only searches in loader classes so don't tell me its bad searching. */
context.classes().stream().map(ClassWrapper::classNode).forEach(classNode -> classNode.methods.forEach(methodNode -> methodNode.instructions.forEach(abstractInsnNode -> {
if (abstractInsnNode.isString() && abstractInsnNode.asString().endsWith("==")) {
key.set(abstractInsnNode.asString());
}
})));
if (key.get().isEmpty()) {
LOGGER.error("Key not found");
return;
}
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.getDecoder().decode(key.get()), "AES"));
context.getFiles().forEach((file, bytes) -> {
if (file.endsWith(endOfEncryptedFile)) {
String cleanFileName = file.replace(endOfEncryptedFile, "").replace(".", "/");
toRemove.add(file);
try {
newClasses
.put
(cleanFileName, ClassHelper.loadClass(cleanFileName,
cipher.doFinal(bytes),
ClassReader.SKIP_FRAMES,
ClassWriter.COMPUTE_MAXS,
true));
markChange();
} catch (Exception e) {
LOGGER.error(e);
}
}
});
toRemove.forEach(context.getFiles()::remove);
context.getClasses().putAll(newClasses);
context.classes().stream().map(ClassWrapper::classNode).forEach(classNode -> classNode.methods.forEach(methodNode -> methodNode.instructions.forEach(abstractInsnNode -> {
if (abstractInsnNode.isString() && abstractInsnNode.asString().endsWith("==")) {
key.set(abstractInsnNode.asString());
}
})));
if (key.get().isEmpty()) {
LOGGER.error("Key not found");
return;
}
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.getDecoder().decode(key.get()), "AES"));
context.getFiles().forEach((file, bytes) -> {
if (file.endsWith(endOfEncryptedFile)) {
String cleanFileName = file.replace(endOfEncryptedFile, "").replace(".", "/");
toRemove.add(file);
try {
newClasses
.put
(cleanFileName, ClassHelper.loadClass(cleanFileName,
cipher.doFinal(bytes),
ClassReader.SKIP_FRAMES,
ClassWriter.COMPUTE_MAXS,
true));
markChange();
} catch (Exception e) {
LOGGER.error(e);
}
}
});
toRemove.forEach(context.getFiles()::remove);
context.getClasses().putAll(newClasses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,53 @@

public class HP888StringTransformer extends Transformer {

@Override
protected void transform(ClassWrapper scope, Context context) throws Exception {
context.classes().stream().map(ClassWrapper::classNode).forEach(classNode -> {
List<MethodNode> toRemove = new ArrayList<>();
classNode.methods.forEach(methodNode -> Arrays.stream(methodNode.instructions.toArray())
.filter(node -> node.getOpcode() == INVOKESTATIC)
.filter(node -> node.getPrevious() != null && node.getPrevious().isString())
.map(MethodInsnNode.class::cast)
.filter(node -> node.owner.equals(classNode.name))
.filter(node -> node.desc.equals("(Ljava/lang/String;)Ljava/lang/String;"))
.forEach(node -> findMethod(classNode, method -> method.name.equals(node.name) && method.desc.equals(node.desc)).ifPresent(method -> {
String string = node.getPrevious().asString();
int constantPoolSize = context.getClasses().get(getClassToPool(method).orElseThrow().getInternalName()).getConstantPool().getSize();
String class0 = classNode.name;
String class1 = classNode.name;
methodNode.instructions.remove(node.getPrevious());
methodNode.instructions.set(node, new LdcInsnNode(decrypt(string, constantPoolSize, class0.hashCode(), class1.hashCode())));
markChange();
toRemove.add(method);
})));
classNode.methods.removeAll(toRemove);
toRemove.clear();
});
}
@Override
protected void transform(ClassWrapper scope, Context context) throws Exception {
context.classes().stream().map(ClassWrapper::classNode).forEach(classNode -> {
List<MethodNode> toRemove = new ArrayList<>();
classNode.methods.forEach(methodNode -> Arrays.stream(methodNode.instructions.toArray())
.filter(node -> node.getOpcode() == INVOKESTATIC)
.filter(node -> node.getPrevious() != null && node.getPrevious().isString())
.map(MethodInsnNode.class::cast)
.filter(node -> node.owner.equals(classNode.name))
.filter(node -> node.desc.equals("(Ljava/lang/String;)Ljava/lang/String;"))
.forEach(node -> findMethod(classNode, method -> method.name.equals(node.name) && method.desc.equals(node.desc)).ifPresent(method -> {
String string = node.getPrevious().asString();
int constantPoolSize = context.getClasses().get(getClassToPool(method).orElseThrow().getInternalName()).getConstantPool().getSize();
String class0 = classNode.name;
String class1 = classNode.name;
methodNode.instructions.remove(node.getPrevious());
methodNode.instructions.set(node, new LdcInsnNode(decrypt(string, constantPoolSize, class0.hashCode(), class1.hashCode())));
markChange();
toRemove.add(method);
})));
classNode.methods.removeAll(toRemove);
toRemove.clear();
});
}

private Optional<Type> getClassToPool(MethodNode methodNode) {
return Arrays.stream(methodNode.instructions.toArray())
.filter(node -> node.getOpcode() == INVOKESTATIC)
.map(AbstractInsnNode::next)
.filter(next -> next.getOpcode() == LDC)
.filter(next -> next.next().getOpcode() == INVOKEINTERFACE)
.filter(abstractInsnNode -> abstractInsnNode instanceof LdcInsnNode)
.map(LdcInsnNode.class::cast)
.map(ldcInsnNode -> ldcInsnNode.cst)
.map(Type.class::cast)
.findFirst();
}
private Optional<Type> getClassToPool(MethodNode methodNode) {
return Arrays.stream(methodNode.instructions.toArray())
.filter(node -> node.getOpcode() == INVOKESTATIC)
.map(AbstractInsnNode::next)
.filter(next -> next.getOpcode() == LDC)
.filter(next -> next.next().getOpcode() == INVOKEINTERFACE)
.filter(abstractInsnNode -> abstractInsnNode instanceof LdcInsnNode)
.map(LdcInsnNode.class::cast)
.map(ldcInsnNode -> ldcInsnNode.cst)
.map(Type.class::cast)
.findFirst();
}

private String decrypt(String string, int constantPoolSize, int className0HashCode, int className1HashCode) {
char[] lllIlIIIllIllIIIllIlIllIl = string.toCharArray();
int llIllIIIlllllIllIIlIIlIIl = 0;
for (char IlIIlIlllIIllIIIllIIIIIll : lllIlIIIllIllIIIllIlIllIl) {
IlIIlIlllIIllIIIllIIIIIll = (char)(IlIIlIlllIIllIIIllIIIIIll ^ constantPoolSize);
IlIIlIlllIIllIIIllIIIIIll = (char)(IlIIlIlllIIllIIIllIIIIIll ^ className0HashCode);
lllIlIIIllIllIIIllIlIllIl[llIllIIIlllllIllIIlIIlIIl] = (char)(IlIIlIlllIIllIIIllIIIIIll ^ className1HashCode);
++llIllIIIlllllIllIIlIIlIIl;
}
return new String(lllIlIIIllIllIIIllIlIllIl);
private String decrypt(String string, int constantPoolSize, int className0HashCode, int className1HashCode) {
char[] lllIlIIIllIllIIIllIlIllIl = string.toCharArray();
int llIllIIIlllllIllIIlIIlIIl = 0;
for (char IlIIlIlllIIllIIIllIIIIIll : lllIlIIIllIllIIIllIlIllIl) {
IlIIlIlllIIllIIIllIIIIIll = (char) (IlIIlIlllIIllIIIllIIIIIll ^ constantPoolSize);
IlIIlIlllIIllIIIllIIIIIll = (char) (IlIIlIlllIIllIIIllIIIIIll ^ className0HashCode);
lllIlIIIllIllIIIllIlIllIl[llIllIIIlllllIllIIlIIlIIl] = (char) (IlIIlIlllIIllIIIllIIIIIll ^ className1HashCode);
++llIllIIIlllllIllIIlIIlIIl;
}
return new String(lllIlIIIllIllIIIllIlIllIl);
}
}

0 comments on commit 1c94d45

Please sign in to comment.