From 2854abfb080934c4dbb3b248832f894e7771a7ba Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 5 Feb 2016 20:22:13 -0500 Subject: [PATCH] init field order fix --- .../code/instruction/types/MappableInstruction.java | 2 +- .../runelite/deob/attributes/code/instructions/If.java | 2 +- .../deob/attributes/code/instructions/If0.java | 2 +- .../deob/attributes/code/instructions/IfNe.java | 4 ++-- .../attributes/code/instructions/InvokeInterface.java | 2 +- .../attributes/code/instructions/InvokeSpecial.java | 2 +- .../attributes/code/instructions/InvokeStatic.java | 2 +- .../attributes/code/instructions/InvokeVirtual.java | 2 +- .../deob/attributes/code/instructions/PutField.java | 7 ++++++- .../deob/attributes/code/instructions/PutStatic.java | 2 +- .../deob/deobfuscators/rename/MappingException.java | 6 ++++++ .../deob/deobfuscators/rename/MappingExecutorUtil.java | 5 ++--- src/main/java/net/runelite/deob/execution/Frame.java | 2 +- .../deob/deobfuscators/rename/MapStaticTest.java | 10 +++++----- 14 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 src/main/java/net/runelite/deob/deobfuscators/rename/MappingException.java diff --git a/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java b/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java index e3cd78ab4a..f884363550 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java +++ b/src/main/java/net/runelite/deob/attributes/code/instruction/types/MappableInstruction.java @@ -9,5 +9,5 @@ public interface MappableInstruction boolean isSame(InstructionContext thisIc, InstructionContext otherIc); - boolean canMap(); + boolean canMap(InstructionContext thisIc); } 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 d0a1e2eb5b..7e17fee68a 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 @@ -156,7 +156,7 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return true; } 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 8914b64969..08cf9b2402 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 @@ -159,7 +159,7 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return true; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java index 77632d57be..a68dfe5481 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java @@ -21,7 +21,7 @@ public class IfNe extends If0 if (super.isSame(thisIc, otherIc)) return true; - if (otherIc.getInstruction() instanceof IfICmpNe) + if (otherIc.getInstruction() instanceof IfICmpNe || otherIc.getInstruction() instanceof IfICmpEq) { // check for one side being 0 StackContext s1 = otherIc.getPops().get(0), @@ -59,7 +59,7 @@ public class IfNe extends If0 @Override public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { - if (other.getInstruction() instanceof IfEq) + if (other.getInstruction() instanceof IfEq || other.getInstruction() instanceof IfICmpEq) { super.mapOtherBranch(mapping, ctx, other); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index dcdb4a2115..5d509854c4 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -180,7 +180,7 @@ public class InvokeInterface extends Instruction implements InvokeInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return MappingExecutorUtil.isMappable(this); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index cf1503e76e..6b63c6c1c3 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -181,7 +181,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return MappingExecutorUtil.isMappable(this); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index 52b23b3f44..7ed1133e68 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -183,7 +183,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return MappingExecutorUtil.isMappable(this); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java index e7d0a387b9..4cc24c5507 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java @@ -203,7 +203,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return MappingExecutorUtil.isMappable(this); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java index 3b1f2525f9..008958da53 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java @@ -130,8 +130,13 @@ public class PutField extends Instruction implements SetFieldInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { + StackContext value = thisIc.getPops().get(0); + Instruction i = value.getPushed().getInstruction(); + if (thisIc.getFrame().getMethod().getName().equals("")) + if (i instanceof PushConstantInstruction || i instanceof AConstNull) + return false; return true; } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java index 3f2cb7584b..da493153f0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java @@ -112,7 +112,7 @@ public class PutStatic extends Instruction implements SetFieldInstruction } @Override - public boolean canMap() + public boolean canMap(InstructionContext thisIc) { return true; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingException.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingException.java new file mode 100644 index 0000000000..157c8c9dee --- /dev/null +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingException.java @@ -0,0 +1,6 @@ +package net.runelite.deob.deobfuscators.rename; + +public class MappingException extends Exception +{ + +} diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java index a17b9a3a6a..361c860eca 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -59,7 +59,7 @@ public class MappingExecutorUtil return map1.equals(map2); } - public static ParallelExecutorMapping map(Method m1, Method m2) + public static ParallelExecutorMapping map(Method m1, Method m2) throws MappingException { ClassGroup group1 = m1.getMethods().getClassFile().getGroup(); ClassGroup group2 = m2.getMethods().getClassFile().getGroup(); @@ -103,9 +103,8 @@ public class MappingExecutorUtil if (!mi1.isSame(p1, p2)) { - assert mi1.isSame(p1, p2); + throw new MappingException(); } - //assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass()); mi1.map(mappings, p1, p2); diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index b8669376c4..8984ee7267 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -257,7 +257,7 @@ public class Frame if (execution.step && oldCur instanceof MappableInstruction) { MappableInstruction mi = (MappableInstruction) oldCur; - if (mi.canMap()) + if (mi.canMap(ictx)) { execution.paused = true; return; 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 fc511d6207..87fe947fe9 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -63,7 +63,7 @@ public class MapStaticTest // } @Test - public void testAll() throws IOException + public void testAll() throws IOException, MappingException { ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); @@ -80,7 +80,7 @@ public class MapStaticTest } @Test - public void test() throws IOException + public void test() throws IOException, MappingException { ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); @@ -103,7 +103,7 @@ public class MapStaticTest //Assert.assertNotNull(other); } - private static boolean test; + private static boolean test = true; @Test public void testDeep() throws IOException @@ -220,8 +220,8 @@ public class MapStaticTest catch (Throwable ex) { System.err.println("Error mapping " + m1 + " to " + m2); - if (test) - throw ex; + //if (test) + // throw ex; return; }