From 9c16bc7edede4eb05a3bef8e2a31437b02ebc62e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 5 Sep 2015 19:10:57 -0400 Subject: [PATCH] Fix methodinliner to move jumps to the function being inlined to the right place (cherry picked from commit fae040a98faa4627e4e523fc608d676735d1c06b) --- .../deob/deobfuscators/MethodInliner.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/runelite/deob/deobfuscators/MethodInliner.java b/src/main/java/net/runelite/deob/deobfuscators/MethodInliner.java index c86f15976e..37e946ce68 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/MethodInliner.java +++ b/src/main/java/net/runelite/deob/deobfuscators/MethodInliner.java @@ -111,6 +111,8 @@ public class MethodInliner implements Deobfuscator idx += descriptor.getTypeOfArg(j).getSlots(); } + Instruction firstParamStore = null; + for (int j = descriptor.size() - 1; j >= 0; --j) { Type type = descriptor.getTypeOfArg(j); @@ -151,12 +153,15 @@ public class MethodInliner implements Deobfuscator // insert storeIns before invoke instruction ins.getInstructions().add(invokeIdx++, storeIns); + + if (firstParamStore == null) + firstParamStore = storeIns; } int maxStack = code.getMaxStack() + invokedMethod.getCode().getMaxStack(); // not really right but ok code.setMaxStack(maxStack); - inline(m, i, invokedMethod, lvtIndex); + inline(m, i, invokedMethod, lvtIndex, firstParamStore); moveExceptions(m, invokedMethod); ++inlineCount; break; @@ -165,7 +170,7 @@ public class MethodInliner implements Deobfuscator return inlineCount; } - private void inline(Method method, Instruction invokeIns, Method invokeMethod, int lvtBase) + private void inline(Method method, Instruction invokeIns, Method invokeMethod, int lvtBase, Instruction firstParamStore) { Code methodCode = method.getCode(), invokeMethodCode = invokeMethod.getCode(); @@ -177,11 +182,17 @@ public class MethodInliner implements Deobfuscator Instruction nextInstruction = methodInstructions.getInstructions().get(idx + 1); - // move stuff which jumps to invokeIns to nop + // move stuff which jumps to invokeIns to firstParamStore. If there are no arguments that are stored, + // firstParamStore is null, and so create a nop instruction. - Instruction nop = new NOP(methodInstructions); - methodInstructions.getInstructions().add(idx + 1, nop); - ++idx; + if (firstParamStore == null) + { + Instruction nop = new NOP(methodInstructions); + methodInstructions.getInstructions().add(idx + 1, nop); + ++idx; + + firstParamStore = nop; + } methodInstructions.buildJumpGraph(); invokeMethodInstructions.buildJumpGraph(); @@ -191,15 +202,15 @@ public class MethodInliner implements Deobfuscator assert fromI.jump.contains(invokeIns); fromI.jump.remove(invokeIns); - fromI.replace(invokeIns, nop); + fromI.replace(invokeIns, firstParamStore); - fromI.jump.add(nop); - nop.from.add(fromI); + fromI.jump.add(firstParamStore); + firstParamStore.from.add(fromI); } invokeIns.from.clear(); for (net.runelite.deob.attributes.code.Exception e : invokeMethodCode.getExceptions().getExceptions()) - e.replace(invokeIns, nop); + e.replace(invokeIns, firstParamStore); methodInstructions.remove(invokeIns);