diff --git a/src/main/java/info/sigterm/deob/Deob.java b/src/main/java/info/sigterm/deob/Deob.java index c76916186d..9d6543dd65 100644 --- a/src/main/java/info/sigterm/deob/Deob.java +++ b/src/main/java/info/sigterm/deob/Deob.java @@ -1,14 +1,11 @@ package info.sigterm.deob; -import info.sigterm.deob.deobfuscators.IllegalStateExceptions; -import info.sigterm.deob.deobfuscators.RuntimeExceptions; -import info.sigterm.deob.deobfuscators.UnusedFields; -import info.sigterm.deob.deobfuscators.UnusedMethods; -import info.sigterm.deob.deobfuscators.UnusedParameters; import info.sigterm.deob.deobfuscators.ConstantParameter; -import info.sigterm.deob.deobfuscators.MethodInliner; +import info.sigterm.deob.deobfuscators.IllegalStateExceptions; import info.sigterm.deob.deobfuscators.RenameUnique; +import info.sigterm.deob.deobfuscators.RuntimeExceptions; import info.sigterm.deob.deobfuscators.UnreachedCode; +import info.sigterm.deob.deobfuscators.UnusedMethods; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; diff --git a/src/main/java/info/sigterm/deob/deobfuscators/ConstantParameter.java b/src/main/java/info/sigterm/deob/deobfuscators/ConstantParameter.java index b48244c0b2..43636c2bb0 100644 --- a/src/main/java/info/sigterm/deob/deobfuscators/ConstantParameter.java +++ b/src/main/java/info/sigterm/deob/deobfuscators/ConstantParameter.java @@ -129,7 +129,7 @@ public class ConstantParameter implements Deobfuscator if (ctx.getPushed().getInstruction() instanceof PushConstantInstruction) { - PushConstantInstruction pc = (PushConstantInstruction) ctx.getPushed().getInstruction(); + PushConstantInstruction pc = (PushConstantInstruction) ctx.getPushed().getInstruction(); if (!(pc.getConstant().getObject() instanceof Number)) continue; diff --git a/src/main/java/info/sigterm/deob/execution/Frame.java b/src/main/java/info/sigterm/deob/execution/Frame.java index 71d9f7d203..336e942ca0 100644 --- a/src/main/java/info/sigterm/deob/execution/Frame.java +++ b/src/main/java/info/sigterm/deob/execution/Frame.java @@ -13,6 +13,8 @@ import info.sigterm.deob.attributes.code.Instructions; import info.sigterm.deob.attributes.code.instructions.LookupSwitch; import info.sigterm.deob.attributes.code.instructions.TableSwitch; import info.sigterm.deob.pool.NameAndType; +import java.util.HashSet; +import java.util.Set; import org.apache.commons.collections4.MultiMap; import org.apache.commons.collections4.map.MultiValueMap; @@ -60,11 +62,7 @@ public class Frame this.cur = other.cur; this.stack = new Stack(other.stack); this.variables = new Variables(other.variables); - //this.instructions = new ArrayList<>(other.instructions); // deep? this.visited = other.visited; - -// for (InstructionContext ctx : other.instructions) -// instructions.add(new InstructionContext(other, ctx)); } public Frame dup() diff --git a/src/main/java/info/sigterm/deob/execution/InstructionContext.java b/src/main/java/info/sigterm/deob/execution/InstructionContext.java index 540426dbf7..672cdf63ae 100644 --- a/src/main/java/info/sigterm/deob/execution/InstructionContext.java +++ b/src/main/java/info/sigterm/deob/execution/InstructionContext.java @@ -11,6 +11,7 @@ public class InstructionContext { private Instruction ins; private Frame frame; + private Stack stack; // stack at time ins was executed private List pops = new ArrayList<>(); // stack contexts popped by instruction execution private List pushes = new ArrayList<>(); // stack contexts pushed by instruction execution private List reads = new ArrayList<>(); // lvt reads @@ -20,6 +21,7 @@ public class InstructionContext { ins = i; frame = f; + stack = new Stack(frame.getStack()); } public void pop(StackContext... ctx) @@ -53,6 +55,11 @@ public class InstructionContext return ins; } + public Stack getStack() + { + return stack; + } + public List getPops() { return pops; @@ -90,15 +97,18 @@ public class InstructionContext if (ins != ic.ins) return false; - if (getPops().size() != ic.getPops().size()) + // check if stack at time of execution is equal + Stack ours = new Stack(this.getStack()), // copy stacks since we destroy them + theirs = new Stack(ic.getStack()); + + if (ours.getSize() != theirs.getSize()) return false; - for (int i = 0; i < getPops().size(); ++i) + while (ours.getSize() > 0) { - StackContext ours = getPops().get(i), - theirs = ic.getPops().get(i); + StackContext s1 = ours.pop(), s2 = theirs.pop(); - if (!ours.getPushed().equals(theirs.getPushed())) + if (s1.getPushed().getInstruction() != s2.getPushed().getInstruction()) return false; }