From bcc74c62562a625d4ab8baf7fb9e2afe7e5a5398 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 13 Feb 2016 18:02:20 -0500 Subject: [PATCH] Map field of invoked object too --- .../code/instructions/InvokeInterface.java | 26 ++++++++++- .../code/instructions/InvokeSpecial.java | 26 ++++++++++- .../code/instructions/InvokeVirtual.java | 29 +++++++++++- .../deobfuscators/rename/MapStaticTest.java | 46 +++++++++++++------ 4 files changed, 108 insertions(+), 19 deletions(-) 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 2ac648d3d6..3cd248027e 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 @@ -166,8 +166,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction @Override public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { + InvokeInterface otherIv = (InvokeInterface) other.getInstruction(); + List myMethods = this.getMethods(), - otherMethods = ((InvokeInterface) other.getInstruction()).getMethods(); + otherMethods = otherIv.getMethods(); assert myMethods.size() == otherMethods.size(); @@ -196,6 +198,28 @@ public class InvokeInterface extends Instruction implements InvokeInstruction } } } + + /* map field that was invoked on */ + + StackContext object1 = ctx.getPops().get(method.getNameAndType().getNumberOfArgs()), + object2 = other.getPops().get(otherIv.method.getNameAndType().getNumberOfArgs()); + + InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1); + InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2); + + if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), + gf2 = (GetFieldInstruction) base2.getInstruction(); + + Field f1 = gf1.getMyField(), + f2 = gf2.getMyField(); + + if (f1 != null && f2 != null) + { + mapping.map(f1, f2); + } + } } @Override 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 43f02068a4..740e441102 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 @@ -164,8 +164,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction @Override public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { + InvokeSpecial otherIv = (InvokeSpecial) other.getInstruction(); + List myMethods = this.getMethods(), - otherMethods = ((InvokeSpecial) other.getInstruction()).getMethods(); + otherMethods = otherIv.getMethods(); List m1 = this.myMethods; List m2 = ((InvokeSpecial) other.getInstruction()).myMethods; @@ -196,6 +198,28 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction } } } + + /* map field that was invoked on */ + + StackContext object1 = ctx.getPops().get(method.getNameAndType().getNumberOfArgs()), + object2 = other.getPops().get(otherIv.method.getNameAndType().getNumberOfArgs()); + + InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1); + InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2); + + if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), + gf2 = (GetFieldInstruction) base2.getInstruction(); + + Field f1 = gf1.getMyField(), + f2 = gf2.getMyField(); + + if (f1 != null && f2 != null) + { + mapping.map(f1, f2); + } + } } @Override 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 df7fad7ac6..e714099368 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 @@ -183,9 +183,12 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction @Override public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { - List myMethods = this.getMethods(), - otherMethods = ((InvokeVirtual) other.getInstruction()).getMethods(); + InvokeVirtual otherIv = (InvokeVirtual) other.getInstruction(); + List myMethods = this.getMethods(), + otherMethods = otherIv.getMethods(); + + assert method.getNameAndType().getDescriptor().equals(otherIv.method.getNameAndType().getDescriptor()); assert myMethods.size() == otherMethods.size(); for (int i = 0; i < myMethods.size(); ++i) @@ -222,6 +225,28 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction } } } + + /* map field that was invoked on */ + + StackContext object1 = ctx.getPops().get(method.getNameAndType().getNumberOfArgs()), + object2 = other.getPops().get(otherIv.method.getNameAndType().getNumberOfArgs()); + + InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1); + InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2); + + if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), + gf2 = (GetFieldInstruction) base2.getInstruction(); + + Field f1 = gf1.getMyField(), + f2 = gf2.getMyField(); + + if (f1 != null && f2 != null) + { + mapping.map(f1, f2); + } + } } @Override 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 d86d56b567..38af52768b 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -89,8 +89,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("class92").findMethod("method2176"); - Method m2 = group2.findClass("client").findMethod("method540"); + Method m1 = group1.findClass("class222").findMethod("method4107"); + Method m2 = group2.findClass("class222").findMethod("method3980"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); @@ -161,7 +161,7 @@ public class MapStaticTest int fields = 0, staticMethod = 0, method = 0, total = 0; for (Entry e : finalm.getMap().entrySet()) { - System.out.println(e.getKey() + " <-> " + e.getValue()); + //System.out.println(e.getKey() + " <-> " + e.getValue()); Object o = e.getKey(); if (o instanceof Field) @@ -217,6 +217,34 @@ public class MapStaticTest finalm.merge(testStaticMapperMap(group1, group2)); finalm.merge(testMapperMap(group1, group2)); + + for (int i = -1; i < 250; ++i) + { + ClassFile c1; + + if (i == -1) + { + c1 = group1.findClass("client"); + } + else + { + c1 = group1.findClass("class" + i); + } + + if (c1 == null) + continue; + + for (Method m : c1.getMethods().getMethods()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } + for (Field m : c1.getFields().getFields()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } + } summary(finalm, group1); @@ -225,18 +253,6 @@ public class MapStaticTest System.out.println("GROUP 1 " + sg1); System.out.println("GROUP 2 " + sg2); - - - 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