forked from java-deobfuscator/deobfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
250 additions
and
7 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
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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/javadeobfuscator/deobfuscator/rules/stringer/RuleStringDecryptorV3.java
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2018 Sam Sun <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.javadeobfuscator.deobfuscator.rules.stringer; | ||
|
||
import com.javadeobfuscator.deobfuscator.*; | ||
import com.javadeobfuscator.deobfuscator.rules.*; | ||
import com.javadeobfuscator.deobfuscator.transformers.*; | ||
import com.javadeobfuscator.deobfuscator.transformers.stringer.v9.*; | ||
import com.javadeobfuscator.deobfuscator.utils.*; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import java.util.*; | ||
|
||
public class RuleStringDecryptorV3 implements Rule { | ||
@Override | ||
public String getDescription() { | ||
return "This variant of Stringer's string decryptor makes use of invokedynamic obfuscation within the string decryption classes"; | ||
} | ||
|
||
@Override | ||
public String test(Deobfuscator deobfuscator) { | ||
for (ClassNode classNode : deobfuscator.getClasses().values()) { | ||
for (MethodNode methodNode : classNode.methods) { | ||
if (!TransformerHelper.basicType(methodNode.desc).equals("(Ljava/lang/Object;III)Ljava/lang/Object;")) { | ||
continue; | ||
} | ||
|
||
boolean isStringer = true; | ||
|
||
isStringer = isStringer && TransformerHelper.containsInvokeStatic(methodNode, "java/lang/Thread", "currentThread", "()Ljava/lang/Thread;"); | ||
isStringer = isStringer && TransformerHelper.containsInvokeVirtual(methodNode, "java/lang/Thread", "getStackTrace", "()[Ljava/lang/StackTraceElement;"); | ||
isStringer = isStringer && TransformerHelper.countOccurencesOf(methodNode, IAND) > 20; | ||
isStringer = isStringer && TransformerHelper.countOccurencesOf(methodNode, IXOR) > 20; | ||
isStringer = isStringer && TransformerHelper.countOccurencesOf(methodNode, IUSHR) > 10; | ||
isStringer = isStringer && TransformerHelper.countOccurencesOf(methodNode, ISHL) > 10; | ||
|
||
if (!isStringer) { | ||
continue; | ||
} | ||
|
||
return "Found possible string decryption class " + classNode.name; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<Class<? extends Transformer>> getRecommendTransformers() { | ||
return Collections.singleton(StringEncryptionTransformer.class); | ||
} | ||
} |
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
102 changes: 102 additions & 0 deletions
102
...m/javadeobfuscator/deobfuscator/transformers/stringer/v9/StringEncryptionTransformer.java
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2018 Sam Sun <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.javadeobfuscator.deobfuscator.transformers.stringer.v9; | ||
|
||
import com.javadeobfuscator.deobfuscator.config.*; | ||
import com.javadeobfuscator.deobfuscator.matcher.*; | ||
import com.javadeobfuscator.deobfuscator.transformers.*; | ||
import com.javadeobfuscator.deobfuscator.transformers.stringer.v9.utils.*; | ||
import com.javadeobfuscator.deobfuscator.utils.*; | ||
import com.javadeobfuscator.javavm.*; | ||
import com.javadeobfuscator.javavm.exceptions.*; | ||
import org.objectweb.asm.*; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import java.util.*; | ||
|
||
public class StringEncryptionTransformer extends Transformer<TransformerConfig> implements Opcodes { | ||
@Override | ||
public boolean transform() throws Throwable { | ||
VirtualMachine vm = TransformerHelper.newVirtualMachine(this); | ||
|
||
// vm.beforeCallHooks.add(info -> { | ||
// if (!info.is("java/lang/Class", "forName0", "(Ljava/lang/String;ZLjava/lang/ClassLoader;Ljava/lang/Class;)Ljava/lang/Class;")) { | ||
// return; | ||
// } | ||
// List<StackTraceHolder> stacktrace = vm.getStacktrace(); | ||
// if (stacktrace.size() < 3) { | ||
// return; | ||
// } | ||
// if (!classes.containsKey(stacktrace.get(2).getClassNode().name)) { | ||
// return; | ||
// } | ||
// info.getParams().set(1, vm.newBoolean(false)); | ||
// }); | ||
|
||
int decrypted = 0; | ||
|
||
for (ClassNode classNode : classes.values()) { | ||
for (MethodNode methodNode : new ArrayList<>(classNode.methods)) { | ||
InstructionModifier modifier = new InstructionModifier(); | ||
|
||
Map<LabelNode, LabelNode> cloneMap = Utils.generateCloneMap(methodNode.instructions); | ||
|
||
for (AbstractInsnNode insn : TransformerHelper.instructionIterator(methodNode)) { | ||
InstructionMatcher matcher = Constants.DECRYPT_PATTERN.matcher(insn); | ||
if (!matcher.find()) { | ||
continue; | ||
} | ||
|
||
MethodNode decryptorMethod = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, methodNode.name, "()Ljava/lang/String;", null, null); | ||
for (AbstractInsnNode matched : matcher.getCapturedInstructions("all")) { | ||
decryptorMethod.instructions.add(matched.clone(cloneMap)); | ||
} | ||
decryptorMethod.instructions.add(new InsnNode(ARETURN)); | ||
|
||
classNode.methods.add(decryptorMethod); | ||
try { | ||
MethodExecution result = vm.execute(classNode, decryptorMethod); | ||
classNode.methods.remove(decryptorMethod); | ||
|
||
String decryptedStr = vm.convertJavaObjectToString(result.getReturnValue()); | ||
|
||
logger.debug("Decrypted {} {}{}, {}", classNode.name, methodNode.name, methodNode.desc, decryptedStr); | ||
decrypted++; | ||
|
||
modifier.removeAll(matcher.getCapturedInstructions("all")); | ||
modifier.replace(matcher.getEnd(), new LdcInsnNode(decryptedStr)); | ||
} catch (VMException e) { | ||
TransformerHelper.dumpMethod(decryptorMethod); | ||
vm.convertException(e).printStackTrace(); | ||
return false; | ||
} catch (Throwable t) { | ||
TransformerHelper.dumpMethod(decryptorMethod); | ||
t.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
|
||
modifier.apply(methodNode); | ||
} | ||
} | ||
|
||
vm.shutdown(); | ||
|
||
logger.info("Decrypted {} strings", decrypted); | ||
return true; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...main/java/com/javadeobfuscator/deobfuscator/transformers/stringer/v9/utils/Constants.java
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2018 Sam Sun <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.javadeobfuscator.deobfuscator.transformers.stringer.v9.utils; | ||
|
||
import com.javadeobfuscator.deobfuscator.matcher.*; | ||
import org.objectweb.asm.*; | ||
|
||
public class Constants implements Opcodes { | ||
public static final InstructionPattern DECRYPT_PATTERN = new InstructionPattern( | ||
new OpcodeStep(LDC), | ||
new InvocationStep(INVOKEVIRTUAL, "java/lang/String", "toCharArray", "()[C", false), | ||
new OpcodeStep(DUP), | ||
new OpcodeStep(DUP), | ||
new LoadIntStep(), | ||
new OpcodeStep(DUP_X1), | ||
new OpcodeStep(CALOAD), | ||
new LoadIntStep(), | ||
new OpcodeStep(IXOR), | ||
new OpcodeStep(I2C), | ||
new OpcodeStep(CASTORE), | ||
new LoadIntStep(), | ||
new LoadIntStep(), | ||
new OpcodeStep(ISHL), | ||
new LoadIntStep(), | ||
new OpcodeStep(IOR), | ||
new LoadIntStep(), | ||
new LoadIntStep(), | ||
new InvocationStep(INVOKESTATIC, null, null, "(Ljava/lang/Object;III)Ljava/lang/Object;", true) | ||
); | ||
} |
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