From cbe45eddfe1e4c34da89ca91971c5378ad889098 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 30 Jan 2016 15:56:36 -0500 Subject: [PATCH] Keep real type of stack contexts, which I think I need later. Exec test passes, not sure of other implications of this. --- .../code/instructions/GetField.java | 2 +- .../code/instructions/GetStatic.java | 2 +- .../attributes/code/instructions/IInc.java | 2 +- .../attributes/code/instructions/ILoad.java | 2 +- .../attributes/code/instructions/ILoad_0.java | 2 +- .../attributes/code/instructions/ILoad_1.java | 2 +- .../attributes/code/instructions/ILoad_2.java | 2 +- .../attributes/code/instructions/ILoad_3.java | 2 +- .../attributes/code/instructions/IStore.java | 2 +- .../code/instructions/IStore_0.java | 2 +- .../code/instructions/IStore_1.java | 2 +- .../code/instructions/IStore_2.java | 2 +- .../code/instructions/IStore_3.java | 2 +- .../code/instructions/InvokeInterface.java | 2 +- .../code/instructions/InvokeSpecial.java | 2 +- .../code/instructions/InvokeStatic.java | 2 +- .../code/instructions/InvokeVirtual.java | 2 +- .../net/runelite/deob/execution/Frame.java | 2 +- .../net/runelite/deob/execution/Type.java | 9 ++++-- .../deob/execution/ExecutionTest.java | 28 ++++++++++--------- 20 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java index c751ba903f..2d33534d8c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java @@ -52,7 +52,7 @@ public class GetField extends Instruction implements GetFieldInstruction StackContext object = stack.pop(); ins.pop(object); - StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType(), Value.NULL); + StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java index 704161d3c5..a6162e246f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java @@ -56,7 +56,7 @@ public class GetStatic extends Instruction implements GetFieldInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType(), Value.NULL); + StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()), Value.NULL); stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java index dd6c1efffb..3684fffbb0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IInc.java @@ -65,7 +65,7 @@ public class IInc extends Instruction implements LVTInstruction, WideInstruction Variables var = frame.getVariables(); VariableContext vctx = var.get(index); - assert vctx.getType().equals(new Type(int.class.getCanonicalName())); + assert vctx.getType().isInt(); ins.read(vctx); Value value = vctx.getValue(); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java index 3ae70500b5..036ecc127f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad.java @@ -70,7 +70,7 @@ public class ILoad extends Instruction implements LVTInstruction, WideInstructio Variables variables = frame.getVariables(); VariableContext vctx = variables.get(index); - assert vctx.getType().equals(new Type(int.class.getName())); + assert vctx.getType().isInt(); ins.read(vctx); StackContext ctx = new StackContext(ins, vctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java index f075e5b614..034406c7da 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_0.java @@ -29,7 +29,7 @@ public class ILoad_0 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); VariableContext vctx = variables.get(0); - assert vctx.getType().equals(new Type(int.class.getName())); + assert vctx.getType().isInt(); ins.read(vctx); StackContext ctx = new StackContext(ins, vctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java index 3b944a1701..e4e16c1349 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_1.java @@ -29,7 +29,7 @@ public class ILoad_1 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); VariableContext vctx = variables.get(1); - assert vctx.getType().equals(new Type(int.class.getName())); + assert vctx.getType().isInt(); ins.read(vctx); StackContext ctx = new StackContext(ins, vctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java index 70fbf70839..f0cf9603f9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_2.java @@ -29,7 +29,7 @@ public class ILoad_2 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); VariableContext vctx = variables.get(2); - assert vctx.getType().equals(new Type(int.class.getName())); + assert vctx.getType().isInt(); ins.read(vctx); StackContext ctx = new StackContext(ins, vctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java index 4d8a0740fa..ed842bc006 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ILoad_3.java @@ -29,7 +29,7 @@ public class ILoad_3 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); VariableContext vctx = variables.get(3); - assert vctx.getType().equals(new Type(int.class.getName())); + assert vctx.getType().isInt(); ins.read(vctx); StackContext ctx = new StackContext(ins, vctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore.java index 3283bbabeb..a51c9f2697 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore.java @@ -55,7 +55,7 @@ public class IStore extends Instruction implements LVTInstruction, WideInstructi Variables variables = frame.getVariables(); StackContext value = stack.pop(); - assert value.getType().equals(new Type(int.class.getName())); + assert value.getType().isInt(); ins.pop(value); variables.set(index, new VariableContext(ins, value)); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_0.java index 796eb0d53f..186912a245 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_0.java @@ -34,7 +34,7 @@ public class IStore_0 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); StackContext value = stack.pop(); - assert value.getType().equals(new Type(int.class.getName())); + assert value.getType().isInt(); ins.pop(value); variables.set(0, new VariableContext(ins, value)); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_1.java index 23b58b31f9..af4b438918 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_1.java @@ -34,7 +34,7 @@ public class IStore_1 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); StackContext value = stack.pop(); - assert value.getType().equals(new Type(int.class.getName())); + assert value.getType().isInt(); ins.pop(value); variables.set(1, new VariableContext(ins, value)); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_2.java index 944e74ba89..c81c9d434e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_2.java @@ -34,7 +34,7 @@ public class IStore_2 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); StackContext value = stack.pop(); - assert value.getType().equals(new Type(int.class.getName())); + assert value.getType().isInt(); ins.pop(value); variables.set(2, new VariableContext(ins, value)); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_3.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_3.java index a066e46ab6..fe5b6854f9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_3.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IStore_3.java @@ -29,7 +29,7 @@ public class IStore_3 extends Instruction implements LVTInstruction Variables variables = frame.getVariables(); StackContext value = stack.pop(); - assert value.getType().equals(new Type(int.class.getName())); + assert value.getType().isInt(); ins.pop(value); variables.set(3, new VariableContext(ins, value)); 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 981534b5f7..5e92c88f1f 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 @@ -92,7 +92,7 @@ public class InvokeInterface extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { StackContext ctx = new StackContext(ins, - new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + new Type(method.getNameAndType().getDescriptor().getReturnValue()), Value.NULL ); stack.push(ctx); 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 5ecfae0c77..2942721269 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 @@ -77,7 +77,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { StackContext ctx = new StackContext(ins, - new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + new Type(method.getNameAndType().getDescriptor().getReturnValue()), Value.NULL ); stack.push(ctx); 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 c65c0ccc4f..ced225a714 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 @@ -87,7 +87,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { StackContext ctx = new StackContext(ins, - new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + new Type(method.getNameAndType().getDescriptor().getReturnValue()), Value.NULL ); stack.push(ctx); 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 a9269f6495..e7d0a387b9 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 @@ -79,7 +79,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction if (!method.getNameAndType().isVoid()) { StackContext ctx = new StackContext(ins, - new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType(), + new Type(method.getNameAndType().getDescriptor().getReturnValue()), Value.NULL ); stack.push(ctx); diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 6e55018c69..45b7ddf90b 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -64,7 +64,7 @@ public class Frame NameAndType nat = method.getNameAndType(); for (int i = 0; i < nat.getNumberOfArgs(); ++i) { - variables.set(pos, new VariableContext(new Type(nat.getDescriptor().getTypeOfArg(i)).toStackType()).markParameter()); + variables.set(pos, new VariableContext(new Type(nat.getDescriptor().getTypeOfArg(i))).markParameter()); pos += nat.getDescriptor().getTypeOfArg(i).getSlots(); } diff --git a/src/main/java/net/runelite/deob/execution/Type.java b/src/main/java/net/runelite/deob/execution/Type.java index 29e376c23e..91e113f001 100644 --- a/src/main/java/net/runelite/deob/execution/Type.java +++ b/src/main/java/net/runelite/deob/execution/Type.java @@ -17,8 +17,8 @@ public class Type for (int i = 0; i < t.getArrayDims(); ++i) type = type + "[]"; } - - public Type toStackType() + + private Type toStackType() { if (type.equals(byte.class.getCanonicalName()) || type.equals(char.class.getCanonicalName()) || type.equals(short.class.getCanonicalName()) || type.equals(boolean.class.getCanonicalName())) @@ -26,6 +26,11 @@ public class Type return this; } + public boolean isInt() + { + return toStackType().equals(new Type(int.class.getName())); + } + private static String asmTypeToClass(String type) { switch (type) diff --git a/src/test/java/net/runelite/deob/execution/ExecutionTest.java b/src/test/java/net/runelite/deob/execution/ExecutionTest.java index 6f6b558a02..de77cd4d5e 100644 --- a/src/test/java/net/runelite/deob/execution/ExecutionTest.java +++ b/src/test/java/net/runelite/deob/execution/ExecutionTest.java @@ -2,28 +2,30 @@ package net.runelite.deob.execution; import java.io.File; import net.runelite.deob.ClassGroup; +import net.runelite.deob.deobfuscators.rename.MapStaticTest; import net.runelite.deob.util.JarUtil; import org.junit.Test; public class ExecutionTest { + private static final String JAR1 = MapStaticTest.class.getResource("/adamin1.jar").getFile(), + JAR2 = MapStaticTest.class.getResource("/adamin2.jar").getFile(); + @Test public void test() throws Exception { - ClassGroup group = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); - - System.out.println("Done loading jar " + System.currentTimeMillis() / 1000); - - Execution e = new Execution(group); - //e.setBuildGraph(true); - //e.setFollowInvokes(false); + ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); + Execution e = new Execution(group1); + e.populateInitialMethods(); + e.run(); + } + + @Test + public void test2() throws Exception + { + ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); + Execution e = new Execution(group2); e.populateInitialMethods(); e.run(); - - System.out.println("Done exec " + System.currentTimeMillis() / 1000); - - Runtime runtime = Runtime.getRuntime(); - - System.out.println("Total memory (MB) " + runtime.totalMemory()/1024L/1024L); } }