From 6f6fd5150920ed2f403ad4b4d8230e647a175174 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 3 Oct 2015 00:36:30 -0400 Subject: [PATCH] Split datastream loading from classfile to prepare for tests --- .../java/net/runelite/deob/ClassFile.java | 24 +++--- .../java/net/runelite/deob/ClassGroup.java | 5 ++ .../java/net/runelite/deob/ConstantPool.java | 4 +- src/main/java/net/runelite/deob/Deob.java | 86 +++++++++---------- src/main/java/net/runelite/deob/Field.java | 5 +- src/main/java/net/runelite/deob/Fields.java | 11 ++- .../java/net/runelite/deob/Interfaces.java | 4 +- src/main/java/net/runelite/deob/Method.java | 5 +- src/main/java/net/runelite/deob/Methods.java | 11 ++- .../runelite/deob/attributes/Attribute.java | 7 +- .../runelite/deob/attributes/Attributes.java | 24 +++--- .../net/runelite/deob/attributes/Code.java | 10 +-- .../deob/attributes/ConstantValue.java | 3 +- .../runelite/deob/attributes/Exceptions.java | 4 +- .../net/runelite/deob/attributes/Unknown.java | 3 +- .../deob/attributes/code/Exception.java | 3 +- .../deob/attributes/code/Exceptions.java | 6 +- .../deob/attributes/code/Instruction.java | 5 ++ .../deob/attributes/code/Instructions.java | 7 +- .../attributes/code/instructions/ALoad.java | 25 ++++-- .../code/instructions/ANewArray.java | 9 +- .../attributes/code/instructions/AStore.java | 9 +- .../attributes/code/instructions/BiPush.java | 9 +- .../code/instructions/CheckCast.java | 9 +- .../attributes/code/instructions/DLoad.java | 29 ++++--- .../attributes/code/instructions/DStore.java | 9 +- .../attributes/code/instructions/FLoad.java | 29 ++++--- .../attributes/code/instructions/FStore.java | 9 +- .../code/instructions/GetField.java | 9 +- .../code/instructions/GetStatic.java | 9 +- .../attributes/code/instructions/Goto.java | 13 +-- .../attributes/code/instructions/GotoW.java | 9 +- .../attributes/code/instructions/IInc.java | 33 ++++--- .../attributes/code/instructions/ILoad.java | 29 ++++--- .../attributes/code/instructions/IStore.java | 18 ++-- .../deob/attributes/code/instructions/If.java | 9 +- .../attributes/code/instructions/If0.java | 9 +- .../code/instructions/InstanceOf.java | 9 +- .../code/instructions/InvokeInterface.java | 9 +- .../code/instructions/InvokeSpecial.java | 9 +- .../code/instructions/InvokeStatic.java | 9 +- .../code/instructions/InvokeVirtual.java | 9 +- .../attributes/code/instructions/LDC2_W.java | 9 +- .../attributes/code/instructions/LDC_W.java | 29 ++++--- .../attributes/code/instructions/LLoad.java | 29 ++++--- .../attributes/code/instructions/LStore.java | 9 +- .../code/instructions/LookupSwitch.java | 11 ++- .../code/instructions/MultiANewArray.java | 7 +- .../attributes/code/instructions/New.java | 9 +- .../code/instructions/NewArray.java | 9 +- .../code/instructions/PutField.java | 11 ++- .../code/instructions/PutStatic.java | 8 +- .../attributes/code/instructions/SiPush.java | 9 +- .../code/instructions/TableSwitch.java | 11 ++- .../attributes/code/instructions/Wide.java | 13 +-- .../net/runelite/deob/execution/Stack.java | 2 +- .../java/net/runelite/deob/pool/Class.java | 3 +- .../java/net/runelite/deob/pool/Double.java | 4 +- .../java/net/runelite/deob/pool/Field.java | 4 +- .../java/net/runelite/deob/pool/Float.java | 4 +- .../java/net/runelite/deob/pool/Integer.java | 4 +- .../runelite/deob/pool/InterfaceMethod.java | 4 +- .../java/net/runelite/deob/pool/Long.java | 4 +- .../java/net/runelite/deob/pool/Method.java | 4 +- .../net/runelite/deob/pool/NameAndType.java | 4 +- .../java/net/runelite/deob/pool/String.java | 4 +- .../java/net/runelite/deob/pool/UTF8.java | 5 +- 67 files changed, 436 insertions(+), 321 deletions(-) diff --git a/src/main/java/net/runelite/deob/ClassFile.java b/src/main/java/net/runelite/deob/ClassFile.java index 56915648da..c8713441ce 100644 --- a/src/main/java/net/runelite/deob/ClassFile.java +++ b/src/main/java/net/runelite/deob/ClassFile.java @@ -16,7 +16,6 @@ public class ClassFile private static final int MAGIC = 0xcafebabe; private ClassGroup group; - private DataInputStream is; private ClassFile parent; // super class private List children = new ArrayList<>(); // classes which inherit from this @@ -35,7 +34,6 @@ public class ClassFile public ClassFile(ClassGroup group, DataInputStream is) throws IOException { this.group = group; - this.is = is; int magic = is.readInt(); if (magic != MAGIC) @@ -50,12 +48,21 @@ public class ClassFile name = pool.getClass(is.readUnsignedShort()); super_class = pool.getClass(is.readUnsignedShort()); - interfaces = new Interfaces(this); + interfaces = new Interfaces(this, is); + fields = new Fields(this, is); + + methods = new Methods(this, is); + + attributes = new Attributes(this, is); + } + + public ClassFile(ClassGroup group) + { + this.group = group; + fields = new Fields(this); - methods = new Methods(this); - attributes = new Attributes(this); } @@ -93,12 +100,7 @@ public class ClassFile { return group; } - - public DataInputStream getStream() - { - return is; - } - + public ConstantPool getPool() { return pool; diff --git a/src/main/java/net/runelite/deob/ClassGroup.java b/src/main/java/net/runelite/deob/ClassGroup.java index f0d5cac302..c775db277f 100644 --- a/src/main/java/net/runelite/deob/ClassGroup.java +++ b/src/main/java/net/runelite/deob/ClassGroup.java @@ -20,6 +20,11 @@ public class ClassGroup return cf; } + public void addClass(ClassFile cf) + { + classes.add(cf); + } + public void removeClass(ClassFile cf) { classes.remove(cf); diff --git a/src/main/java/net/runelite/deob/ConstantPool.java b/src/main/java/net/runelite/deob/ConstantPool.java index 8193237f25..8dae509745 100644 --- a/src/main/java/net/runelite/deob/ConstantPool.java +++ b/src/main/java/net/runelite/deob/ConstantPool.java @@ -38,8 +38,8 @@ public class ConstantPool try { - Constructor con = type.getPoolClass().getConstructor(new Class[] { ConstantPool.class }); - PoolEntry entry = con.newInstance(this); + Constructor con = type.getPoolClass().getConstructor(new Class[] { ConstantPool.class, DataInputStream.class }); + PoolEntry entry = con.newInstance(this, is); entry.id = i; entries.add(entry); diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 0a823896b2..b82ce45710 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -39,52 +39,52 @@ public class Deob ClassGroup group = loadJar(args[0]); -// run(group, new RenameUnique()); + //run(group, new RenameUnique()); -// // remove except RuntimeException -// run(group, new RuntimeExceptions()); -// -// // remove unused methods -// run(group, new UnusedMethods()); -// -// run(group, new UnreachedCode()); -// -// // remove illegal state exceptions, frees up some parameters -// run(group, new IllegalStateExceptions()); -// -// // remove constant logically dead parameters -// run(group, new ConstantParameter()); -// -// // remove unhit blocks -// run(group, new UnreachedCode()); -// -// // remove unused parameters -// run(group, new UnusedParameters()); -// -// // remove jump obfuscation -// //new Jumps().run(group); -// -// // remove unused fields -// run(group, new UnusedFields()); -// -// // remove unused methods, again? -// run(group, new UnusedMethods()); -// -// run(group, new MethodInliner()); -// -// run(group, new MethodMover()); -// -// run(group, new FieldInliner()); -// -// // XXX this is broken because when moving clinit around, some fields can depend on other fields -// // (like multianewarray) -// //new FieldMover().run(group); -// -// run(group, new UnusedClass()); + // remove except RuntimeException + run(group, new RuntimeExceptions()); - //new ModArith().run(group); + // remove unused methods + run(group, new UnusedMethods()); - new MultiplicationDeobfuscator().run(group); + run(group, new UnreachedCode()); + + // remove illegal state exceptions, frees up some parameters + run(group, new IllegalStateExceptions()); + + // remove constant logically dead parameters + run(group, new ConstantParameter()); + + // remove unhit blocks + run(group, new UnreachedCode()); + + // remove unused parameters + run(group, new UnusedParameters()); + + // remove jump obfuscation + //new Jumps().run(group); + + // remove unused fields + run(group, new UnusedFields()); + + // remove unused methods, again? + run(group, new UnusedMethods()); + + run(group, new MethodInliner()); + + run(group, new MethodMover()); + + run(group, new FieldInliner()); + + // XXX this is broken because when moving clinit around, some fields can depend on other fields + // (like multianewarray) + //new FieldMover().run(group); + + run(group, new UnusedClass()); + + new ModArith().run(group); + +// new MultiplicationDeobfuscator().run(group); // new MultiplyOneDeobfuscator().run(group); // diff --git a/src/main/java/net/runelite/deob/Field.java b/src/main/java/net/runelite/deob/Field.java index 74d2916598..c9f2bfd3a1 100644 --- a/src/main/java/net/runelite/deob/Field.java +++ b/src/main/java/net/runelite/deob/Field.java @@ -29,17 +29,16 @@ public class Field private Type type; private Attributes attributes; - Field(Fields fields) throws IOException + Field(Fields fields, DataInputStream is) throws IOException { this.fields = fields; - DataInputStream is = fields.getClassFile().getStream(); ConstantPool pool = fields.getClassFile().getPool(); accessFlags = is.readShort(); name = pool.getUTF8(is.readUnsignedShort()); type = new Type(pool.getUTF8(is.readUnsignedShort())); - attributes = new Attributes(this); + attributes = new Attributes(this, is); } public void write(DataOutputStream out) throws IOException diff --git a/src/main/java/net/runelite/deob/Fields.java b/src/main/java/net/runelite/deob/Fields.java index 49e2ffcefb..471eaaf9a7 100644 --- a/src/main/java/net/runelite/deob/Fields.java +++ b/src/main/java/net/runelite/deob/Fields.java @@ -14,16 +14,19 @@ public class Fields private List fields = new ArrayList<>(); - Fields(ClassFile c) throws IOException + Fields(ClassFile c, DataInputStream is) throws IOException { classFile = c; - DataInputStream is = c.getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) - fields.add(new Field(this)); + fields.add(new Field(this, is)); + } + + Fields(ClassFile c) + { + classFile = c; } public void write(DataOutputStream out) throws IOException diff --git a/src/main/java/net/runelite/deob/Interfaces.java b/src/main/java/net/runelite/deob/Interfaces.java index df3fbd1d66..4bee37f2df 100644 --- a/src/main/java/net/runelite/deob/Interfaces.java +++ b/src/main/java/net/runelite/deob/Interfaces.java @@ -14,12 +14,10 @@ public class Interfaces private List interfaces = new ArrayList(); - Interfaces(ClassFile c) throws IOException + Interfaces(ClassFile c, DataInputStream is) throws IOException { classFile = c; - DataInputStream is = c.getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) diff --git a/src/main/java/net/runelite/deob/Method.java b/src/main/java/net/runelite/deob/Method.java index a51508935c..a915c47c5a 100644 --- a/src/main/java/net/runelite/deob/Method.java +++ b/src/main/java/net/runelite/deob/Method.java @@ -27,18 +27,17 @@ public class Method public Signature arguments; private Attributes attributes; - Method(Methods methods) throws IOException + Method(Methods methods, DataInputStream is) throws IOException { this.methods = methods; - DataInputStream is = methods.getClassFile().getStream(); ConstantPool pool = methods.getClassFile().getPool(); accessFlags = is.readShort(); name = pool.getUTF8(is.readUnsignedShort()); arguments = new Signature(pool.getUTF8(is.readUnsignedShort())); attributes = new Attributes(this); - attributes.load(); + attributes.load(is); } public Method(Methods methods, String name, Signature signature) diff --git a/src/main/java/net/runelite/deob/Methods.java b/src/main/java/net/runelite/deob/Methods.java index 4bb6dceab3..63460f825b 100644 --- a/src/main/java/net/runelite/deob/Methods.java +++ b/src/main/java/net/runelite/deob/Methods.java @@ -15,16 +15,19 @@ public class Methods private List methods = new ArrayList<>(); - Methods(ClassFile cf) throws IOException + Methods(ClassFile cf, DataInputStream is) throws IOException { classFile = cf; - DataInputStream is = cf.getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) - methods.add(new Method(this)); + methods.add(new Method(this, is)); + } + + Methods(ClassFile cf) + { + classFile = cf; } public void write(DataOutputStream out) throws IOException diff --git a/src/main/java/net/runelite/deob/attributes/Attribute.java b/src/main/java/net/runelite/deob/attributes/Attribute.java index c92378223f..46980a5fb4 100644 --- a/src/main/java/net/runelite/deob/attributes/Attribute.java +++ b/src/main/java/net/runelite/deob/attributes/Attribute.java @@ -17,14 +17,13 @@ public abstract class Attribute this.type = type; } - public final void load() throws IOException + public final void load(DataInputStream is) throws IOException { - DataInputStream is = attributes.getStream(); this.length = is.readInt(); - this.loadAttribute(); + this.loadAttribute(is); } - public abstract void loadAttribute() throws IOException; + public abstract void loadAttribute(DataInputStream is) throws IOException; public final void write(DataOutputStream out) throws IOException { diff --git a/src/main/java/net/runelite/deob/attributes/Attributes.java b/src/main/java/net/runelite/deob/attributes/Attributes.java index e91300e2e5..be8c8a816c 100644 --- a/src/main/java/net/runelite/deob/attributes/Attributes.java +++ b/src/main/java/net/runelite/deob/attributes/Attributes.java @@ -19,18 +19,23 @@ public class Attributes private List attributes = new ArrayList<>(); - public Attributes(ClassFile cf) throws IOException + public Attributes(ClassFile cf, DataInputStream is) throws IOException { classFile = cf; - load(); + load(is); + } + + public Attributes(ClassFile cf) + { + classFile = cf; } - public Attributes(Field f) throws IOException + public Attributes(Field f, DataInputStream is) throws IOException { field = f; - load(); + load(is); } public Attributes(Method m) @@ -73,15 +78,8 @@ public class Attributes return null; } - public DataInputStream getStream() + public void load(DataInputStream is) throws IOException { - return getClassFile().getStream(); - } - - public void load() throws IOException - { - DataInputStream is = getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) @@ -93,7 +91,7 @@ public class Attributes { Constructor con = type.getAttributeClass().getConstructor(new Class[] { Attributes.class }); Attribute attr = con.newInstance(this); - attr.load(); + attr.load(is); if (type != AttributeType.UNKNOWN) attributes.add(attr); diff --git a/src/main/java/net/runelite/deob/attributes/Code.java b/src/main/java/net/runelite/deob/attributes/Code.java index edacb393de..6dee991646 100644 --- a/src/main/java/net/runelite/deob/attributes/Code.java +++ b/src/main/java/net/runelite/deob/attributes/Code.java @@ -26,21 +26,19 @@ public class Code extends Attribute } @Override - public void loadAttribute() throws IOException + public void loadAttribute(DataInputStream is) throws IOException { - DataInputStream is = this.getAttributes().getStream(); - maxStack = is.readUnsignedShort(); is.skip(2); // max locals instructions = new Instructions(this); - instructions.load(); + instructions.load(is); exceptions = new Exceptions(this); - exceptions.load(); + exceptions.load(is); this.attributes = new Attributes(this); - this.attributes.load(); + this.attributes.load(is); instructions.buildBlocks(); instructions.buildJumpGraph(); diff --git a/src/main/java/net/runelite/deob/attributes/ConstantValue.java b/src/main/java/net/runelite/deob/attributes/ConstantValue.java index 56e61c077a..44f8d92af3 100644 --- a/src/main/java/net/runelite/deob/attributes/ConstantValue.java +++ b/src/main/java/net/runelite/deob/attributes/ConstantValue.java @@ -23,9 +23,8 @@ public class ConstantValue extends Attribute } @Override - public void loadAttribute() throws IOException + public void loadAttribute(DataInputStream is) throws IOException { - 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 d3542e8f84..adfa20444d 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 loadAttribute() throws IOException + public void loadAttribute(DataInputStream is) throws IOException { - DataInputStream is = this.getAttributes().getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) { diff --git a/src/main/java/net/runelite/deob/attributes/Unknown.java b/src/main/java/net/runelite/deob/attributes/Unknown.java index a37270b02d..74fc97ebb3 100644 --- a/src/main/java/net/runelite/deob/attributes/Unknown.java +++ b/src/main/java/net/runelite/deob/attributes/Unknown.java @@ -14,10 +14,9 @@ public class Unknown extends Attribute } @Override - public void loadAttribute() throws IOException + public void loadAttribute(DataInputStream is) throws IOException { int len = this.getLength(); - DataInputStream is = this.getAttributes().getStream(); data = new byte[len]; diff --git a/src/main/java/net/runelite/deob/attributes/code/Exception.java b/src/main/java/net/runelite/deob/attributes/code/Exception.java index 6ad9e1b32c..d7257deb03 100644 --- a/src/main/java/net/runelite/deob/attributes/code/Exception.java +++ b/src/main/java/net/runelite/deob/attributes/code/Exception.java @@ -15,11 +15,10 @@ public class Exception private Instruction start, end, handler; private Class catchType; - public Exception(Exceptions exceptions) throws IOException + public Exception(Exceptions exceptions, DataInputStream is) throws IOException { this.exceptions = exceptions; - DataInputStream is = exceptions.getCode().getAttributes().getStream(); ConstantPool pool = exceptions.getCode().getAttributes().getClassFile().getPool(); int startPc = is.readUnsignedShort(); diff --git a/src/main/java/net/runelite/deob/attributes/code/Exceptions.java b/src/main/java/net/runelite/deob/attributes/code/Exceptions.java index e9de6f3c31..ea2a19f0e2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/Exceptions.java +++ b/src/main/java/net/runelite/deob/attributes/code/Exceptions.java @@ -19,14 +19,12 @@ public class Exceptions this.code = code; } - public void load() throws IOException + public void load(DataInputStream is) throws IOException { - DataInputStream is = code.getAttributes().getStream(); - int count = is.readUnsignedShort(); for (int i = 0; i < count; ++i) - exceptions.add(new Exception(this)); + exceptions.add(new Exception(this, is)); } public void add(Exception e) diff --git a/src/main/java/net/runelite/deob/attributes/code/Instruction.java b/src/main/java/net/runelite/deob/attributes/code/Instruction.java index 9db98de703..dbd93a8736 100644 --- a/src/main/java/net/runelite/deob/attributes/code/Instruction.java +++ b/src/main/java/net/runelite/deob/attributes/code/Instruction.java @@ -1,5 +1,6 @@ package net.runelite.deob.attributes.code; +import java.io.DataInputStream; import net.runelite.deob.ClassFile; import net.runelite.deob.ConstantPool; import net.runelite.deob.Field; @@ -31,6 +32,10 @@ public abstract class Instruction this.pc = pc; } + public void load(DataInputStream is) throws IOException + { + } + protected void remove() { assert block == null; diff --git a/src/main/java/net/runelite/deob/attributes/code/Instructions.java b/src/main/java/net/runelite/deob/attributes/code/Instructions.java index bb7148659b..20170e8b36 100644 --- a/src/main/java/net/runelite/deob/attributes/code/Instructions.java +++ b/src/main/java/net/runelite/deob/attributes/code/Instructions.java @@ -26,10 +26,8 @@ public class Instructions this.code = code; } - public void load() throws IOException + public void load(DataInputStream is) throws IOException { - DataInputStream is = code.getAttributes().getStream(); - int length = is.readInt(); int pc; @@ -43,8 +41,9 @@ public class Instructions { Constructor con = type.getInstructionClass().getConstructor(Instructions.class, InstructionType.class, int.class); Instruction ins = con.newInstance(this, type, pc); - Instruction genericIns = ins.makeGeneric(); + ins.load(is); + Instruction genericIns = ins.makeGeneric(); if (genericIns != ins) { genericIns.setPc(ins.getPc()); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java index 19d09f8bda..2d606f6275 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ALoad.java @@ -19,6 +19,7 @@ import java.io.IOException; public class ALoad extends Instruction implements LVTInstruction, WideInstruction { private int index; + private boolean wide; public ALoad(Instructions instructions, int index) { @@ -30,19 +31,27 @@ public class ALoad extends Instruction implements LVTInstruction, WideInstructio public ALoad(Instructions instructions, InstructionType type, int pc) throws IOException { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - length += 1; } public ALoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - length += 2; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + length += 2; + } + else + { + index = is.readByte(); + length += 1; + } } @Override diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java index 2258188730..0e47651364 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ANewArray.java @@ -19,11 +19,14 @@ public class ANewArray extends Instruction { private Class clazz; - public ANewArray(Instructions instructions, InstructionType type, int pc) throws IOException + public ANewArray(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { clazz = this.getPool().getClass(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/AStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/AStore.java index bc60499d24..b189381d3f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/AStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/AStore.java @@ -27,11 +27,14 @@ public class AStore extends Instruction implements LVTInstruction, WideInstructi ++length; } - public AStore(Instructions instructions, InstructionType type, int pc) throws IOException + public AStore(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { index = is.readByte(); length += 1; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java b/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java index 7207072db9..6404d7a48d 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/BiPush.java @@ -18,11 +18,14 @@ public class BiPush extends Instruction implements PushConstantInstruction { private byte b; - public BiPush(Instructions instructions, InstructionType type, int pc) throws IOException + public BiPush(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { b = is.readByte(); length += 1; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java b/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java index 8c424f5ea0..33a8cc9812 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/CheckCast.java @@ -19,11 +19,14 @@ public class CheckCast extends Instruction { private Class clazz; - public CheckCast(Instructions instructions, InstructionType type, int pc) throws IOException + public CheckCast(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { clazz = this.getPool().getClass(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java index 7968b6f7dc..ae1c069026 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DLoad.java @@ -20,6 +20,7 @@ import java.io.IOException; public class DLoad extends Instruction implements LVTInstruction, WideInstruction { private int index; + private boolean wide; public DLoad(Instructions instructions, int index) { @@ -28,22 +29,30 @@ public class DLoad extends Instruction implements LVTInstruction, WideInstructio ++length; } - public DLoad(Instructions instructions, InstructionType type, int pc) throws IOException + public DLoad(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - length += 1; } - public DLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException + public DLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - length += 2; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + length += 2; + } + else + { + index = is.readByte(); + length += 1; + } } @Override diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/DStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/DStore.java index a42a618723..7696fbbcdc 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/DStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/DStore.java @@ -27,11 +27,14 @@ public class DStore extends Instruction implements LVTInstruction, WideInstructi ++length; } - public DStore(Instructions instructions, InstructionType type, int pc) throws IOException + public DStore(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { index = is.readByte(); length += 1; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java index cda5057067..f6022d2464 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FLoad.java @@ -20,6 +20,7 @@ import java.io.IOException; public class FLoad extends Instruction implements LVTInstruction, WideInstruction { private int index; + private boolean wide; public FLoad(Instructions instructions, int index) { @@ -28,22 +29,30 @@ public class FLoad extends Instruction implements LVTInstruction, WideInstructio ++length; } - public FLoad(Instructions instructions, InstructionType type, int pc) throws IOException + public FLoad(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - length += 1; } - public FLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException + public FLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - length += 2; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + length += 2; + } + else + { + index = is.readByte(); + length += 1; + } } @Override diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/FStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/FStore.java index 53f08a4966..6bbb78c365 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/FStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/FStore.java @@ -27,11 +27,14 @@ public class FStore extends Instruction implements LVTInstruction, WideInstructi ++length; } - public FStore(Instructions instructions, InstructionType type, int pc) throws IOException + public FStore(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { index = is.readByte(); length += 1; } 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 84bbe1d55c..9cc68e0150 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 @@ -24,11 +24,14 @@ public class GetField extends Instruction implements GetFieldInstruction { private Field field; - public GetField(Instructions instructions, InstructionType type, int pc) throws IOException + public GetField(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { field = this.getPool().getField(is.readUnsignedShort()); length += 2; } 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 68b2451a5d..fcc8bde040 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 @@ -24,11 +24,14 @@ public class GetStatic extends Instruction implements GetFieldInstruction { private Field field; - public GetStatic(Instructions instructions, InstructionType type, int pc) throws IOException + public GetStatic(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { field = this.getPool().getField(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Goto.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Goto.java index 38ddc9d37d..4f7b60fd6a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Goto.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Goto.java @@ -18,13 +18,9 @@ public class Goto extends Instruction implements JumpingInstruction private Instruction to; private short offset; - public Goto(Instructions instructions, InstructionType type, int pc) throws IOException + public Goto(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - offset = is.readShort(); - length += 2; } public Goto(Instructions instructions, Instruction to) @@ -34,6 +30,13 @@ public class Goto extends Instruction implements JumpingInstruction length += 2; } + @Override + public void load(DataInputStream is) throws IOException + { + offset = is.readShort(); + length += 2; + } + @Override public void resolve() { diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GotoW.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GotoW.java index 67263ae0ca..123bed2413 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GotoW.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GotoW.java @@ -18,11 +18,14 @@ public class GotoW extends Instruction implements JumpingInstruction private Instruction to; private int offset; - public GotoW(Instructions instructions, InstructionType type, int pc) throws IOException + public GotoW(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { offset = is.readInt(); length += 4; } 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 0ab042b8af..5e94c1497a 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 @@ -19,25 +19,34 @@ public class IInc extends Instruction implements LVTInstruction, WideInstruction { private short index; private short inc; + private boolean wide; - public IInc(Instructions instructions, InstructionType type, int pc) throws IOException + public IInc(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - inc = is.readByte(); - length += 2; } - public IInc(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException + public IInc(Instructions instructions, InstructionType type, Instruction instruction, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - inc = is.readShort(); - length += 4; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + inc = is.readShort(); + length += 4; + } + else + { + index = is.readByte(); + inc = is.readByte(); + length += 2; + } } @Override 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 74cae101bf..b9b7403b07 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 @@ -20,6 +20,7 @@ import java.io.IOException; public class ILoad extends Instruction implements LVTInstruction, WideInstruction { private int index; + private boolean wide; public ILoad(Instructions instructions, int index) { @@ -28,22 +29,30 @@ public class ILoad extends Instruction implements LVTInstruction, WideInstructio ++length; } - public ILoad(Instructions instructions, InstructionType type, int pc) throws IOException + public ILoad(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - length += 1; } - public ILoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException + public ILoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - length += 2; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + length += 2; + } + else + { + index = is.readByte(); + length += 1; + } } @Override 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 df295480f0..e9893542b2 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 @@ -28,24 +28,18 @@ public class IStore extends Instruction implements LVTInstruction, WideInstructi ++length; } - public IStore(Instructions instructions, InstructionType type, int pc) throws IOException + public IStore(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { index = is.readByte(); length += 1; } -// public IStore(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException -// { -// super(instructions, type, pc); -// -// DataInputStream is = instructions.getCode().getAttributes().getStream(); -// index = is.readShort(); -// length += 2; -// } - @Override public void write(DataOutputStream out) throws IOException { 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 33dea6a988..7d14cee235 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 @@ -21,11 +21,14 @@ public class If extends Instruction implements JumpingInstruction, ComparisonIns private Instruction to; private short offset; - public If(Instructions instructions, InstructionType type, int pc) throws IOException + public If(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { offset = is.readShort(); length += 2; } 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 a0d1a538e7..4fb9f4272c 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 @@ -21,11 +21,14 @@ public class If0 extends Instruction implements JumpingInstruction, ComparisonIn private Instruction to; private short offset; - public If0(Instructions instructions, InstructionType type, int pc) throws IOException + public If0(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { offset = is.readShort(); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java index c73ec2c0e1..76fdbd900e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InstanceOf.java @@ -18,11 +18,14 @@ public class InstanceOf extends Instruction { private Class clazz; - public InstanceOf(Instructions instructions, InstructionType type, int pc) throws IOException + public InstanceOf(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { clazz = this.getPool().getClass(is.readUnsignedShort()); length += 2; } 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 316a96b001..e926446534 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 @@ -30,11 +30,14 @@ public class InvokeInterface extends Instruction implements InvokeInstruction private InterfaceMethod method; private int count; - public InvokeInterface(Instructions instructions, InstructionType type, int pc) throws IOException + public InvokeInterface(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { method = this.getPool().getInterfaceMethod(is.readUnsignedShort()); count = is.readUnsignedByte(); is.skip(1); 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 4620440f14..8df3eceeb4 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 @@ -28,11 +28,14 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction { private Method method; - public InvokeSpecial(Instructions instructions, InstructionType type, int pc) throws IOException + public InvokeSpecial(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { method = this.getPool().getMethod(is.readUnsignedShort()); length += 2; } 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 6c3b057f73..5d434e9793 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 @@ -28,11 +28,14 @@ public class InvokeStatic extends Instruction implements InvokeInstruction { private Method method; - public InvokeStatic(Instructions instructions, InstructionType type, int pc) throws IOException + public InvokeStatic(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { method = this.getPool().getMethod(is.readUnsignedShort()); length += 2; } 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 8a33320d8e..c374548e57 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 @@ -28,11 +28,14 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction { private Method method; - public InvokeVirtual(Instructions instructions, InstructionType type, int pc) throws IOException + public InvokeVirtual(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { method = this.getPool().getMethod(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java index cbc026db64..f770a6a6c5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java @@ -18,11 +18,14 @@ public class LDC2_W extends Instruction implements PushConstantInstruction { private PoolEntry value; - public LDC2_W(Instructions instructions, InstructionType type, int pc) throws IOException + public LDC2_W(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { value = this.getPool().getEntry(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java index a358f84ae1..303d944248 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java @@ -18,11 +18,26 @@ public class LDC_W extends Instruction implements PushConstantInstruction { private PoolEntry value; - public LDC_W(Instructions instructions, InstructionType type, int pc) throws IOException + public LDC_W(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + + assert type == InstructionType.LDC_W || type == InstructionType.LDC; + } + + public LDC_W(Instructions instructions, PoolEntry value) + { + super(instructions, InstructionType.LDC_W, 0); + + this.value = value; + length += 2; + } + + @Override + public void load(DataInputStream is) throws IOException + { + InstructionType type = this.getType(); + assert type == InstructionType.LDC_W || type == InstructionType.LDC; if (type == InstructionType.LDC_W) @@ -37,14 +52,6 @@ public class LDC_W extends Instruction implements PushConstantInstruction } } - public LDC_W(Instructions instructions, PoolEntry value) - { - super(instructions, InstructionType.LDC_W, 0); - - this.value = value; - length += 2; - } - @Override public void prime() { diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java index 85965b2b49..2fc0129555 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LLoad.java @@ -20,6 +20,7 @@ import java.io.IOException; public class LLoad extends Instruction implements LVTInstruction, WideInstruction { private int index; + private boolean wide; public LLoad(Instructions instructions, int index) { @@ -28,22 +29,30 @@ public class LLoad extends Instruction implements LVTInstruction, WideInstructio ++length; } - public LLoad(Instructions instructions, InstructionType type, int pc) throws IOException + public LLoad(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readByte(); - length += 1; } - public LLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) throws IOException + public LLoad(Instructions instructions, InstructionType type, Instruction instruction, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - index = is.readShort(); - length += 2; + wide = true; + } + + @Override + public void load(DataInputStream is) throws IOException + { + if (wide) + { + index = is.readShort(); + length += 2; + } + else + { + index = is.readByte(); + length += 1; + } } @Override diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LStore.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LStore.java index 7f519055e2..7a04bf927c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LStore.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LStore.java @@ -28,11 +28,14 @@ public class LStore extends Instruction implements LVTInstruction, WideInstructi ++length; } - public LStore(Instructions instructions, InstructionType type, int pc) throws IOException + public LStore(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { index = is.readByte(); length += 1; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java index c1923d7d67..cf499f1086 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java @@ -26,12 +26,15 @@ public class LookupSwitch extends Instruction implements JumpingInstruction private int[] match; private int[] branch; - public LookupSwitch(Instructions instructions, InstructionType type, int pc) throws IOException + public LookupSwitch(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - + } + + @Override + public void load(DataInputStream is) throws IOException + { + int pc = this.getPc(); int tableSkip = 4 - (pc + 1) % 4; if (tableSkip == 4) tableSkip = 0; if (tableSkip > 0) is.skip(tableSkip); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java index 37f3a9a773..a29de34494 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/MultiANewArray.java @@ -23,8 +23,11 @@ public class MultiANewArray extends Instruction public MultiANewArray(Instructions instructions, InstructionType type, int pc) throws IOException { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { clazz = this.getPool().getClass(is.readUnsignedShort()); dimensions = is.readUnsignedByte(); length += 3; diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/New.java b/src/main/java/net/runelite/deob/attributes/code/instructions/New.java index b972ab959f..a3af1181eb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/New.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/New.java @@ -19,11 +19,14 @@ public class New extends Instruction { private Class clazz; - public New(Instructions instructions, InstructionType type, int pc) throws IOException + public New(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { clazz = this.getPool().getClass(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java b/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java index 153d07822b..90270616f0 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/NewArray.java @@ -17,11 +17,14 @@ public class NewArray extends Instruction { private int type; - public NewArray(Instructions instructions, InstructionType type, int pc) throws IOException + public NewArray(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { this.type = is.readUnsignedByte(); length += 1; } 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 89cd1c12e6..99cc4246e2 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 @@ -16,10 +16,6 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; -import static net.runelite.deob.attributes.code.instructions.PutStatic.translate; import net.runelite.deob.deobfuscators.arithmetic.Encryption; import net.runelite.deob.deobfuscators.arithmetic.Pair; @@ -30,8 +26,11 @@ public class PutField extends Instruction implements SetFieldInstruction public PutField(Instructions instructions, InstructionType type, int pc) throws IOException { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { field = this.getPool().getField(is.readUnsignedShort()); length += 2; } 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 c71ec51a10..3b6a7aab36 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 @@ -16,7 +16,6 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.HashSet; import java.util.Set; import net.runelite.deob.attributes.code.instruction.types.DupInstruction; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; @@ -31,8 +30,11 @@ public class PutStatic extends Instruction implements SetFieldInstruction public PutStatic(Instructions instructions, InstructionType type, int pc) throws IOException { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { field = this.getPool().getField(is.readUnsignedShort()); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java index e86ffe9159..0cad63a64c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java @@ -18,11 +18,14 @@ public class SiPush extends Instruction implements PushConstantInstruction { private short s; - public SiPush(Instructions instructions, InstructionType type, int pc) throws IOException + public SiPush(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); + } + + @Override + public void load(DataInputStream is) throws IOException + { s = is.readShort(); length += 2; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java b/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java index 2e097b6cb8..cc88def589 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java @@ -25,12 +25,15 @@ public class TableSwitch extends Instruction implements JumpingInstruction private int high; private int[] jumps; - public TableSwitch(Instructions instructions, InstructionType type, int pc) throws IOException + public TableSwitch(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - + } + + @Override + public void load(DataInputStream is) throws IOException + { + int pc = this.getPc(); int tableSkip = 4 - (pc + 1) % 4; if (tableSkip == 4) tableSkip = 0; if (tableSkip > 0) is.skip(tableSkip); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Wide.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Wide.java index c9f42abcce..4e83058175 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Wide.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Wide.java @@ -17,19 +17,22 @@ public class Wide extends Instruction implements LVTInstruction { private Instruction ins; - public Wide(Instructions instructions, InstructionType type, int pc) throws IOException + public Wide(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); - - DataInputStream is = instructions.getCode().getAttributes().getStream(); - + } + + @Override + public void load(DataInputStream is) throws IOException + { byte opcode = is.readByte(); // this byte is already in the length of the new instruction (length is initialized to 1) InstructionType op = InstructionType.findInstructionFromCode(opcode); try { Constructor con = op.getInstructionClass().getConstructor(Instructions.class, InstructionType.class, Instruction.class, int.class); - ins = con.newInstance(instructions, op, this, pc); + ins = con.newInstance(this.getInstructions(), op, this, this.getPc()); + ins.load(is); length += ins.getLength(); } catch (Exception ex) diff --git a/src/main/java/net/runelite/deob/execution/Stack.java b/src/main/java/net/runelite/deob/execution/Stack.java index 961d4725eb..5078344e76 100644 --- a/src/main/java/net/runelite/deob/execution/Stack.java +++ b/src/main/java/net/runelite/deob/execution/Stack.java @@ -9,7 +9,7 @@ public class Stack public Stack(int sz) { - stack = new StackContext[sz*2]; // XXX + stack = new StackContext[sz*2]; // XXX FIXME } protected Stack(Stack other) diff --git a/src/main/java/net/runelite/deob/pool/Class.java b/src/main/java/net/runelite/deob/pool/Class.java index b10b3b3f11..12c405fed4 100644 --- a/src/main/java/net/runelite/deob/pool/Class.java +++ b/src/main/java/net/runelite/deob/pool/Class.java @@ -12,11 +12,10 @@ public class Class extends PoolEntry private int index; private java.lang.String name; - public Class(ConstantPool pool) throws IOException + public Class(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.CLASS); - DataInputStream is = pool.getClassFile().getStream(); index = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/Double.java b/src/main/java/net/runelite/deob/pool/Double.java index 79a5915d90..7ed74a9ade 100644 --- a/src/main/java/net/runelite/deob/pool/Double.java +++ b/src/main/java/net/runelite/deob/pool/Double.java @@ -11,12 +11,10 @@ public class Double extends PoolEntry { private double value; - public Double(ConstantPool pool) throws IOException + public Double(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.DOUBLE); - DataInputStream is = pool.getClassFile().getStream(); - value = is.readDouble(); } diff --git a/src/main/java/net/runelite/deob/pool/Field.java b/src/main/java/net/runelite/deob/pool/Field.java index ee8adbd168..87b569e7f3 100644 --- a/src/main/java/net/runelite/deob/pool/Field.java +++ b/src/main/java/net/runelite/deob/pool/Field.java @@ -12,12 +12,10 @@ public class Field extends PoolEntry private Class clazz; private NameAndType nat; - public Field(ConstantPool pool) throws IOException + public Field(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.FIELDREF); - DataInputStream is = pool.getClassFile().getStream(); - classIndex = is.readUnsignedShort(); natIndex = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/Float.java b/src/main/java/net/runelite/deob/pool/Float.java index 293db1a282..33fa6f297d 100644 --- a/src/main/java/net/runelite/deob/pool/Float.java +++ b/src/main/java/net/runelite/deob/pool/Float.java @@ -11,12 +11,10 @@ public class Float extends PoolEntry { private float value; - public Float(ConstantPool pool) throws IOException + public Float(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.FLOAT); - DataInputStream is = pool.getClassFile().getStream(); - value = is.readFloat(); } diff --git a/src/main/java/net/runelite/deob/pool/Integer.java b/src/main/java/net/runelite/deob/pool/Integer.java index dd53b013f4..b0746dba10 100644 --- a/src/main/java/net/runelite/deob/pool/Integer.java +++ b/src/main/java/net/runelite/deob/pool/Integer.java @@ -11,12 +11,10 @@ public class Integer extends PoolEntry { private int value; - public Integer(ConstantPool pool) throws IOException + public Integer(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.INTEGER); - DataInputStream is = pool.getClassFile().getStream(); - value = is.readInt(); } diff --git a/src/main/java/net/runelite/deob/pool/InterfaceMethod.java b/src/main/java/net/runelite/deob/pool/InterfaceMethod.java index 836e62b148..0da3118783 100644 --- a/src/main/java/net/runelite/deob/pool/InterfaceMethod.java +++ b/src/main/java/net/runelite/deob/pool/InterfaceMethod.java @@ -20,12 +20,10 @@ public class InterfaceMethod extends PoolEntry this.nat = nat; } - public InterfaceMethod(ConstantPool pool) throws IOException + public InterfaceMethod(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.INTERFACE_METHOD_REF); - DataInputStream is = pool.getClassFile().getStream(); - classIndex = is.readUnsignedShort(); natIndex = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/Long.java b/src/main/java/net/runelite/deob/pool/Long.java index 532dd049f2..c372c31a74 100644 --- a/src/main/java/net/runelite/deob/pool/Long.java +++ b/src/main/java/net/runelite/deob/pool/Long.java @@ -11,12 +11,10 @@ public class Long extends PoolEntry { private long value; - public Long(ConstantPool pool) throws IOException + public Long(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.LONG); - DataInputStream is = pool.getClassFile().getStream(); - value = is.readLong(); } diff --git a/src/main/java/net/runelite/deob/pool/Method.java b/src/main/java/net/runelite/deob/pool/Method.java index d7fa9d3c1b..91d2e34d44 100644 --- a/src/main/java/net/runelite/deob/pool/Method.java +++ b/src/main/java/net/runelite/deob/pool/Method.java @@ -20,12 +20,10 @@ public class Method extends PoolEntry this.nat = nat; } - public Method(ConstantPool pool) throws IOException + public Method(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.METHODREF); - DataInputStream is = pool.getClassFile().getStream(); - classIndex = is.readUnsignedShort(); natIndex = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/NameAndType.java b/src/main/java/net/runelite/deob/pool/NameAndType.java index 85e6e2cede..58a7b12d3f 100644 --- a/src/main/java/net/runelite/deob/pool/NameAndType.java +++ b/src/main/java/net/runelite/deob/pool/NameAndType.java @@ -18,12 +18,10 @@ public class NameAndType extends PoolEntry /* type */ private Type type; - public NameAndType(ConstantPool pool) throws IOException + public NameAndType(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.NAME_AND_TYPE); - DataInputStream is = pool.getClassFile().getStream(); - nameIndex = is.readUnsignedShort(); descriptorIndex = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/String.java b/src/main/java/net/runelite/deob/pool/String.java index 5bab46875c..b135e3f4a5 100644 --- a/src/main/java/net/runelite/deob/pool/String.java +++ b/src/main/java/net/runelite/deob/pool/String.java @@ -12,12 +12,10 @@ public class String extends PoolEntry private int stringIndex; private java.lang.String string; - public String(ConstantPool pool) throws IOException + public String(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.STRING); - DataInputStream is = pool.getClassFile().getStream(); - stringIndex = is.readUnsignedShort(); } diff --git a/src/main/java/net/runelite/deob/pool/UTF8.java b/src/main/java/net/runelite/deob/pool/UTF8.java index 95f3ca8cf7..e431e93837 100644 --- a/src/main/java/net/runelite/deob/pool/UTF8.java +++ b/src/main/java/net/runelite/deob/pool/UTF8.java @@ -10,12 +10,11 @@ public class UTF8 extends PoolEntry { private java.lang.String string; - public UTF8(ConstantPool pool) throws IOException + public UTF8(ConstantPool pool, DataInputStream is) throws IOException { super(ConstantType.UTF8); - DataInputStream ios = pool.getClassFile().getStream(); - string = ios.readUTF(); + string = is.readUTF(); } public UTF8(java.lang.String value)