|
| 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