From 9a68e863bd98186b92abde70798f5c4aacf62396 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 15 Nov 2015 13:55:25 -0500 Subject: [PATCH] Begin per-method executions in rename to use less memory. Runs still with 336. --- src/main/java/net/runelite/deob/Deob.java | 1 - .../attributes/code/instructions/IInc.java | 2 +- .../deob/deobfuscators/rename/Rename.java | 38 ++++++++++++++++--- .../runelite/deob/execution/Execution.java | 23 ++++++++++- .../deob/execution/VariableContext.java | 7 ++++ 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 09d4e778ab..53cba01fa9 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -9,7 +9,6 @@ import net.runelite.deob.execution.Execution; import net.runelite.deob.util.JarUtil; // XXX something to detect final fields and evaluate them -// XXX ORDER IN WHICH FIELDS ARE ACCESSED public class Deob { diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java index 5e94c1497a..1afc4813b1 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java @@ -67,7 +67,7 @@ public class IInc extends Instruction implements LVTInstruction, WideInstruction assert vctx.getType().equals(new Type(int.class.getCanonicalName())); ins.read(vctx); - vctx = new VariableContext(ins, vctx.getStackContext()); // XXX this is probably not right. + vctx = new VariableContext(ins, vctx); var.set(index, vctx); frame.addInstructionContext(ins); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java index 8d0367c6e8..9880e79811 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java @@ -22,8 +22,10 @@ import net.runelite.deob.execution.Frame; public class Rename { + private ClassGroup groupOne, groupTwo; + // respective executions - private Execution eone, etwo; + //private Execution eone, etwo; // old -> new object mapping private Map objMap = new HashMap<>(); @@ -78,9 +80,22 @@ public class Rename private void process(Method one, Method two) { + Execution eone = new Execution(groupOne); + eone.setBuildGraph(true); + eone.setFollowInvokes(false); + eone.addMethod(one); + eone.run(); + + Execution etwo = new Execution(groupTwo); + etwo.setBuildGraph(true); + etwo.setFollowInvokes(false); + etwo.addMethod(two); + etwo.run(); + // get frames for respective methods - List f1 = eone.processedFrames.stream().filter(f -> f.getMethod() == one).collect(Collectors.toList()); - List f2 = etwo.processedFrames.stream().filter(f -> f.getMethod() == two).collect(Collectors.toList()); + List f1 = eone.processedFrames, f2 = etwo.processedFrames; + //List f1 = eone.processedFrames.stream().filter(f -> f.getMethod() == one).collect(Collectors.toList()); + //List f2 = etwo.processedFrames.stream().filter(f -> f.getMethod() == two).collect(Collectors.toList()); Frame p1 = null, p2 = null; outer: @@ -110,12 +125,19 @@ public class Rename } public void run(ClassGroup one, ClassGroup two) { - eone = new Execution(one); + groupOne = one; + groupTwo = two; + + Execution eone = new Execution(one); + eone.setBuildGraph(true); + eone.setFollowInvokes(false); eone.populateInitialMethods(); List initial1 = eone.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList()); eone.run(); - etwo = new Execution(two); + Execution etwo = new Execution(two); + etwo.setBuildGraph(true); + etwo.setFollowInvokes(false); etwo.populateInitialMethods(); List initial2 = etwo.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList()); etwo.run(); @@ -153,6 +175,12 @@ public class Rename Method m = (Method) next.get(); Method m2 = (Method) objMap.get(m); + if (m.getCode() == null || m2.getCode() == null) + { + processed.add(m); + continue; + } + System.out.println("Scanning " + m.getMethods().getClassFile().getName() + "." + m.getName() + " -> " + m2.getMethods().getClassFile().getName() + "." + m2.getName()); process(m, m2); processed.add(m); diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 0d95a4dd67..32b3fa753e 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -27,7 +27,8 @@ public class Execution private Encryption encryption; public MultiValueMap contexts = new MultiValueMap<>(); private Map methodContexts = new HashMap<>(); - private boolean buildGraph; + private boolean buildGraph; // if true the frame graph is built and execution hasJumped also compares previous instructions + private boolean followInvokes = true; public Execution(ClassGroup group) { @@ -43,6 +44,16 @@ public class Execution { this.encryption = encryption; } + + public boolean isFollowInvokes() + { + return followInvokes; + } + + public void setFollowInvokes(boolean followInvokes) + { + this.followInvokes = followInvokes; + } public List getInitialMethods() { @@ -104,6 +115,9 @@ public class Execution public void invoke(InstructionContext from, Method to) { + if (!this.isFollowInvokes()) + return; + if (hasInvoked(from, to)) return; @@ -112,6 +126,13 @@ public class Execution this.addFrame(f); } + public void addMethod(Method to) + { + Frame f = new Frame(this, to); + f.initialize(); + this.addFrame(f); + } + public void run() { int fcount = 0; diff --git a/src/main/java/net/runelite/deob/execution/VariableContext.java b/src/main/java/net/runelite/deob/execution/VariableContext.java index 9b4560e4c5..4c60dcc597 100644 --- a/src/main/java/net/runelite/deob/execution/VariableContext.java +++ b/src/main/java/net/runelite/deob/execution/VariableContext.java @@ -22,6 +22,13 @@ public class VariableContext this.type = type; } + public VariableContext(InstructionContext i, VariableContext other) + { + ic = i; + ctx = other.ctx; + type = other.type; + } + public StackContext getStackContext() { return ctx;