From 4ea2d8d63217a663119cd46aa6aba1747998feba Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 18 Mar 2016 16:12:04 -0400 Subject: [PATCH] Fix if field mapper to take static/class name into consideration --- .../deob/attributes/code/instructions/If.java | 60 ++++++++++++------- .../attributes/code/instructions/If0.java | 8 ++- .../rename/AnnotationMapperTest.java | 7 ++- 3 files changed, 51 insertions(+), 24 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 e5965c0ebc..e0c1e31faa 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 @@ -155,20 +155,6 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp f2.other = branch1; branch1.other = f2; - // 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); - this.mapArguments(mapping, ctx, other, true); } @@ -206,8 +192,20 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp Field f1 = f1s.get(0), f2 = f2s.get(0); Field j1 = f1s.get(1), j2 = f2s.get(1); - mapping.map(f1, j2); - mapping.map(j1, f2); + + assert !(couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2)); + + if (couldBeSame(f1, f2) && couldBeSame(j1, j2)) + { + mapping.map(f1, f2); + mapping.map(j1, f2); + } + + if (couldBeSame(f1, j2) && couldBeSame(j1, f2)) + { + mapping.map(f1, j2); + mapping.map(j1, f2); + } } else assert false; @@ -253,6 +251,18 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp return (Integer) gfi.getConstant().getObject(); } + private boolean couldBeSame(Field f1, Field f2) + { + if (f1.isStatic() != f2.isStatic()) + return false; + + if (!f1.isStatic()) + if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName())) + return false; + + return f1.getType().equals(f2.getType()); + } + protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc) { List f1s = getComparedFields(thisIc), f2s = getComparedFields(otherIc); @@ -272,15 +282,23 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp { Field f1 = f1s.get(0), f2 = f2s.get(0); Field j1 = f1s.get(1), j2 = f2s.get(1); - - return (f1.getType().equals(f2.getType()) && j1.getType().equals(j2.getType())) || - (f1.getType().equals(j2.getType()) && j1.getType().equals(f2.getType())); + + if (couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2)) + return false; // ambiguous + + if (couldBeSame(f1, f2) && couldBeSame(j1, j2)) + return true; + + if (couldBeSame(f1, j2) && couldBeSame(j1, f2)) + return true; + + return false; } else { Field f1 = f1s.get(0), f2 = f2s.get(0); - - return f1.getType().equals(f2.getType()); + + return couldBeSame(f1, f2); } } 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 30f84ac02e..8a82cb3c87 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 @@ -20,7 +20,6 @@ import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; -import net.runelite.deob.execution.Execution; public abstract class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction { @@ -202,6 +201,13 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com if (f1 == null || f2 == null) return true; + if (f1.isStatic() != f2.isStatic()) + return false; + + if (!f1.isStatic()) + if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName())) + return false; + return f1.getType().equals(f2.getType()); } diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/AnnotationMapperTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/AnnotationMapperTest.java index 5a32095e8c..611073316a 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/AnnotationMapperTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/AnnotationMapperTest.java @@ -8,8 +8,9 @@ import org.junit.Test; public class AnnotationMapperTest { - private static final String JAR1 = MapStaticTest.class.getResource("/adamin1.jar").getFile(), - JAR2 = MapStaticTest.class.getResource("/adamin2.jar").getFile(); + private static final String JAR1 = "C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar", + JAR2 = "c:/rs/gamepack_v18_deobbed.jar", + OUT = "c:/rs/adamout.jar"; @Test public void testRun() throws IOException @@ -23,6 +24,8 @@ public class AnnotationMapperTest AnnotationMapper amapper = new AnnotationMapper(group1, group2, mapping); amapper.run(); + + JarUtil.saveJar(group2, new File(OUT)); } }