From 83f338a2e9a1f378c8e96ac2a8a0e5a446cddb67 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 14 Feb 2016 18:33:51 -0500 Subject: [PATCH] Dont know if this is right, but the pkt handlers at least can be picked up now. --- src/main/java/net/runelite/deob/Field.java | 1 + .../deob/attributes/code/instructions/If.java | 52 ++++++++++++++----- .../rename/ParallelExecutorMapping.java | 3 ++ .../execution/ParallellMappingExecutor.java | 13 ++--- .../deobfuscators/rename/MapStaticTest.java | 32 +++++++++++- 5 files changed, 81 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/runelite/deob/Field.java b/src/main/java/net/runelite/deob/Field.java index 4d0fdfef72..529f731505 100644 --- a/src/main/java/net/runelite/deob/Field.java +++ b/src/main/java/net/runelite/deob/Field.java @@ -26,6 +26,7 @@ public class Field private String name; private Type type; private Attributes attributes; + public boolean packetHandler; Field(Fields fields, DataInputStream is) throws IOException { 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 da4a5a0584..42b952cc1f 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 @@ -86,12 +86,26 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp ins.pop(one, two); - Frame other = frame.dup(); - other.created = this; - other.forking = ins; - other.jump(ins, to); - - ins.branch(other); + Field f1 = getComparedField(ins); + if (f1 != null && f1.getName().equals("field289")) + { + int i =5; + } +// if (f1 != null && f1.packetHandler) +// { +// assert this instanceof IfICmpNe; +// +// frame.jump(ins, to); +// } +// else + { + Frame other = frame.dup(); + other.created = this; + other.forking = ins; + other.jump(ins, to); + + ins.branch(other); + } frame.addInstructionContext(ins); } @@ -112,14 +126,20 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp @Override public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { - Frame branch1 = ctx.getBranches().get(0), - branch2 = other.getBranches().get(0); + assert ctx.getBranches().size() == other.getBranches().size(); - assert branch1.other == null; - assert branch2.other == null; - - branch1.other = branch2; - branch2.other = branch1; + // can be empty for packet handlers + if (!ctx.getBranches().isEmpty()) + { + Frame branch1 = ctx.getBranches().get(0), + branch2 = other.getBranches().get(0); + + assert branch1.other == null; + assert branch2.other == null; + + branch1.other = branch2; + branch2.other = branch1; + } this.mapArguments(mapping, ctx, other); } @@ -173,6 +193,12 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp assert f1.getType().equals(f2.getType()); mapping.map(f1, f2); + + if (f1.packetHandler && f2.packetHandler) + { + mapping.packetHandler1.add(this); + mapping.packetHandler2.add((If) other.getInstruction()); + } } private Field getComparedField(InstructionContext ctx) 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 47a9f20bf9..9175702563 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java @@ -7,6 +7,7 @@ import java.util.Map; import net.runelite.deob.ClassGroup; import net.runelite.deob.Field; import net.runelite.deob.Method; +import net.runelite.deob.attributes.code.instructions.If; public class ParallelExecutorMapping { @@ -15,6 +16,8 @@ public class ParallelExecutorMapping //private List order = new ArrayList<>(); public Method m1, m2; public boolean crashed; + public List packetHandler1 = new ArrayList<>(); + public List packetHandler2 = new ArrayList<>(); public ParallelExecutorMapping(ClassGroup group, ClassGroup group2) { diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index 2a9dd88617..c08ef61465 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -29,7 +29,7 @@ public class ParallellMappingExecutor ++count; - if (count == 65925) + if (count == 26) { int i = 5; } @@ -70,8 +70,9 @@ public class ParallellMappingExecutor // assert f2.returnTo == null; // XXX I dont know if this is right! only helps a few fields. - popStack(f1); - popStack(f2); + // XXX if a frame exits from a jump loop it would step out which might be bad + //popStack(f1); + //popStack(f2); e.frames.remove(f1); e2.frames.remove(f2); @@ -304,9 +305,9 @@ public class ParallellMappingExecutor // if (!f.getInstructions().isEmpty()) // return f; // -// InstructionContext i = f.getInstructions().get(f.getInstructions().size() - 1); -// if (!(i.getInstruction() instanceof ReturnInstruction)) -// return f; + InstructionContext i = f.getInstructions().get(f.getInstructions().size() - 1); + if (!(i.getInstruction() instanceof ReturnInstruction)) + return f; Frame r = popStackForce(f); 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 bb16f199a6..7fe47d7cc3 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -479,7 +479,8 @@ public class MapStaticTest for (Field f : exported) { Field other = (Field) mapping.get(f); - System.out.println(f + " " + other); + if (other == null) + System.out.println("missing " + f + " " + other); if (other != null) ++mapped; else ++not; } @@ -512,4 +513,33 @@ public class MapStaticTest } return list; } + + @Test + public void testPackets() throws IOException + { + ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); + ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); + + group1.findClass("client").findField("field446").packetHandler = true; + group2.findClass("client").findField("field324").packetHandler = true; + + Method m1 = group1.findClass("client").findMethod("vmethod3096"); + Method m2 = group2.findClass("client").findMethod("vmethod2975"); + + ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); + + System.out.println("BEGIN OF MAPPING"); + for (Object o : mappings.getMap().keySet()) + { + Object value = mappings.get(o); + System.out.println(o + " <-> " + value); + } + System.out.println("END OF MAPPINGS " + mappings.getMap().size()); + + System.out.println(mappings.packetHandler1.size() + " vs " + mappings.packetHandler2.size() + " handlers"); + + // I think because this is an array store + //Object other = mappings.get(group1.findClass("class136").findField("field2098")); + //Assert.assertNotNull(other); + } }