Skip to content

Commit 5acfda6

Browse files
committed
Remove static calculations
1 parent 9a52a15 commit 5acfda6

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.splotycode.deobfuscator.module;
2+
3+
import io.github.splotycode.deobfuscator.search.InstructionSearch;
4+
import io.github.splotycode.deobfuscator.util.InstructionUtil;
5+
import jdk.internal.org.objectweb.asm.Opcodes;
6+
import jdk.internal.org.objectweb.asm.tree.AbstractInsnNode;
7+
import jdk.internal.org.objectweb.asm.tree.ClassNode;
8+
import jdk.internal.org.objectweb.asm.tree.InsnNode;
9+
import jdk.internal.org.objectweb.asm.tree.MethodNode;
10+
11+
public class StaticCalculation extends Module implements InstructionSearch {
12+
13+
@Override
14+
public boolean transform(ClassNode classNode) {
15+
return search(classNode);
16+
}
17+
18+
@Override
19+
public boolean onInstruction(MethodNode caller, AbstractInsnNode instruction) {
20+
if (instruction instanceof InsnNode) {
21+
if (instruction.getOpcode() == Opcodes.INEG) {
22+
Integer negate = InstructionUtil.readInt(instruction.getPrevious());
23+
if (negate != null) {
24+
caller.instructions.remove(instruction.getPrevious());
25+
caller.instructions.set(instruction, InstructionUtil.getStoreIntInstruction(-negate));
26+
return true;
27+
}
28+
return false;
29+
}
30+
AbstractInsnNode rightNode = instruction.getPrevious();
31+
Integer right = InstructionUtil.readInt(rightNode);
32+
if (right != null) {
33+
AbstractInsnNode leftNode = rightNode.getPrevious();
34+
Integer left = InstructionUtil.readInt(leftNode);
35+
if (left != null) {
36+
int result;
37+
switch (instruction.getOpcode()) {
38+
case Opcodes.IXOR:
39+
result = left ^ right;
40+
break;
41+
case Opcodes.IAND:
42+
result = left & right;
43+
break;
44+
default:
45+
return false;
46+
}
47+
caller.instructions.set(instruction, InstructionUtil.getStoreIntInstruction(result));
48+
caller.instructions.remove(leftNode);
49+
caller.instructions.remove(rightNode);
50+
return true;
51+
}
52+
}
53+
}
54+
return false;
55+
}
56+
}

0 commit comments

Comments
 (0)