From cdc949abe051ff4ad7378e53c11a873b636dae81 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 12 Feb 2016 13:30:01 -0500 Subject: [PATCH] pop stack more, I dont know if this is right, but maps a couple more fields --- .../deob/attributes/code/instructions/If.java | 22 +-- .../attributes/code/instructions/If0.java | 22 +-- .../rename/MethodSignatureMapper.java | 2 +- .../rename/ParallelExecutorMapping.java | 6 +- .../execution/ParallellMappingExecutor.java | 135 +++++------------- .../deobfuscators/rename/MapStaticTest.java | 42 +++--- 6 files changed, 88 insertions(+), 141 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java index 7e17fee68a..a4586beb88 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java @@ -136,17 +136,17 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp // switch frame order in executor frame list - Execution e = f1.getExecution(), - e2 = f2.getExecution(); - - int i = e2.frames.indexOf(f2), - i2 = e2.frames.indexOf(branch2); - - e2.frames.remove(i); - e2.frames.add(i, branch2); - - e2.frames.remove(i2); - e2.frames.add(i2, f2); +// Execution e = f1.getExecution(), +// e2 = f2.getExecution(); +// +// int i = e2.frames.indexOf(f2), +// i2 = e2.frames.indexOf(branch2); +// +// e2.frames.remove(i); +// e2.frames.add(i, branch2); +// +// e2.frames.remove(i2); +// e2.frames.add(i2, f2); } @Override diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java index 08cf9b2402..7f6f4a5c42 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java @@ -139,17 +139,17 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com // switch frame order in executor frame list - Execution e = f1.getExecution(), - e2 = f2.getExecution(); - - int i = e2.frames.indexOf(f2), - i2 = e2.frames.indexOf(branch2); - - e2.frames.remove(i); - e2.frames.add(i, branch2); - - e2.frames.remove(i2); - e2.frames.add(i2, f2); +// Execution e = f1.getExecution(), +// e2 = f2.getExecution(); +// +// int i = e2.frames.indexOf(f2), +// i2 = e2.frames.indexOf(branch2); +// +// e2.frames.remove(i); +// e2.frames.add(i, branch2); +// +// e2.frames.remove(i2); +// e2.frames.add(i2, f2); } @Override diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java index 3be845f0db..bfcf70b700 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java @@ -27,7 +27,7 @@ public class MethodSignatureMapper { for (Method m : c1.getMethods().getMethods()) { - if (m.isStatic() || m.getName().equals("") || count(c1.getMethods(), m.getDescriptor()) > 1) + if (m.isStatic() || count(c1.getMethods(), m.getDescriptor()) > 1) continue; Method other = get(c2.getMethods(), m.getDescriptor()); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java b/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java index 1a6715b6af..6a894ef626 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java @@ -12,7 +12,7 @@ public class ParallelExecutorMapping { private ClassGroup group, group2; private Map map = new HashMap<>(); - private List order = new ArrayList<>(); + //private List order = new ArrayList<>(); public Method m1, m2; public ParallelExecutorMapping(ClassGroup group, ClassGroup group2) @@ -39,7 +39,7 @@ public class ParallelExecutorMapping belongs(two, group2); map.put(one, two); - order.add(one); + //order.add(one); } public Object get(Object o) @@ -52,7 +52,7 @@ public class ParallelExecutorMapping return map; } - public List getOrder() { return order; } + //public List getOrder() { return order; } private void belongs(Object o, ClassGroup to) { diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index a2fc02f307..2a9dd88617 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -51,6 +51,8 @@ public class ParallellMappingExecutor return step(); } + //assert e2.frames.contains(f2); + // assert f1.other.other == f1; // assert f2.other.other == f2; @@ -63,94 +65,16 @@ public class ParallellMappingExecutor // before realizing its already executed it before, so it will set the frame // as not executing if (!f1.isExecuting() || !f2.isExecuting()) - { -// assert f1.returnTo == null || !e.frames.contains(f1.returnTo); -// assert f2.returnTo == null || !e2.frames.contains(f2.returnTo); -// -// // get the previous instruction. if this frame is the result of a fork and there isn't any, get the fork instruction -// InstructionContext fork1 = f1.getInstructions().isEmpty() ? f1.forking : f1.getInstructions().get(f1.getInstructions().size() - 1); -// InstructionContext fork2 = f2.getInstructions().isEmpty() ? f2.forking : f2.getInstructions().get(f2.getInstructions().size() - 1); -// -// assert fork1 != null; -// assert fork2 != null; -// -// if (!(f1.getInstructions().isEmpty() == f2.getInstructions().isEmpty())) -// { -// int i = 5; -// } -// -// // Due to jump ob one side can stop while the other side jumps. So we need to remove the excess frames to keep it in line. -// -// if (fork1 == f1.forking) -// { -// // if f1 was forked, remove source frame. -// -// assert fork1.getBranches().size() == 1; -// //assert fork1.getBranches().get(0) == f1; -// -// int i1 = e.frames.indexOf(fork1.getFrame()); // this might be -1 because it is now in an invokestatic. AHhh. -// if (i1 == -1) -// { -// i1 = e.frames.indexOf(fork1.getFrame().returnTo); -// //XXX returnframes are diff objects is why? -// } -// int i2 = e.frames.indexOf(fork1.getBranches().get(0)); -// -// // remove fork1.frame -// e.frames.remove(fork1.getFrame()); -// //e.frames.remove(fork1.getBranches().get(0)); -// } -// else -// { -// //p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); -// -// for (Frame branch : fork1.getBranches()) -// { -// e.frames.remove(branch); -// } -// } -// -// // this is empty but should be removing a branch, because of the map other, theres no prev instruction. -// // should always populate prev instruction -// //if (f2.getInstructions().size() > 0) -// if (fork2 == f2.forking) -// { -// assert fork2.getBranches().size() == 1; -// //assert fork2.getBranches().get(0) == f2; -// -// int i1 = e2.frames.indexOf(fork2.getFrame()); -// int i2 = e2.frames.indexOf(fork2.getBranches().get(0)); -// -// e2.frames.remove(fork2.getFrame()); -// //e.frames.remove(fork2.getBranches().get(0)); -// } -// else -// { -// //p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); -// -// for (Frame branch : fork2.getBranches()) -// { -// e2.frames.remove(branch); -// } -// } + { +// assert f1.returnTo == null; +// assert f2.returnTo == null; - //assert e.frames.get(0) == f1; - //assert e2.frames.get(0) == f2; + // XXX I dont know if this is right! only helps a few fields. + popStack(f1); + popStack(f2); e.frames.remove(f1); e2.frames.remove(f2); - -// Frame f1wtf = e.frames.get(0), -// f2wtf = e2.frames.get(0); -// -// int otherIndex1 = e2.frames.indexOf(f1wtf.other), -// otherIndex2 = e.frames.indexOf(f2wtf.other); -// -// // assert f1wtf.other.other == f1wtf; -// // assert f2wtf.other.other == f2wtf; -// -// assert f1wtf.other == f2wtf; -// assert f2wtf.other == f1wtf; step1 = step2 = true; @@ -344,10 +268,17 @@ public class ParallellMappingExecutor f2.created = is; f2.initialize(i); - assert e.frames.contains(f); - int idx = e.frames.indexOf(f); - e.frames.remove(f); // old frame goes away - e.frames.add(idx, f2); +// assert e.frames.contains(f); + if (e.frames.contains(f)) + { + int idx = e.frames.indexOf(f); + e.frames.remove(f); // old frame goes away + e.frames.add(idx, f2); + } + else + { + e.frames.add(f); + } assert f.other.other == f; @@ -370,9 +301,12 @@ public class ParallellMappingExecutor if (f.isExecuting() || f.returnTo == null) return f; - InstructionContext i = f.getInstructions().get(f.getInstructions().size() - 1); - if (!(i.getInstruction() instanceof ReturnInstruction)) - return f; +// if (!f.getInstructions().isEmpty()) +// return f; +// +// InstructionContext i = f.getInstructions().get(f.getInstructions().size() - 1); +// if (!(i.getInstruction() instanceof ReturnInstruction)) +// return f; Frame r = popStackForce(f); @@ -390,14 +324,21 @@ public class ParallellMappingExecutor assert f.returnTo != null; - assert e.frames.contains(f); + //assert e.frames.contains(f); assert !e.frames.contains(f.returnTo); - // replace frame with returnTo - int idx = e.frames.indexOf(f); - e.frames.remove(f); - assert !e.frames.contains(f.returnTo); - e.frames.add(idx, f.returnTo); + if (e.frames.contains(f)) + { + // replace frame with returnTo + int idx = e.frames.indexOf(f); + e.frames.remove(f); + assert !e.frames.contains(f.returnTo); + e.frames.add(idx, f.returnTo); + } + else + { + e.frames.add(f.returnTo); + } assert f.other.other == f; assert f.returnTo.other == null; diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java index f84d49f6e4..cf4cdfffd8 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -88,13 +88,13 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("client").findMethod("vmethod3054"); - Method m2 = group2.findClass("client").findMethod("vmethod2973"); + Method m1 = group1.findClass("class92").findMethod("method2176"); + Method m2 = group2.findClass("client").findMethod("method540"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); System.out.println("BEGIN OF MAPPING"); - for (Object o : mappings.getOrder()) + for (Object o : mappings.getMap().keySet()) { Object value = mappings.get(o); System.out.println(o + " <-> " + value); @@ -116,8 +116,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("client").findMethod("vmethod3096"); - Method m2 = group2.findClass("client").findMethod("vmethod2975"); + Method m1 = group1.findClass("class92").findMethod("method2176"); + Method m2 = group2.findClass("client").findMethod("method540"); HashMap all = new HashMap(); List pmes = new ArrayList<>(); @@ -127,7 +127,13 @@ public class MapStaticTest for (ParallelExecutorMapping pme : pmes) finalm.merge(pme); - //summary(finalm); + System.out.println("BEGIN OF MAPPING"); + for (Object o : finalm.getMap().keySet()) + { + Object value = finalm.get(o); + System.out.println(o + " <-> " + value); + } + System.out.println("END OF MAPPINGS " + finalm.getMap().size()); } //@Test @@ -237,18 +243,18 @@ public class MapStaticTest System.out.println("GROUP 1 " + sg1); System.out.println("GROUP 2 " + sg2); -// System.out.println("db step " + ParallellMappingExecutor.doubleStep.size()); -// -// for (Method m : group1.findClass("client").getMethods().getMethods()) -// { -// if (!finalm.getMap().containsKey(m) && !m.isStatic()) -// System.out.println("missing " + m); -// } -// for (Field m : group1.findClass("client").getFields().getFields()) -// { -// if (!finalm.getMap().containsKey(m)) -// System.out.println("missing " + m); -// } + + + for (Method m : group1.findClass("client").getMethods().getMethods()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } + for (Field m : group1.findClass("client").getFields().getFields()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } } //@Test