diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 7f31a058cd..a58c7d35ca 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -46,68 +46,68 @@ public class Deob // bdur = System.currentTimeMillis() - bstart; // System.out.println("rename unique took " + bdur/1000L + " seconds"); -// // remove except RuntimeException -// bstart = System.currentTimeMillis(); -// new RuntimeExceptions().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("runtime exception took " + bdur/1000L + " seconds"); -// -// // remove unused methods -// bstart = System.currentTimeMillis(); -// new UnusedMethods().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("unused methods took " + bdur/1000L + " seconds"); -// -// new UnreachedCode().run(group); -// -// // remove illegal state exceptions, frees up some parameters -// bstart = System.currentTimeMillis(); -// new IllegalStateExceptions().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("illegal state exception took " + bdur/1000L + " seconds"); -// -// // remove constant logically dead parameters -// bstart = System.currentTimeMillis(); -// new ConstantParameter().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("constant param took " + bdur/1000L + " seconds"); -// -// // remove unhit blocks -// bstart = System.currentTimeMillis(); -// new UnreachedCode().run(group); -// //new UnusedBlocks().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("unused blocks took " + bdur/1000L + " seconds"); -// -// // remove unused parameters -// bstart = System.currentTimeMillis(); -// new UnusedParameters().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("unused params took " + bdur/1000L + " seconds"); -// -// // remove jump obfuscation -// //new Jumps().run(group); -// -// // remove unused fields -// bstart = System.currentTimeMillis(); -// new UnusedFields().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("unused fields took " + bdur/1000L + " seconds"); -// -// // remove unused methods, again? -// bstart = System.currentTimeMillis(); -// new UnusedMethods().run(group); -// bdur = System.currentTimeMillis() - bstart; -// System.out.println("unused methods took " + bdur/1000L + " seconds"); -// -// -// new MethodInliner().run(group); + // remove except RuntimeException + bstart = System.currentTimeMillis(); + new RuntimeExceptions().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("runtime exception took " + bdur/1000L + " seconds"); + + // remove unused methods + bstart = System.currentTimeMillis(); + new UnusedMethods().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("unused methods took " + bdur/1000L + " seconds"); + + new UnreachedCode().run(group); + + // remove illegal state exceptions, frees up some parameters + bstart = System.currentTimeMillis(); + new IllegalStateExceptions().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("illegal state exception took " + bdur/1000L + " seconds"); + + // remove constant logically dead parameters + bstart = System.currentTimeMillis(); + new ConstantParameter().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("constant param took " + bdur/1000L + " seconds"); + + // remove unhit blocks + bstart = System.currentTimeMillis(); + new UnreachedCode().run(group); + //new UnusedBlocks().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("unused blocks took " + bdur/1000L + " seconds"); + + // remove unused parameters + bstart = System.currentTimeMillis(); + new UnusedParameters().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("unused params took " + bdur/1000L + " seconds"); + + // remove jump obfuscation + //new Jumps().run(group); + + // remove unused fields + bstart = System.currentTimeMillis(); + new UnusedFields().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("unused fields took " + bdur/1000L + " seconds"); + + // remove unused methods, again? + bstart = System.currentTimeMillis(); + new UnusedMethods().run(group); + bdur = System.currentTimeMillis() - bstart; + System.out.println("unused methods took " + bdur/1000L + " seconds"); + + + new MethodInliner().run(group); // new ModularArithmeticDeobfuscation().run(group); // // new MethodMover().run(group); - new FieldMover().run(group); + //new FieldMover().run(group); // // new FieldInliner().run(group); diff --git a/src/main/java/net/runelite/deob/attributes/Attribute.java b/src/main/java/net/runelite/deob/attributes/Attribute.java index 71d48e8f7b..c92378223f 100644 --- a/src/main/java/net/runelite/deob/attributes/Attribute.java +++ b/src/main/java/net/runelite/deob/attributes/Attribute.java @@ -17,12 +17,15 @@ public abstract class Attribute this.type = type; } - public void load() throws IOException + public final void load() throws IOException { DataInputStream is = attributes.getStream(); this.length = is.readInt(); + this.loadAttribute(); } + public abstract void loadAttribute() throws IOException; + public final void write(DataOutputStream out) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); diff --git a/src/main/java/net/runelite/deob/attributes/Code.java b/src/main/java/net/runelite/deob/attributes/Code.java index 13d09f5104..97f9e45b4d 100644 --- a/src/main/java/net/runelite/deob/attributes/Code.java +++ b/src/main/java/net/runelite/deob/attributes/Code.java @@ -23,10 +23,8 @@ public class Code extends Attribute } @Override - public void load() throws IOException + public void loadAttribute() throws IOException { - super.load(); - DataInputStream is = this.getAttributes().getStream(); maxStack = is.readUnsignedShort(); diff --git a/src/main/java/net/runelite/deob/attributes/ConstantValue.java b/src/main/java/net/runelite/deob/attributes/ConstantValue.java index 7d76506a5b..56e61c077a 100644 --- a/src/main/java/net/runelite/deob/attributes/ConstantValue.java +++ b/src/main/java/net/runelite/deob/attributes/ConstantValue.java @@ -23,10 +23,8 @@ public class ConstantValue extends Attribute } @Override - public void load() throws IOException + public void loadAttribute() throws IOException { - super.load(); - DataInputStream is = this.getAttributes().getStream(); value = this.getAttributes().getClassFile().getPool().getEntry(is.readUnsignedShort()); } diff --git a/src/main/java/net/runelite/deob/attributes/Exceptions.java b/src/main/java/net/runelite/deob/attributes/Exceptions.java index abb7cebb35..d3542e8f84 100644 --- a/src/main/java/net/runelite/deob/attributes/Exceptions.java +++ b/src/main/java/net/runelite/deob/attributes/Exceptions.java @@ -19,10 +19,8 @@ public class Exceptions extends Attribute } @Override - public void load() throws IOException + public void loadAttribute() throws IOException { - super.load(); - DataInputStream is = this.getAttributes().getStream(); int count = is.readUnsignedShort(); diff --git a/src/main/java/net/runelite/deob/attributes/Unknown.java b/src/main/java/net/runelite/deob/attributes/Unknown.java index a790c45481..a37270b02d 100644 --- a/src/main/java/net/runelite/deob/attributes/Unknown.java +++ b/src/main/java/net/runelite/deob/attributes/Unknown.java @@ -14,10 +14,8 @@ public class Unknown extends Attribute } @Override - public void load() throws IOException + public void loadAttribute() throws IOException { - super.load(); - int len = this.getLength(); DataInputStream is = this.getAttributes().getStream(); diff --git a/src/main/java/net/runelite/deob/deobfuscators/UnusedParameters.java b/src/main/java/net/runelite/deob/deobfuscators/UnusedParameters.java index a9a351ce81..8830fafeeb 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/UnusedParameters.java +++ b/src/main/java/net/runelite/deob/deobfuscators/UnusedParameters.java @@ -114,7 +114,7 @@ public class UnusedParameters implements Deobfuscator for (InstructionContext ins : f.getInstructions()) if (!ins.getInvokes().isEmpty() && methods.containsAll(ins.getInvokes())) { - int pops = signature.size() - paramIndex - 1; // index from top of stack of parameter + int pops = signature.size() - paramIndex - 1; // index from top of stack of parameter. 0 is the last parameter ins.removeStack(pops); // remove parameter from stack if (done.contains(ins.getInstruction())) @@ -235,7 +235,10 @@ public class UnusedParameters implements Deobfuscator int[] lvtIndexes = getLvtIndexes(signature, offset); for (Method m2 : methods) + { + assert !done.contains(m2); done.add(m2); + } /* removing the parameter can't cause collisions on other (overloaded) methods because prior to this we rename * all classes/fields/methods to have unique names. diff --git a/src/main/java/net/runelite/deob/execution/InstructionContext.java b/src/main/java/net/runelite/deob/execution/InstructionContext.java index efd7dd50a3..07a6126c0a 100644 --- a/src/main/java/net/runelite/deob/execution/InstructionContext.java +++ b/src/main/java/net/runelite/deob/execution/InstructionContext.java @@ -80,6 +80,8 @@ public class InstructionContext // idx 0 is top of the stack, 1 is one under // stack contexts are added to 'pops' in the order that they are popped from the stack, StackContext ctx = pops.get(idx); + assert !ctx.removed; + ctx.removed = true; // start recursively removing return ctx.removeStack(); diff --git a/src/main/java/net/runelite/deob/execution/StackContext.java b/src/main/java/net/runelite/deob/execution/StackContext.java index 7f68b33d39..92fc0f3f93 100644 --- a/src/main/java/net/runelite/deob/execution/StackContext.java +++ b/src/main/java/net/runelite/deob/execution/StackContext.java @@ -8,6 +8,7 @@ public class StackContext public InstructionContext pushed; // instruction which pushed this public InstructionContext popped; // instruction which popped this public Type type; // type of this + public boolean removed; public StackContext(InstructionContext pushed, Type type) {