-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters