From 2e7e2d31d4f2eb2cd5dec0d13cecdde5c1ce66f1 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 8 Aug 2015 11:06:41 -0400 Subject: [PATCH] Inline static void methods with no arguments --- .../deob/attributes/code/instructions/If0.java | 2 ++ .../deob/deobfuscators/MethodInliner.java | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/info/sigterm/deob/attributes/code/instructions/If0.java b/src/main/java/info/sigterm/deob/attributes/code/instructions/If0.java index f0f111c716..b53f2d8c09 100644 --- a/src/main/java/info/sigterm/deob/attributes/code/instructions/If0.java +++ b/src/main/java/info/sigterm/deob/attributes/code/instructions/If0.java @@ -40,6 +40,8 @@ public class If0 extends Instruction implements JumpingInstruction, ComparisonIn public void write(DataOutputStream out) throws IOException { super.write(out); + assert to.getInstructions() == this.getInstructions(); + assert to.getInstructions().getInstructions().contains(to); out.writeShort(to.getPc() - this.getPc()); } diff --git a/src/main/java/info/sigterm/deob/deobfuscators/MethodInliner.java b/src/main/java/info/sigterm/deob/deobfuscators/MethodInliner.java index 5cea0c27b4..45f8f7f9db 100644 --- a/src/main/java/info/sigterm/deob/deobfuscators/MethodInliner.java +++ b/src/main/java/info/sigterm/deob/deobfuscators/MethodInliner.java @@ -77,7 +77,6 @@ public class MethodInliner implements Deobfuscator continue; // only inline methods called once // XXX do this later - System.out.println(invokedMethod.getDescriptor().getReturnValue().getType() + " " + invokedMethod.getDescriptor().size()); if (!invokedMethod.getDescriptor().getReturnValue().getType().equals("V") || invokedMethod.getDescriptor().size() != 0) continue; @@ -116,6 +115,9 @@ public class MethodInliner implements Deobfuscator fromI.jump.remove(invokeIns); fromI.replace(invokeIns, nop); + + fromI.jump.add(nop); + nop.from.add(fromI); } invokeIns.from.clear(); @@ -132,7 +134,16 @@ public class MethodInliner implements Deobfuscator // XXX I am assuming that this function leaves the stack in a clean state? // instead of return, jump to next instruction after the invoke + Instruction oldI = i; i = new Goto(methodInstructions, nextInstruction); + + i.jump.addAll(oldI.jump); + i.from.addAll(oldI.from); + + for (Instruction i2 : oldI.from) + i2.replace(oldI, i); + + oldI.from.clear(); } if (i instanceof LVTInstruction) @@ -144,10 +155,11 @@ public class MethodInliner implements Deobfuscator } methodInstructions.getInstructions().add(idx++, i); + i.setInstructions(methodInstructions); } - // old instructions go away - invokeMethodInstructions.getInstructions().clear(); + // old method goes away + invokeMethod.getMethods().removeMethod(invokeMethod); } @Override