From ceafe5acec31f018e6434b07c84b71337e87fa0f Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 15 Nov 2015 21:35:35 -0500 Subject: [PATCH] Execution test is inf looping with new frame/exec stuff, dont know why. --- .../deob/deobfuscators/rename/Rename.java | 56 +++++++++---------- .../runelite/deob/execution/Execution.java | 26 ++++++--- .../net/runelite/deob/execution/Frame.java | 17 +++--- .../deob/execution/ExecutionTest.java | 10 ++++ 4 files changed, 65 insertions(+), 44 deletions(-) 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 5e7c8c6372..122c832fc0 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java @@ -129,35 +129,35 @@ public class Rename 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(); -// -// 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(); -// -// assert initial1.size() == initial2.size(); -// -// for (int i = 0; i < initial1.size(); ++i) -// { -// Method m1 = initial1.get(i), m2 = initial2.get(i); -// -// assert m1.getName().equals(m2.getName()); -// -// objMap.put(m1, m2); -// } + 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(); + + 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(); + + assert initial1.size() == initial2.size(); + + for (int i = 0; i < initial1.size(); ++i) + { + Method m1 = initial1.get(i), m2 = initial2.get(i); + + assert m1.getName().equals(m2.getName()); + + objMap.put(m1, m2); + } - process( - one.findClass("class143").findMethod("method3014"), - two.findClass("class143").findMethod("method2966") - ); +// process( +// one.findClass("class143").findMethod("method3014"), +// two.findClass("class143").findMethod("method2966") +// ); for (;;) { diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 7a85773b06..62a1774b06 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -19,8 +20,8 @@ import org.apache.commons.collections4.map.MultiValueMap; public class Execution { private ClassGroup group; - public List frames = new ArrayList<>(), - processedFrames = new ArrayList<>(); + public List frames = new LinkedList<>(), + processedFrames = new LinkedList<>(); public Set methods = new HashSet<>(); // all methods public Set executed = new HashSet<>(); // executed instructions private MultiValueMap invokes = new MultiValueMap<>(); @@ -110,7 +111,7 @@ public class Execution private void addFrame(Frame frame) { - frames.add(frame); + frames.add(0, frame); } public void invoke(InstructionContext from, Method to) @@ -123,8 +124,7 @@ public class Execution Frame f = new Frame(this, to); f.initialize(from); - frames.add(0, f); - //this.addFrame(f); + this.addFrame(f); } public void addMethod(Method to) @@ -139,13 +139,25 @@ public class Execution int fcount = 0; while (!frames.isEmpty()) { - Frame frame = frames.remove(0); + Frame frame = frames.get(0); methods.add(frame.getMethod()); ++fcount; frame.execute(); - processedFrames.add(frame); + + if (!frame.isExecuting()) + { + assert frames.get(0) == frame; + frames.remove(0); + processedFrames.add(frame); + System.out.println(fcount + "/" + frames.size()); + } + else + { + System.out.println("deferring"); + // another frame takes priority + } } System.out.println("Processed " + fcount + " frames"); diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 37e3751334..3e0d13f536 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -129,6 +129,11 @@ public class Frame { return execution; } + + public boolean isExecuting() + { + return executing; + } public Method getMethod() { @@ -201,17 +206,8 @@ public class Frame execution.executed.add(oldCur); - if (!execution.frames.isEmpty() && execution.frames.get(0) != this) - break; - processExceptions(oldCur); - if (oldCur instanceof InvokeInstruction) - { - InvokeInstruction ii = (InvokeInstruction) oldCur; - // this.prevInvokes = ii.getMethods(); - } - if (!executing) break; @@ -227,6 +223,9 @@ public class Frame { /* jump */ } + + if (!execution.frames.isEmpty() && execution.frames.get(0) != this) + break; } } diff --git a/src/test/java/net/runelite/deob/execution/ExecutionTest.java b/src/test/java/net/runelite/deob/execution/ExecutionTest.java index ae2bd8a67f..6f6b558a02 100644 --- a/src/test/java/net/runelite/deob/execution/ExecutionTest.java +++ b/src/test/java/net/runelite/deob/execution/ExecutionTest.java @@ -12,8 +12,18 @@ public class ExecutionTest { ClassGroup group = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); + System.out.println("Done loading jar " + System.currentTimeMillis() / 1000); + Execution e = new Execution(group); + //e.setBuildGraph(true); + //e.setFollowInvokes(false); e.populateInitialMethods(); e.run(); + + System.out.println("Done exec " + System.currentTimeMillis() / 1000); + + Runtime runtime = Runtime.getRuntime(); + + System.out.println("Total memory (MB) " + runtime.totalMemory()/1024L/1024L); } }