diff --git a/cache/src/main/java/net/runelite/cache/item/ItemSpriteFactory.java b/cache/src/main/java/net/runelite/cache/item/ItemSpriteFactory.java index c93edf3611..5d6f340508 100644 --- a/cache/src/main/java/net/runelite/cache/item/ItemSpriteFactory.java +++ b/cache/src/main/java/net/runelite/cache/item/ItemSpriteFactory.java @@ -38,19 +38,19 @@ import net.runelite.cache.models.VertexNormal; public class ItemSpriteFactory { public static final BufferedImage createSprite(ItemProvider itemProvider, ModelProvider modelProvider, - SpriteProvider spriteProvider, TextureProvider textureProvider, - int itemId, int quantity, int border, int shadowColor, - boolean noted) throws IOException + SpriteProvider spriteProvider, TextureProvider textureProvider, + int itemId, int quantity, int border, int shadowColor, + boolean noted) throws IOException { - SpritePixels spritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider, - itemId, quantity, border, shadowColor, noted); + Sprite spritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider, + itemId, quantity, border, shadowColor, noted); return spritePixels == null ? null : spritePixels.toBufferedImage(); } - private static final SpritePixels createSpritePixels(ItemProvider itemProvider, ModelProvider modelProvider, - SpriteProvider spriteProvider, TextureProvider textureProvider, - int itemId, int quantity, int border, int shadowColor, - boolean noted) throws IOException + private static final Sprite createSpritePixels(ItemProvider itemProvider, ModelProvider modelProvider, + SpriteProvider spriteProvider, TextureProvider textureProvider, + int itemId, int quantity, int border, int shadowColor, + boolean noted) throws IOException { ItemDefinition item = itemProvider.provide(itemId); @@ -83,11 +83,11 @@ public class ItemSpriteFactory return null; } - SpritePixels auxSpritePixels = null; + Sprite auxSpritePixels = null; if (item.notedTemplate != -1) { auxSpritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider, - item.notedID, 10, 1, 0, true); + item.notedID, 10, 1, 0, true); if (auxSpritePixels == null) { return null; @@ -96,7 +96,7 @@ public class ItemSpriteFactory else if (item.boughtTemplateId != -1) { auxSpritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider, - item.boughtId, quantity, border, shadowColor, false); + item.boughtId, quantity, border, shadowColor, false); if (auxSpritePixels == null) { return null; @@ -105,7 +105,7 @@ public class ItemSpriteFactory else if (item.placeholderTemplateId != -1) { auxSpritePixels = createSpritePixels(itemProvider, modelProvider, spriteProvider, textureProvider, - item.placeholderId, quantity, 0, 0, false); + item.placeholderId, quantity, 0, 0, false); if (auxSpritePixels == null) { return null; @@ -114,7 +114,7 @@ public class ItemSpriteFactory RSTextureProvider rsTextureProvider = new RSTextureProvider(textureProvider, spriteProvider); - SpritePixels spritePixels = new SpritePixels(36, 32); + Sprite spritePixels = new Sprite(36, 32); Graphics3D graphics = new Graphics3D(rsTextureProvider); graphics.setBrightness(0.6d); graphics.setRasterBuffer(spritePixels.pixels, 36, 32); @@ -142,12 +142,12 @@ public class ItemSpriteFactory itemModel.calculateBoundsCylinder(); itemModel.rotateAndProject(graphics, 0, - item.yan2d, - item.zan2d, - item.xan2d, - item.xOffset2d, - itemModel.modelHeight / 2 + var17 + item.yOffset2d, - var18 + item.yOffset2d); + item.yan2d, + item.zan2d, + item.xan2d, + item.xOffset2d, + itemModel.modelHeight / 2 + var17 + item.yOffset2d, + var18 + item.yOffset2d); if (item.boughtTemplateId != -1) { auxSpritePixels.drawAtOn(graphics, 0, 0); @@ -175,8 +175,8 @@ public class ItemSpriteFactory } graphics.setRasterBuffer(graphics.graphicsPixels, - graphics.graphicsPixelsWidth, - graphics.graphicsPixelsHeight); + graphics.graphicsPixelsWidth, + graphics.graphicsPixelsHeight); graphics.setRasterClipping(); graphics.rasterGouraudLowRes = true; diff --git a/cache/src/main/java/net/runelite/cache/item/SpritePixels.java b/cache/src/main/java/net/runelite/cache/item/SpritePixels.java index 02079847f7..ed8be85a18 100644 --- a/cache/src/main/java/net/runelite/cache/item/SpritePixels.java +++ b/cache/src/main/java/net/runelite/cache/item/SpritePixels.java @@ -26,7 +26,7 @@ package net.runelite.cache.item; import java.awt.image.BufferedImage; -class SpritePixels +class Sprite { public int[] pixels; public int width; @@ -34,7 +34,7 @@ class SpritePixels public int offsetX; int offsetY; - public SpritePixels(int[] var1, int var2, int var3) + public Sprite(int[] var1, int var2, int var3) { this.pixels = var1; this.width = var2; @@ -43,7 +43,7 @@ class SpritePixels this.offsetX = 0; } - public SpritePixels(int var1, int var2) + public Sprite(int var1, int var2) { this(new int[var2 * var1], var1, var2); } diff --git a/deobfuscator/pom.xml b/deobfuscator/pom.xml new file mode 100644 index 0000000000..d165e2b933 --- /dev/null +++ b/deobfuscator/pom.xml @@ -0,0 +1,174 @@ + + + + 4.0.0 + + + net.runelite + runelite-parent + 1.5.27-SNAPSHOT + + + deobfuscator + Deobfuscator + + + + net.runelite + runelite-api + ${project.version} + + + net.runelite.rs + runescape-api + ${project.version} + + + net.runelite + fernflower + 20171017 + + + + com.google.guava + guava + 27.1-jre + + + org.slf4j + slf4j-api + 1.8.0-beta4 + + + org.slf4j + slf4j-simple + 1.7.12 + + + com.google.code.gson + gson + 2.8.5 + + + org.ow2.asm + asm-debug-all + 5.2 + + + + net.runelite + runescape-client + ${project.version} + test + + + net.runelite.rs + vanilla + ${rs.version} + test + + + junit + junit + 4.12 + test + + + org.mockito + mockito-all + 1.10.19 + test + + + + + + + src/main/resources + true + + + + + src/test/resources + true + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + generate-sources + + + properties + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + true + -Xmx2048m + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/deobfuscator/src/main/java/net/runelite/asm/ClassFile.java b/deobfuscator/src/main/java/net/runelite/asm/ClassFile.java new file mode 100644 index 0000000000..dcbbd91bac --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/ClassFile.java @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import java.util.ArrayList; +import java.util.List; +import net.runelite.asm.attributes.Annotations; +import net.runelite.asm.attributes.annotation.Annotation; +import net.runelite.asm.pool.Class; +import net.runelite.asm.signature.Signature; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +public class ClassFile +{ + private ClassGroup group; + + private ClassFile parent; // super class + private final List children = new ArrayList<>(); // classes which inherit from this + + private int version; + private int access; + private Class name; + private Class super_class; + private String source; + private final Interfaces interfaces; + private final List fields = new ArrayList<>(); + private final List methods = new ArrayList<>(); + private final Annotations annotations; + + public ClassFile(ClassGroup group) + { + this.group = group; + + interfaces = new Interfaces(this); + annotations = new Annotations(); + } + + public ClassFile() + { + this(null); + } + + @Override + public String toString() + { + return "ClassFile{" + "name=" + name + '}'; + } + + public int getVersion() + { + return version; + } + + public void setVersion(int version) + { + this.version = version; + } + + public int getAccess() + { + return access; + } + + public void setAccess(int access) + { + this.access = access; + } + + public void accept(ClassVisitor visitor) + { + String[] ints = interfaces.getInterfaces().stream().map(i -> i.getName()).toArray(String[]::new); + + visitor.visit(version, access, name.getName(), null, super_class.getName(), ints); + visitor.visitSource(source, null); + + for (Annotation annotation : annotations.getAnnotations()) + { + AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true); + annotation.accept(av); + } + + for (Field field : fields) + { + FieldVisitor fv = visitor.visitField(field.getAccessFlags(), field.getName(), field.getType().toString(), null, field.getValue()); + field.accept(fv); + } + + for (Method method : methods) + { + String[] exceptions = method.getExceptions().getExceptions().stream().map(cl -> cl.getName()).toArray(String[]::new); + if (exceptions.length == 0) + { + exceptions = null; + } + + MethodVisitor mv = visitor.visitMethod(method.getAccessFlags(), method.getName(), method.getDescriptor().toString(), null, exceptions); + method.accept(mv); + } + + visitor.visitEnd(); + } + + public ClassGroup getGroup() + { + return group; + } + + public void setGroup(ClassGroup group) + { + this.group = group; + } + + public Interfaces getInterfaces() + { + return interfaces; + } + + public List getFields() + { + return fields; + } + + public void addField(Field field) + { + fields.add(field); + } + + public void removeField(Field field) + { + fields.remove(field); + } + + public List getMethods() + { + return methods; + } + + public void addMethod(Method method) + { + methods.add(method); + } + + public void removeMethod(Method method) + { + methods.remove(method); + } + + public Annotations getAnnotations() + { + return annotations; + } + + public String getName() + { + return name.getName(); + } + + public void setName(String name) + { + // Must be removed from the class group map first + assert group == null || this.name == null || group.findClass(this.name.getName()) == null; + + this.name = new Class(name); + } + + public String getClassName() + { + String n = getName(); + int i = n.lastIndexOf('/'); + return n.substring(i + 1); + } + + public String getSuperName() + { + return super_class.getName(); + } + + public void setSuperName(String name) + { + super_class = new Class(name); + } + + public String getSource() + { + return source; + } + + public void setSource(String source) + { + this.source = source; + } + + public Class getParentClass() + { + return this.super_class; + } + + public void setParentClass(Class c) + { + super_class = c; + } + + public ClassFile getParent() + { + return parent; + } + + public List getChildren() + { + return children; + } + + public Field findField(String name, Type type) + { + for (Field f : fields) + { + if (f.getName().equals(name) && f.getType().equals(type)) + { + return f; + } + } + return null; + } + + public Field findField(String name) + { + for (Field f : fields) + { + if (f.getName().equals(name)) + { + return f; + } + } + return null; + } + + public Class getPoolClass() + { + return name; + } + + public Field findFieldDeep(String name, Type type) + { + Field f = findField(name, type); + if (f != null) + { + return f; + } + + ClassFile parent = getParent(); + if (parent != null) + { + return parent.findFieldDeep(name, type); + } + + return null; + } + + public Method findMethod(String name, Signature type) + { + for (Method m : methods) + { + if (m.getName().equals(name) && m.getDescriptor().equals(type)) + { + return m; + } + } + return null; + } + + public Method findMethod(String name) + { + for (Method m : methods) + { + if (m.getName().equals(name)) + { + return m; + } + } + return null; + } + + public Method findMethodDeep(String name, Signature type) + { + Method m = findMethod(name, type); + if (m != null) + { + return m; + } + + ClassFile parent = getParent(); + if (parent != null) + { + return parent.findMethodDeep(name, type); + } + + return null; + } + + public Method findMethodDeepStatic(String name, Signature type) + { + Method m = findMethod(name, type); + if (m != null && m.isStatic()) + { + return m; + } + + ClassFile parent = getParent(); + if (parent != null) + { + return parent.findMethodDeepStatic(name, type); + } + + return null; + } + + public Method findMethodDeep(String name) + { + Method m = findMethod(name); + if (m != null) + { + return m; + } + + ClassFile parent = getParent(); + if (parent != null) + { + return parent.findMethodDeep(name); + } + + return null; + } + + public void clearClassGraph() + { + parent = null; + children.clear(); + } + + public void buildClassGraph() + { + ClassFile other = group.findClass(super_class.getName()); + if (other != null) + { + this.parent = other; + parent.children.add(this); + } + + for (ClassFile i : interfaces.getMyInterfaces()) + { + i.children.add(this); + } + } + + public boolean instanceOf(ClassFile other) + { + return this == other || interfaces.instanceOf(other) || (getParent() != null && getParent().instanceOf(other)); + } + + public boolean isAbstract() + { + return (this.access & Opcodes.ACC_ABSTRACT) != 0; + } + + public boolean isFinal() + { + return (this.access & Opcodes.ACC_FINAL) != 0; + } + + public boolean isInterface() + { + return (this.access & Opcodes.ACC_INTERFACE) != 0; + } + + public boolean isEnum() + { + return (this.access & Opcodes.ACC_ENUM) != 0; + } + + public void setEnum() + { + this.access |= Opcodes.ACC_ENUM; + } + + public void clearFinal() + { + this.access &= ~Opcodes.ACC_FINAL; + } + + public void clearAbstract() + { + this.access &= ~Opcodes.ACC_ABSTRACT; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/ClassGroup.java b/deobfuscator/src/main/java/net/runelite/asm/ClassGroup.java new file mode 100644 index 0000000000..2c6ba531a5 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/ClassGroup.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.runelite.asm.attributes.Code; + +public class ClassGroup +{ + private final List classes = new ArrayList<>(); // to keep order + private final Map classMap = new HashMap<>(); + + public void addClass(ClassFile cf) + { + assert cf.getGroup() == this || cf.getGroup() == null; + cf.setGroup(this); + + classes.add(cf); + classMap.put(cf.getName(), cf); + } + + public void removeClass(ClassFile cf) + { + classes.remove(cf); + classMap.remove(cf.getName()); + } + + public void renameClass(ClassFile cf, String newName) + { + assert classes.contains(cf); + assert classMap.get(cf.getName()) == cf; + + classMap.remove(cf.getName()); + cf.setName(newName); + classMap.put(cf.getName(), cf); + } + + public List getClasses() + { + return Collections.unmodifiableList(classes); + } + + public ClassFile findClass(String name) + { + return classMap.get(name); + } + + public void initialize() + { + buildClassGraph(); + lookup(); + } + + public void buildClassGraph() + { + for (ClassFile c : classes) + { + c.clearClassGraph(); + } + + for (ClassFile c : classes) + { + c.buildClassGraph(); + } + } + + public void lookup() + { + for (ClassFile cf : this.getClasses()) + { + for (Method m : cf.getMethods()) + { + Code code = m.getCode(); + + if (code == null) + { + continue; + } + + code.getInstructions().lookup(); + } + } + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/Field.java b/deobfuscator/src/main/java/net/runelite/asm/Field.java new file mode 100644 index 0000000000..8d70053adb --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/Field.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import net.runelite.asm.attributes.Annotations; +import net.runelite.asm.attributes.annotation.Annotation; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.Opcodes; + +import static org.objectweb.asm.Opcodes.ACC_PRIVATE; +import static org.objectweb.asm.Opcodes.ACC_PROTECTED; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; + +public class Field +{ + public static final int ACCESS_MODIFIERS = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED; + + private final ClassFile classFile; + + private int accessFlags; + private String name; + private Type type; + private Object value; // ConstantValue + private final Annotations annotations; + + public Field(ClassFile classFile, String name, Type type) + { + this.classFile = classFile; + this.name = name; + this.type = type; + + annotations = new Annotations(); + } + + public void accept(FieldVisitor visitor) + { + for (Annotation annotation : annotations.getAnnotations()) + { + AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true); + annotation.accept(av); + } + + visitor.visitEnd(); + } + + public ClassFile getClassFile() + { + return classFile; + } + + public int getAccessFlags() + { + return accessFlags; + } + + public void setAccessFlags(int accessFlags) + { + this.accessFlags = accessFlags; + } + + public boolean isPublic() + { + return (accessFlags & Opcodes.ACC_PUBLIC) != 0; + } + + public void setPublic() + { + accessFlags = (short) ((accessFlags & ~ACCESS_MODIFIERS) | ACC_PUBLIC); + } + + public boolean isStatic() + { + return (accessFlags & Opcodes.ACC_STATIC) != 0; + } + + public void setStatic() + { + accessFlags |= Opcodes.ACC_STATIC; + } + + public boolean isSynthetic() + { + return (accessFlags & Opcodes.ACC_SYNTHETIC) != 0; + } + + public void setEnum() + { + accessFlags |= Opcodes.ACC_ENUM; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Type getType() + { + return type; + } + + public void setType(Type type) + { + this.type = type; + } + + public Object getValue() + { + return value; + } + + public void setValue(Object value) + { + this.value = value; + } + + public Annotations getAnnotations() + { + return annotations; + } + + public net.runelite.asm.pool.Field getPoolField() + { + return new net.runelite.asm.pool.Field( + new net.runelite.asm.pool.Class(classFile.getName()), + this.getName(), + this.getType() + ); + } + + @Override + public String toString() + { + return (this.isStatic() ? "static " : "") + this.type + " " + classFile.getName() + "." + this.getName(); + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/Interfaces.java b/deobfuscator/src/main/java/net/runelite/asm/Interfaces.java new file mode 100644 index 0000000000..a372f9d68c --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/Interfaces.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import net.runelite.asm.pool.Class; + +public class Interfaces +{ + private final ClassFile classFile; + + private final List interfaces = new ArrayList<>(); + + Interfaces(ClassFile c) + { + classFile = c; + } + + public void addInterface(Class clazz) + { + if (!interfaces.contains(clazz)) + { + interfaces.add(clazz); + } + } + + public List getInterfaces() + { + return interfaces; + } + + public void clear() + { + interfaces.clear(); + } + + public List getMyInterfaces() + { + List l = new ArrayList<>(); + for (Class clazz : interfaces) + { + ClassFile iface = classFile.getGroup().findClass(clazz.getName()); + if (iface != null) + { + l.add(iface); + } + } + return l; + } + + public List getNonMyInterfaces() + { + return interfaces.stream().filter(clazz -> classFile.getGroup().findClass(clazz.getName()) == null).collect(Collectors.toList()); + } + + public boolean instanceOf(ClassFile cf) + { + for (Class clazz : interfaces) + { + ClassFile iface = classFile.getGroup().findClass(clazz.getName()); + if (iface.instanceOf(cf)) + { + return true; + } + } + return false; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/Method.java b/deobfuscator/src/main/java/net/runelite/asm/Method.java new file mode 100644 index 0000000000..bc2c8b305b --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/Method.java @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import java.util.ArrayList; +import java.util.List; +import net.runelite.asm.attributes.Annotations; +import net.runelite.asm.attributes.Code; +import net.runelite.asm.attributes.Exceptions; +import net.runelite.asm.attributes.annotation.Annotation; +import net.runelite.asm.attributes.code.Instruction; +import net.runelite.asm.attributes.code.LocalVariable; +import net.runelite.asm.attributes.code.Parameter; +import net.runelite.asm.attributes.code.instruction.types.LVTInstruction; +import net.runelite.asm.signature.Signature; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import static org.objectweb.asm.Opcodes.ACC_FINAL; +import static org.objectweb.asm.Opcodes.ACC_NATIVE; +import static org.objectweb.asm.Opcodes.ACC_PRIVATE; +import static org.objectweb.asm.Opcodes.ACC_PROTECTED; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; +import static org.objectweb.asm.Opcodes.ACC_STATIC; +import static org.objectweb.asm.Opcodes.ACC_SYNCHRONIZED; + +public class Method +{ + public static final int ACCESS_MODIFIERS = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED; + + private final ClassFile classFile; + + private int accessFlags; + private String name; + private Signature arguments; + private Exceptions exceptions; + private Annotations annotations; + private List parameters; + private Code code; + + public Method(ClassFile classFile, String name, Signature signature) + { + this.classFile = classFile; + this.name = name; + this.arguments = signature; + exceptions = new Exceptions(); + annotations = new Annotations(); + parameters = new ArrayList<>(); + } + + public ClassFile getClassFile() + { + return classFile; + } + + @Override + public String toString() + { + return (this.isStatic() ? "static " : "") + classFile.getName() + "." + this.name + this.arguments; + } + + public void accept(MethodVisitor visitor) + { + //This is required to name unused parameters + for (Parameter p : parameters) + { + visitor.visitParameter(p.getName(), p.getAccess()); + } + + for (Annotation annotation : annotations.getAnnotations()) + { + AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true); + annotation.accept(av); + } + + if (code != null) + { + code.getInstructions().rebuildLabels(); + + visitor.visitCode(); + + net.runelite.asm.attributes.code.Exceptions exceptions = code.getExceptions(); + for (net.runelite.asm.attributes.code.Exception exception : exceptions.getExceptions()) + { + assert exception.getStart().getLabel() != null; + assert exception.getEnd().getLabel() != null; + assert exception.getHandler().getLabel() != null; + + int idxStart = code.getInstructions().getInstructions().indexOf(exception.getStart()); + int idxEnd = code.getInstructions().getInstructions().indexOf(exception.getEnd()); + + assert idxStart != -1; + assert idxEnd != -1; + assert code.getInstructions().getInstructions().contains(exception.getHandler()); + + assert idxEnd > idxStart; + + visitor.visitTryCatchBlock( + exception.getStart().getLabel(), + exception.getEnd().getLabel(), + exception.getHandler().getLabel(), + exception.getCatchType() != null ? exception.getCatchType().getName() : null + ); + } + + for (Instruction i : code.getInstructions().getInstructions()) + { + i.accept(visitor); + } + + //Find first and last label for this method + if (parameters.size() > 0) + { + Label startLabel = null; + Label endLabel = null; + for (Instruction i : code.getInstructions().getInstructions()) + { + if (i instanceof net.runelite.asm.attributes.code.Label) + { + if (startLabel == null) + { + startLabel = ((net.runelite.asm.attributes.code.Label) i).getLabel(); + } + endLabel = ((net.runelite.asm.attributes.code.Label) i).getLabel(); + } + } + + for (Parameter p : parameters) + { + LocalVariable lv = p.getLocalVariable(); + if (lv != null) + { + visitor.visitLocalVariable(lv.getName(), lv.getDesc(), lv.getSignature(), startLabel, endLabel, lv.getIndex()); + } + } + } + + visitor.visitMaxs(code.getMaxStack(), code.getMaxLocals()); + } + + visitor.visitEnd(); + } + + public int getAccessFlags() + { + return accessFlags; + } + + public void setAccessFlags(int accessFlags) + { + this.accessFlags = accessFlags; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Signature getDescriptor() + { + return arguments; + } + + public void setDescriptor(Signature signature) + { + this.arguments = signature; + } + + public boolean isNative() + { + return (accessFlags & ACC_NATIVE) != 0; + } + + public boolean isStatic() + { + return (accessFlags & ACC_STATIC) != 0; + } + + public void setStatic() + { + accessFlags |= ACC_STATIC; + } + + public boolean isSynchronized() + { + return (accessFlags & ACC_SYNCHRONIZED) != 0; + } + + public boolean isFinal() + { + return (accessFlags & ACC_FINAL) != 0; + } + + public void setFinal(boolean f) + { + if (f) + { + accessFlags |= ACC_FINAL; + } + else + { + accessFlags &= ~ACC_FINAL; + } + } + + public boolean isPrivate() + { + return (accessFlags & ACC_PRIVATE) != 0; + } + + public void setPrivate() + { + accessFlags = (short) ((accessFlags & ~ACCESS_MODIFIERS) | ACC_PRIVATE); + } + + public void setPublic() + { + accessFlags = (short) ((accessFlags & ~ACCESS_MODIFIERS) | ACC_PUBLIC); + } + + public Exceptions getExceptions() + { + return exceptions; + } + + public Code getCode() + { + return code; + } + + public void setCode(Code code) + { + this.code = code; + } + + public Annotations getAnnotations() + { + return annotations; + } + + @SuppressWarnings("unchecked") + public List findLVTInstructionsForVariable(int index) + { + List list = new ArrayList<>(); + + if (getCode() == null) + { + return null; + } + + for (Instruction ins : getCode().getInstructions().getInstructions()) + { + if (ins instanceof LVTInstruction) + { + LVTInstruction lv = (LVTInstruction) ins; + + if (lv.getVariableIndex() != index) + { + continue; + } + + list.add((T) ins); + } + } + + return list; + } + + public net.runelite.asm.pool.Method getPoolMethod() + { + return new net.runelite.asm.pool.Method( + new net.runelite.asm.pool.Class(classFile.getName()), + name, + arguments + ); + } + + public List getParameters() + { + return parameters; + } + + public void setParameters(List parameters) + { + this.parameters = parameters; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/Type.java b/deobfuscator/src/main/java/net/runelite/asm/Type.java new file mode 100644 index 0000000000..68ba6960d4 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/Type.java @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm; + +import net.runelite.asm.pool.Class; + +/** + * Created by Kyle Fricilone on 8/20/2017 + */ +public class Type +{ + + public static final Type VOID = new Type("V"); + public static final Type BOOLEAN = new Type("Z"); + public static final Type CHAR = new Type("C"); + public static final Type BYTE = new Type("B"); + public static final Type SHORT = new Type("S"); + public static final Type INT = new Type("I"); + public static final Type FLOAT = new Type("F"); + public static final Type LONG = new Type("J"); + public static final Type DOUBLE = new Type("D"); + public static final Type OBJECT = new Type("Ljava/lang/Object;"); + public static final Type STRING = new Type("Ljava/lang/String;"); + public static final Type THROWABLE = new Type("Ljava/lang/Throwable;"); + public static final Type EXCEPTION = new Type("Ljava/lang/Exception;"); + + private final String type; + + public Type(String type) + { + this.type = type; + } + + public boolean isPrimitive() + { + return this.equals(BOOLEAN) || this.equals(BYTE) || this.equals(SHORT) || this.equals(CHAR) || this.equals(INT) + || this.equals(VOID) || this.equals(LONG) || this.equals(FLOAT) || this.equals(DOUBLE); + } + + public boolean isObject() + { + return this.equals(OBJECT); + } + + public boolean isArray() + { + return getDimensions() > 0; + } + + public boolean isStackInt() + { + return this.equals(BOOLEAN) || this.equals(BYTE) || this.equals(SHORT) || this.equals(CHAR) || this.equals(INT); + } + + public int getSize() + { + if (this.equals(LONG) || this.equals(DOUBLE)) + { + return 2; + } + + if (this.equals(VOID)) + { + return 0; + } + + return 1; + } + + public int getDimensions() + { + return getDimensions(type); + } + + public Type getSubtype() + { + if (!type.startsWith("[")) + { + throw new IllegalStateException(type + " is not an array"); + } + return new Type(type.substring(1)); + } + + public String getInternalName() + { + String s = type; + while (s.startsWith("[")) + { + s = s.substring(1); + } + if (s.startsWith("L")) + { + return s.substring(1, s.length() - 1); + } + else + { + return s; + } + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof Type)) + { + return false; + } + + Type other = (Type) o; + return type.equals(other.type); + } + + @Override + public int hashCode() + { + return type.hashCode(); + } + + @Override + public String toString() + { + return type; + } + + public String toAsmString() + { + if (type.startsWith("L") && type.endsWith(";")) + { + return type.substring(1, type.length() - 1); + } + else + { + return type; + } + } + + public static Type fromAsmString(String str) + { + if (str.startsWith("[")) + { + // array type + return new Type(str); + } + else + { + // object type + return new Type("L" + str + ";"); + } + } + + private static int getDimensions(String type) + { + if (!type.startsWith("[")) + { + return 0; + } + + return (int) type.chars().filter(i -> i == '[').count(); + } + + public static Type getType(String type, int dims) + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < dims; i++) + { + builder.append('['); + } + return new Type(builder.append(type).toString()); + } + + public static Type getType(Object object) + { + Type type; + + if (object instanceof Double) + { + type = DOUBLE; + } + else if (object instanceof Float) + { + type = FLOAT; + } + else if (object instanceof Integer) + { + type = INT; + } + else if (object instanceof Long) + { + type = LONG; + } + else if (object instanceof String) + { + type = STRING; + } + else if (object instanceof Class) + { + type = new Type("L" + ((Class) object).getName() + ";"); + } + else + { + throw new IllegalArgumentException("Unexpected object type: " + object.getClass()); + } + + return type; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/Annotations.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/Annotations.java new file mode 100644 index 0000000000..b14d761c28 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/Annotations.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes; + +import java.util.ArrayList; +import java.util.List; + +import net.runelite.asm.Type; +import net.runelite.asm.attributes.annotation.Annotation; +import net.runelite.asm.attributes.annotation.Element; + +public class Annotations +{ + private final List annotations = new ArrayList<>(); + + public List getAnnotations() + { + return annotations; + } + + public void addAnnotation(Annotation annotation) + { + annotations.add(annotation); + } + + public void removeAnnotation(Annotation annotation) + { + annotations.remove(annotation); + } + + public void clearAnnotations() + { + annotations.clear(); + } + + public Annotation find(Type type) + { + for (Annotation a : annotations) + if (a.getType().equals(type)) + return a; + return null; + } + + public int size() + { + return annotations.size(); + } + + public Annotation addAnnotation(Type type, String name, Object value) + { + Annotation annotation = new Annotation(this); + annotation.setType(type); + addAnnotation(annotation); + + Element element = new Element(annotation); + element.setName(name); + element.setValue(value); + annotation.addElement(element); + + return annotation; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/Code.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/Code.java new file mode 100644 index 0000000000..2a3f08126c --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/Code.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes; + +import net.runelite.asm.Method; +import net.runelite.asm.attributes.code.Exceptions; +import net.runelite.asm.attributes.code.Instruction; +import net.runelite.asm.attributes.code.Instructions; +import net.runelite.asm.attributes.code.instruction.types.LVTInstruction; +import net.runelite.asm.signature.Signature; + +public class Code +{ + private Method method; + private int maxStack; + private Instructions instructions; + private final Exceptions exceptions; + + public Code(Method method) + { + this.method = method; + + exceptions = new Exceptions(this); + instructions = new Instructions(this); + } + + public Method getMethod() + { + return method; + } + + public int getMaxStack() + { + return maxStack; + } + + public void setMaxStack(int maxStack) + { + this.maxStack = maxStack; + } + + private int getMaxLocalsFromSig() + { + Method m = getMethod(); + int num = m.isStatic() ? 0 : 1; + Signature sig = m.getDescriptor(); + for (int i = 0; i < sig.size(); ++i) + num += sig.getTypeOfArg(i).getSize(); + return num; + } + + /** + * calculates the size of the lvt required for this method + * @return + */ + public int getMaxLocals() + { + int max = -1; + + for (Instruction ins : instructions.getInstructions()) + { + if (ins instanceof LVTInstruction) + { + LVTInstruction lvt = (LVTInstruction) ins; + + int sizeRequired = lvt.getVariableIndex() + lvt.type().getSlots(); + if (sizeRequired > max) + { + max = sizeRequired; + } + } + } + + int fromSig = getMaxLocalsFromSig(); + if (fromSig > max) + max = fromSig; + + return max; + } + + public Exceptions getExceptions() + { + return exceptions; + } + + public Instructions getInstructions() + { + return instructions; + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSItem.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/Exceptions.java similarity index 69% rename from runescape-api/src/main/java/net/runelite/rs/api/RSItem.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/Exceptions.java index 4f451cf028..0b12c513fd 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSItem.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/Exceptions.java @@ -22,39 +22,38 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; -import net.runelite.api.Item; -import net.runelite.api.Tile; -import net.runelite.mapping.Import; +package net.runelite.asm.attributes; -public interface RSItem extends RSRenderable, Item +import java.util.ArrayList; +import java.util.List; +import net.runelite.asm.ClassFile; +import net.runelite.asm.pool.Class; + +public class Exceptions { - @Import("id") - @Override - int getId(); + private final List classes = new ArrayList<>(); - @Import("id") - void setId(int id); + public void addException(Class cl) + { + classes.add(cl); + } - @Import("quantity") - @Override - int getQuantity(); - - @Import("quantity") - void setQuantity(int quantity); - - int getX(); - - void setX(int x); - - int getY(); - - void setY(int y); - - /** - * Get the tile this item is on - * @return - */ - Tile getTile(); + public List getExceptions() + { + return classes; + } + + public void renameClass(ClassFile cf, String name) + { + for (Class c : new ArrayList<>(classes)) + { + if (c.getName().equals(cf.getName())) + { + int idx = classes.indexOf(c); + classes.remove(idx); + classes.add(idx, new Class(name)); + } + } + } } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Annotation.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Annotation.java new file mode 100644 index 0000000000..7c727eb788 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Annotation.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.annotation; + +import java.util.ArrayList; +import java.util.List; + +import net.runelite.asm.Type; +import net.runelite.asm.attributes.Annotations; +import org.objectweb.asm.AnnotationVisitor; + +public class Annotation +{ + private final Annotations annotations; + private Type type; + private final List elements = new ArrayList<>(); + + public Annotation(Annotations annotations) + { + this.annotations = annotations; + } + + public Annotations getAnnotations() + { + return annotations; + } + + public void setType(Type type) + { + this.type = type; + } + + public Type getType() + { + return type; + } + + public List getElements() + { + return elements; + } + + public Element getElement() + { + return elements.get(0); + } + + public void addElement(Element element) + { + elements.add(element); + } + + public void accept(AnnotationVisitor visitor) + { + for (Element element : elements) + visitor.visit(element.getName(), element.getValue()); + visitor.visitEnd(); + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSMessageNode.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Element.java similarity index 70% rename from runescape-api/src/main/java/net/runelite/rs/api/RSMessageNode.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Element.java index f673e58c7a..18fdfa33f4 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSMessageNode.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/annotation/Element.java @@ -22,41 +22,47 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; -import net.runelite.api.MessageNode; -import net.runelite.mapping.Import; +package net.runelite.asm.attributes.annotation; -public interface RSMessageNode extends MessageNode +public class Element { - @Import("id") - @Override - int getId(); + private final Annotation annotation; + private String name; + private Object value; + + public Element(Annotation annotation) + { + this.annotation = annotation; + } - @Import("type") - int getRSType(); + public Annotation getAnnotation() + { + return annotation; + } - @Import("name") - @Override - String getName(); + public String getName() + { + return name; + } - @Import("name") - @Override - void setName(String name); + public void setName(String name) + { + this.name = name; + } - @Import("sender") - @Override - String getSender(); + public Object getValue() + { + return value; + } - @Import("sender") - @Override - void setSender(String sender); - - @Import("value") - @Override - String getValue(); - - @Import("value") - @Override - void setValue(String value); + public void setValue(Object value) + { + this.value = value; + } + + public String getString() + { + return value.toString(); + } } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exception.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exception.java new file mode 100644 index 0000000000..b1209a6631 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exception.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code; + +import net.runelite.asm.ClassFile; +import net.runelite.asm.pool.Class; + +public class Exception implements Cloneable +{ + private Exceptions exceptions; + + private Label start, end, handler; + private Class catchType; + + public Exception(Exceptions exceptions) + { + this.exceptions = exceptions; + } + + @Override + public Exception clone() + { + try + { + return (Exception) super.clone(); + } + catch (CloneNotSupportedException ex) + { + throw new RuntimeException(); + } + } + + public Exceptions getExceptions() + { + return exceptions; + } + + public void setExceptions(Exceptions exceptions) + { + this.exceptions = exceptions; + } + + public Label getStart() + { + return start; + } + + public void setStart(Label ins) + { + start = ins; + } + + public Label getEnd() + { + return end; + } + + public void setEnd(Label end) + { + this.end = end; + } + + public Label getHandler() + { + return handler; + } + + public void setHandler(Label handler) + { + this.handler = handler; + } + + public Class getCatchType() + { + return catchType; + } + + public void setCatchType(Class catchType) + { + this.catchType = catchType; + } + + public void renameClass(ClassFile cf, String name) + { + if (catchType != null && cf.getName().equals(catchType.getName())) + catchType = new Class(name); + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exceptions.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exceptions.java new file mode 100644 index 0000000000..30b00a0115 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Exceptions.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code; + +import java.util.ArrayList; +import java.util.List; +import net.runelite.asm.ClassFile; +import net.runelite.asm.attributes.Code; + +public class Exceptions +{ + private Code code; + private List exceptions = new ArrayList(); + + public Exceptions(Code code) + { + this.code = code; + } + + public void add(Exception e) + { + exceptions.add(e); + } + + public void remove(Exception e) + { + exceptions.remove(e); + } + + public void clear() + { + exceptions.clear(); + } + + public Code getCode() + { + return code; + } + + public List getExceptions() + { + return exceptions; + } + + public void renameClass(ClassFile cf, String name) + { + for (Exception e : exceptions) + e.renameClass(cf, name); + } +} \ No newline at end of file diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instruction.java new file mode 100644 index 0000000000..bf8e64535e --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instruction.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code; + +import net.runelite.asm.Method; +import net.runelite.asm.execution.Frame; +import net.runelite.asm.execution.InstructionContext; +import org.objectweb.asm.MethodVisitor; + +public abstract class Instruction implements Cloneable +{ + private Instructions instructions; + private InstructionType type; + + public Instruction(Instructions instructions, InstructionType type) + { + this.instructions = instructions; + this.type = type; + } + + @Override + public String toString() + { + if (this.getInstructions() != null) + { + Method m = this.getInstructions().getCode().getMethod(); + return super.toString() + " in " + m;// + " at pc 0x" + Integer.toHexString(this.getPc()); + } + else + { + return super.toString() + " "; + } + } + + @Override + public Instruction clone() + { + Instruction i; + try + { + i = (Instruction) super.clone(); + } + catch (CloneNotSupportedException ex) + { + throw new RuntimeException(ex); + } + + return i; + } + + protected void remove() + { + Exceptions exceptions = instructions.getCode().getExceptions(); + for (Exception e : exceptions.getExceptions()) + { + assert this != e.getStart(); + assert this != e.getEnd(); + assert this != e.getHandler(); + } + } + + public boolean removeStack() + { + assert instructions != null; + + this.getInstructions().remove(this); // calls remove() + + return true; + } + + // resolve jumps + public void resolve() + { + } + + public void accept(MethodVisitor visitor) + { + visitor.visitInsn(this.getType().getCode()); + } + + public Instructions getInstructions() + { + return instructions; + } + + public void setInstructions(Instructions instructions) + { + this.instructions = instructions; + } + + public InstructionType getType() + { + return type; + } + + protected void setType(InstructionType type) + { + this.type = type; + } + + public abstract InstructionContext execute(Frame e); + + /* does this terminate a block? */ + public boolean isTerminal() + { + return false; + } + + // look up symbols from pool + public void lookup() + { + } + + // instructions keep resolved method/field/class names, this updates the pool value (if the underlying resolved object changes) + public void regeneratePool() + { + } + + public void renameClass(String oldName, String newName) + { + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/InstructionType.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/InstructionType.java new file mode 100644 index 0000000000..919da1bb02 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/InstructionType.java @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code; + +import net.runelite.asm.attributes.code.instructions.AALoad; +import net.runelite.asm.attributes.code.instructions.AAStore; +import net.runelite.asm.attributes.code.instructions.AConstNull; +import net.runelite.asm.attributes.code.instructions.ALoad; +import net.runelite.asm.attributes.code.instructions.ANewArray; +import net.runelite.asm.attributes.code.instructions.AStore; +import net.runelite.asm.attributes.code.instructions.AThrow; +import net.runelite.asm.attributes.code.instructions.ArrayLength; +import net.runelite.asm.attributes.code.instructions.BALoad; +import net.runelite.asm.attributes.code.instructions.BAStore; +import net.runelite.asm.attributes.code.instructions.BiPush; +import net.runelite.asm.attributes.code.instructions.CALoad; +import net.runelite.asm.attributes.code.instructions.CAStore; +import net.runelite.asm.attributes.code.instructions.CheckCast; +import net.runelite.asm.attributes.code.instructions.D2F; +import net.runelite.asm.attributes.code.instructions.D2I; +import net.runelite.asm.attributes.code.instructions.D2L; +import net.runelite.asm.attributes.code.instructions.DALoad; +import net.runelite.asm.attributes.code.instructions.DAStore; +import net.runelite.asm.attributes.code.instructions.DAdd; +import net.runelite.asm.attributes.code.instructions.DCmpG; +import net.runelite.asm.attributes.code.instructions.DCmpL; +import net.runelite.asm.attributes.code.instructions.DDiv; +import net.runelite.asm.attributes.code.instructions.DLoad; +import net.runelite.asm.attributes.code.instructions.DMul; +import net.runelite.asm.attributes.code.instructions.DNeg; +import net.runelite.asm.attributes.code.instructions.DRem; +import net.runelite.asm.attributes.code.instructions.DStore; +import net.runelite.asm.attributes.code.instructions.DSub; +import net.runelite.asm.attributes.code.instructions.Dup; +import net.runelite.asm.attributes.code.instructions.Dup2; +import net.runelite.asm.attributes.code.instructions.Dup2_X1; +import net.runelite.asm.attributes.code.instructions.Dup2_X2; +import net.runelite.asm.attributes.code.instructions.Dup_X1; +import net.runelite.asm.attributes.code.instructions.Dup_X2; +import net.runelite.asm.attributes.code.instructions.F2D; +import net.runelite.asm.attributes.code.instructions.F2I; +import net.runelite.asm.attributes.code.instructions.F2L; +import net.runelite.asm.attributes.code.instructions.FALoad; +import net.runelite.asm.attributes.code.instructions.FAStore; +import net.runelite.asm.attributes.code.instructions.FAdd; +import net.runelite.asm.attributes.code.instructions.FCmpG; +import net.runelite.asm.attributes.code.instructions.FCmpL; +import net.runelite.asm.attributes.code.instructions.FDiv; +import net.runelite.asm.attributes.code.instructions.FLoad; +import net.runelite.asm.attributes.code.instructions.FMul; +import net.runelite.asm.attributes.code.instructions.FNeg; +import net.runelite.asm.attributes.code.instructions.FRem; +import net.runelite.asm.attributes.code.instructions.FStore; +import net.runelite.asm.attributes.code.instructions.FSub; +import net.runelite.asm.attributes.code.instructions.GetField; +import net.runelite.asm.attributes.code.instructions.GetStatic; +import net.runelite.asm.attributes.code.instructions.Goto; +import net.runelite.asm.attributes.code.instructions.GotoW; +import net.runelite.asm.attributes.code.instructions.I2B; +import net.runelite.asm.attributes.code.instructions.I2C; +import net.runelite.asm.attributes.code.instructions.I2D; +import net.runelite.asm.attributes.code.instructions.I2F; +import net.runelite.asm.attributes.code.instructions.I2L; +import net.runelite.asm.attributes.code.instructions.I2S; +import net.runelite.asm.attributes.code.instructions.IALoad; +import net.runelite.asm.attributes.code.instructions.IAStore; +import net.runelite.asm.attributes.code.instructions.IAdd; +import net.runelite.asm.attributes.code.instructions.IAnd; +import net.runelite.asm.attributes.code.instructions.IConstZero; +import net.runelite.asm.attributes.code.instructions.IDiv; +import net.runelite.asm.attributes.code.instructions.IInc; +import net.runelite.asm.attributes.code.instructions.ILoad; +import net.runelite.asm.attributes.code.instructions.IMul; +import net.runelite.asm.attributes.code.instructions.INeg; +import net.runelite.asm.attributes.code.instructions.IOr; +import net.runelite.asm.attributes.code.instructions.IRem; +import net.runelite.asm.attributes.code.instructions.IShL; +import net.runelite.asm.attributes.code.instructions.IShR; +import net.runelite.asm.attributes.code.instructions.IStore; +import net.runelite.asm.attributes.code.instructions.ISub; +import net.runelite.asm.attributes.code.instructions.IUShR; +import net.runelite.asm.attributes.code.instructions.IXor; +import net.runelite.asm.attributes.code.instructions.IfACmpEq; +import net.runelite.asm.attributes.code.instructions.IfACmpNe; +import net.runelite.asm.attributes.code.instructions.IfCmpGe; +import net.runelite.asm.attributes.code.instructions.IfCmpGt; +import net.runelite.asm.attributes.code.instructions.IfCmpLe; +import net.runelite.asm.attributes.code.instructions.IfCmpLt; +import net.runelite.asm.attributes.code.instructions.IfEq; +import net.runelite.asm.attributes.code.instructions.IfGe; +import net.runelite.asm.attributes.code.instructions.IfGt; +import net.runelite.asm.attributes.code.instructions.IfICmpEq; +import net.runelite.asm.attributes.code.instructions.IfICmpNe; +import net.runelite.asm.attributes.code.instructions.IfLe; +import net.runelite.asm.attributes.code.instructions.IfLt; +import net.runelite.asm.attributes.code.instructions.IfNe; +import net.runelite.asm.attributes.code.instructions.IfNonNull; +import net.runelite.asm.attributes.code.instructions.IfNull; +import net.runelite.asm.attributes.code.instructions.InstanceOf; +import net.runelite.asm.attributes.code.instructions.InvokeDynamic; +import net.runelite.asm.attributes.code.instructions.InvokeInterface; +import net.runelite.asm.attributes.code.instructions.InvokeSpecial; +import net.runelite.asm.attributes.code.instructions.InvokeStatic; +import net.runelite.asm.attributes.code.instructions.InvokeVirtual; +import net.runelite.asm.attributes.code.instructions.L2D; +import net.runelite.asm.attributes.code.instructions.L2F; +import net.runelite.asm.attributes.code.instructions.L2I; +import net.runelite.asm.attributes.code.instructions.LALoad; +import net.runelite.asm.attributes.code.instructions.LAStore; +import net.runelite.asm.attributes.code.instructions.LAdd; +import net.runelite.asm.attributes.code.instructions.LAnd; +import net.runelite.asm.attributes.code.instructions.LCmp; +import net.runelite.asm.attributes.code.instructions.LDC; +import net.runelite.asm.attributes.code.instructions.LDiv; +import net.runelite.asm.attributes.code.instructions.LLoad; +import net.runelite.asm.attributes.code.instructions.LMul; +import net.runelite.asm.attributes.code.instructions.LNeg; +import net.runelite.asm.attributes.code.instructions.LOr; +import net.runelite.asm.attributes.code.instructions.LRem; +import net.runelite.asm.attributes.code.instructions.LShL; +import net.runelite.asm.attributes.code.instructions.LShR; +import net.runelite.asm.attributes.code.instructions.LStore; +import net.runelite.asm.attributes.code.instructions.LSub; +import net.runelite.asm.attributes.code.instructions.LUShR; +import net.runelite.asm.attributes.code.instructions.LXor; +import net.runelite.asm.attributes.code.instructions.LookupSwitch; +import net.runelite.asm.attributes.code.instructions.MonitorEnter; +import net.runelite.asm.attributes.code.instructions.MonitorExit; +import net.runelite.asm.attributes.code.instructions.MultiANewArray; +import net.runelite.asm.attributes.code.instructions.NOP; +import net.runelite.asm.attributes.code.instructions.New; +import net.runelite.asm.attributes.code.instructions.NewArray; +import net.runelite.asm.attributes.code.instructions.Pop; +import net.runelite.asm.attributes.code.instructions.Pop2; +import net.runelite.asm.attributes.code.instructions.PutField; +import net.runelite.asm.attributes.code.instructions.PutStatic; +import net.runelite.asm.attributes.code.instructions.Return; +import net.runelite.asm.attributes.code.instructions.SALoad; +import net.runelite.asm.attributes.code.instructions.SAStore; +import net.runelite.asm.attributes.code.instructions.SiPush; +import net.runelite.asm.attributes.code.instructions.Swap; +import net.runelite.asm.attributes.code.instructions.TableSwitch; +import net.runelite.asm.attributes.code.instructions.VReturn; + +public enum InstructionType +{ + NOP(0x00, "nop", NOP.class), + ACONST_NULL(0x01, "aconst_null", AConstNull.class), + ICONST_0(0x03, "iconst_0", IConstZero.class), + BIPUSH(0x10, "bipush", BiPush.class), + SIPUSH(0x11, "sipush", SiPush.class), + LDC(-1, "ldc", LDC.class), + ILOAD(0x15, "iload", ILoad.class), + LLOAD(0x16, "lload", LLoad.class), + FLOAD(0x17, "fload", FLoad.class), + DLOAD(0x18, "dload", DLoad.class), + ALOAD(0x19, "aload", ALoad.class), + IALOAD(0x2e, "iaload", IALoad.class), + LALOAD(0x2f, "laload", LALoad.class), + FALOAD(0x30, "faload", FALoad.class), + DALOAD(0x31, "daload", DALoad.class), + AALOAD(0x32, "aaload", AALoad.class), + BALOAD(0x33, "baload", BALoad.class), + CALOAD(0x34, "caload", CALoad.class), + SALOAD(0x35, "saload", SALoad.class), + ISTORE(0x36, "istore", IStore.class), + LSTORE(0x37, "lstore", LStore.class), + FSTORE(0x38, "fstore", FStore.class), + DSTORE(0x39, "dstore", DStore.class), + ASTORE(0x3a, "astore", AStore.class), + IASTORE(0x4f, "iastore", IAStore.class), + LASTORE(0x50, "lastore", LAStore.class), + FASTORE(0x51, "fastore", FAStore.class), + DASTORE(0x52, "dastore", DAStore.class), + AASTORE(0x53, "aastore", AAStore.class), + BASTORE(0x54, "bastore", BAStore.class), + CASTORE(0x55, "castore", CAStore.class), + SASTORE(0x56, "sastore", SAStore.class), + POP(0x57, "pop", Pop.class), + POP2(0x58, "pop2", Pop2.class), + DUP(0x59, "dup", Dup.class), + DUP_X1(0x5a, "dup_x1", Dup_X1.class), + DUP_X2(0x5b, "dup_x2", Dup_X2.class), + DUP2(0x5c, "dup2", Dup2.class), + DUP2_X1(0x5d, "dup2_x1", Dup2_X1.class), + DUP2_X2(0x5e, "dup2_x2", Dup2_X2.class), + SWAP(0x5f, "swap", Swap.class), + IADD(0x60, "iadd", IAdd.class), + LADD(0x61, "ladd", LAdd.class), + FADD(0x62, "fadd", FAdd.class), + DADD(0x63, "dadd", DAdd.class), + ISUB(0x64, "isub", ISub.class), + LSUB(0x65, "lsub", LSub.class), + FSUB(0x66, "fsub", FSub.class), + DSUB(0x67, "dsub", DSub.class), + IMUL(0x68, "imul", IMul.class), + LMUL(0x69, "lmul", LMul.class), + FMUL(0x6a, "fmul", FMul.class), + DMUL(0x6b, "dmul", DMul.class), + IDIV(0x6c, "idiv", IDiv.class), + LDIV(0x6d, "ldiv", LDiv.class), + FDIV(0x6e, "fdiv", FDiv.class), + DDIV(0x6f, "ddiv", DDiv.class), + IREM(0x70, "irem", IRem.class), + LREM(0x71, "lrem", LRem.class), + FREM(0x72, "frem", FRem.class), + DREM(0x73, "drem", DRem.class), + INEG(0x74, "ineg", INeg.class), + LNEG(0x75, "lneg", LNeg.class), + FNEG(0x76, "fneg", FNeg.class), + DNEG(0x77, "dneg", DNeg.class), + ISHL(0x78, "ishl", IShL.class), + LSHL(0x79, "lshl", LShL.class), + ISHR(0x7a, "ishr", IShR.class), + LSHR(0x7b, "lshr", LShR.class), + IUSHR(0x7c, "iushr", IUShR.class), + LUSHR(0x7d, "lushr", LUShR.class), + IAND(0x7e, "iand", IAnd.class), + LAND(0x7f, "land", LAnd.class), + IOR(0x80, "ior", IOr.class), + LOR(0x81, "lor", LOr.class), + IXOR(0x82, "ixor", IXor.class), + LXOR(0x83, "lxor", LXor.class), + IINC(0x84, "iinc", IInc.class), + I2L(0x85, "i2l", I2L.class), + I2F(0x86, "i2f", I2F.class), + I2D(0x87, "i2d", I2D.class), + L2I(0x88, "l2i", L2I.class), + L2F(0x89, "l2f", L2F.class), + L2D(0x8a, "l2d", L2D.class), + F2I(0x8b, "f2i", F2I.class), + F2L(0x8c, "f2l", F2L.class), + F2D(0x8d, "f2d", F2D.class), + D2I(0x8e, "d2i", D2I.class), + D2L(0x8f, "d2l", D2L.class), + D2F(0x90, "d2f", D2F.class), + I2B(0x91, "i2b", I2B.class), + I2C(0x92, "i2c", I2C.class), + I2S(0x93, "i2s", I2S.class), + LCMP(0x94, "lcmp", LCmp.class), + FCMPL(0x95, "fcmpl", FCmpL.class), + FCMPG(0x96, "fcmpg", FCmpG.class), + DCMPL(0x97, "dcmpl", DCmpL.class), + DCMPG(0x98, "dcmpg", DCmpG.class), + IFEQ(0x99, "ifeq", IfEq.class), + IFNE(0x9a, "ifne", IfNe.class), + IFLT(0x9b, "iflt", IfLt.class), + IFGE(0x9c, "ifge", IfGe.class), + IFGT(0x9d, "ifgt", IfGt.class), + IFLE(0x9e, "ifle", IfLe.class), + IF_ICMPEQ(0x9f, "if_icmpeq", IfICmpEq.class), + IF_ICMPNE(0xa0, "if_icmpne", IfICmpNe.class), + IF_ICMPLT(0xa1, "if_cmplt", IfCmpLt.class), + IF_ICMPGE(0xa2, "if_icmpge", IfCmpGe.class), + IF_ICMPGT(0xa3, "if_icmpgt", IfCmpGt.class), + IF_ICMPLE(0xa4, "if_icmple", IfCmpLe.class), + IF_ACMPEQ(0xa5, "if_acmpeq", IfACmpEq.class), + IF_ACMPNE(0xa6, "if_acmpne", IfACmpNe.class), + GOTO(0xa7, "goto", Goto.class), + TABLESWITCH(0xaa, "tableswitch", TableSwitch.class), + LOOKUPSWITCH(0xab, "lookupswitch", LookupSwitch.class), + IRETURN(0xac, "ireturn", Return.class), + LRETURN(0xad, "lreturn", Return.class), + FRETURN(0xae, "freturn", Return.class), + DRETURN(0xaf, "dreturn", Return.class), + ARETURN(0xb0, "areturn", Return.class), + RETURN(0xb1, "return", VReturn.class), + GETSTATIC(0xb2, "getstatic", GetStatic.class), + PUTSTATIC(0xb3, "putstatic", PutStatic.class), + GETFIELD(0xb4, "getfield", GetField.class), + PUTFIELD(0xb5, "putfield", PutField.class), + INVOKEVIRTUAL(0xb6, "invokevirtual", InvokeVirtual.class), + INVOKESPECIAL(0xb7, "invokespecial", InvokeSpecial.class), + INVOKESTATIC(0xb8, "invokestatic", InvokeStatic.class), + INVOKEINTERFACE(0xb9, "invokeinterface", InvokeInterface.class), + INVOKEDYNAMIC(0xba, "invokedynamic", InvokeDynamic.class), + NEW(0xbb, "new", New.class), + NEWARRAY(0xbc, "newarray", NewArray.class), + ANEWARRAY(0xbd, "anewarray", ANewArray.class), + ARRAYLENGTH(0xbe, "arraylength", ArrayLength.class), + ATHROW(0xbf, "athrow", AThrow.class), + CHECKCAST(0xc0, "checkcast", CheckCast.class), + INSTANCEOf(0xc1, "instanceof", InstanceOf.class), + MONITORENTER(0xc2, "monitorenter", MonitorEnter.class), + MONITOREXIT(0xc3, "monitorexit", MonitorExit.class), + MULTIANEWARRAY(0xc5, "multianewarray", MultiANewArray.class), + IFNULL(0xc6, "ifnull", IfNull.class), + IFNONNULL(0xc7, "ifnonnull", IfNonNull.class), + GOTO_W(0xc8, "goto_w", GotoW.class); + + private final int code; + private final String name; + private final Class clazz; + + InstructionType(int op, String name, Class clazz) + { + this.code = op; + this.name = name; + this.clazz = clazz; + } + + public int getCode() + { + return code; + } + + public String getName() + { + return name; + } + + public Class getInstructionClass() + { + return clazz; + } + + public static InstructionType findInstructionFromCode(int code) + { + for (InstructionType t : InstructionType.values()) + { + if (t.getCode() == code) + { + return t; + } + } + return null; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instructions.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instructions.java new file mode 100644 index 0000000000..a528950d0a --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Instructions.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.runelite.asm.attributes.Code; + +public class Instructions +{ + private final Code code; + private final List instructions = new ArrayList<>(); + private final Map labelMap = new HashMap<>(); + + public Instructions(Code code) + { + this.code = code; + } + + public Label createLabelFor(Instruction target) + { + return createLabelFor(target, false); + } + + public Label createLabelFor(Instruction target, boolean forceCreate) + { + assert target.getInstructions() == this; + assert instructions.contains(target); + + if (target instanceof Label) + { + return (Label) target; + } + + int i = instructions.indexOf(target); + if (i > 0) + { + Instruction before = instructions.get(i - 1); + + if (!forceCreate && before instanceof Label) + { + return (Label) before; + } + } + + Label label = new Label(this); + label.setLabel(new org.objectweb.asm.Label()); + instructions.add(i, label); + labelMap.put(label.getLabel(), label); + return label; + } + + public Label findLabel(org.objectweb.asm.Label l) + { + Label label = labelMap.get(l); + assert label != null; + return label; + } + + public Label findOrCreateLabel(org.objectweb.asm.Label l) + { + Label label = labelMap.get(l); + if (label != null) + { + return label; + } + + label = new Label(this, l); + labelMap.put(l, label); + + return label; + } + + public void rebuildLabels() + { + labelMap.clear(); + + // ow2 asm requires new Labels each time you write out a class + // with ClassWriter, or else it crytpically fails + for (Instruction i : instructions) + { + if (i instanceof Label) + { + org.objectweb.asm.Label label = new org.objectweb.asm.Label(); + ((Label) i).setLabel(label); + + labelMap.put(label, (Label) i); + } + } + } + + public List getInstructions() + { + return instructions; + } + + public void addInstruction(Instruction i) + { + assert i.getInstructions() == this; + instructions.add(i); + } + + public void addInstruction(int idx, Instruction i) + { + assert i.getInstructions() == this; + instructions.add(idx, i); + } + + public void remove(Instruction ins) + { + assert ins.getInstructions() == this; + ins.remove(); + instructions.remove(ins); + ins.setInstructions(null); + } + + public void clear() + { + for (Instruction ins : instructions) + { + ins.remove(); + ins.setInstructions(null); + } + instructions.clear(); + } + + public Code getCode() + { + return code; + } + + public void lookup() + { + for (Instruction i : instructions) + { + i.lookup(); + } + } + + public void regeneratePool() + { + for (Instruction i : instructions) + { + i.regeneratePool(); + } + } + + public int replace(Instruction oldi, Instruction newi) + { + assert oldi != newi; + + assert oldi.getInstructions() == this; + assert newi.getInstructions() == this; + + assert instructions.contains(oldi); + assert !instructions.contains(newi); + + int i = instructions.indexOf(oldi); + instructions.remove(oldi); + oldi.setInstructions(null); + instructions.add(i, newi); + + return i; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Label.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Label.java new file mode 100644 index 0000000000..7f2cd70ffd --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Label.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code; + +import net.runelite.asm.attributes.code.instructions.NOP; +import org.objectweb.asm.MethodVisitor; + +public class Label extends NOP +{ + private org.objectweb.asm.Label label; + private Integer lineNumber; + + public Label(Instructions instructions) + { + super(instructions); + } + + public Label(Instructions instructions, org.objectweb.asm.Label label) + { + super(instructions); + this.label = label; + } + + @Override + public String toString() + { + String string; + + if (this.getInstructions() == null) + { + string = "label "; + } + else + { + Instruction next = next(); + + if (next == null) + { + string = "label with no next instruction"; + } + else + { + string = "label " + next.toString(); + } + } + + if (lineNumber != null) + { + string += " on line number " + lineNumber; + } + + return string; + } + + @Override + public Instruction clone() + { + Label l = (Label) super.clone(); + l.label = new org.objectweb.asm.Label(); + l.lineNumber = lineNumber; + return l; + } + + @Override + public void accept(MethodVisitor visitor) + { + visitor.visitLabel(label); + + if (lineNumber != null) + { + visitor.visitLineNumber(lineNumber, label); + } + } + + public org.objectweb.asm.Label getLabel() + { + return label; + } + + public void setLabel(org.objectweb.asm.Label label) + { + this.label = label; + } + + public void setLineNumber(Integer lineNumber) + { + this.lineNumber = lineNumber; + } + + public Instruction next() + { + Instructions ins = this.getInstructions(); + int i = ins.getInstructions().indexOf(this); + assert i != -1; + + Instruction next; + do + { + next = ins.getInstructions().get(i + 1); + ++i; + } + while (next instanceof Label); + + return next; + } +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSItemLayerMixin.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/LocalVariable.java similarity index 61% rename from runelite-mixins/src/main/java/net/runelite/mixins/RSItemLayerMixin.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/LocalVariable.java index 8b67d4d314..3956b453d1 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSItemLayerMixin.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/LocalVariable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, SomeoneWithAnInternetConnection + * Copyright (c) 2018 Morgan Lewis * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,37 +22,56 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.mixins; +package net.runelite.asm.attributes.code; -import java.awt.geom.Area; -import net.runelite.api.mixins.Inject; -import net.runelite.api.mixins.Mixin; -import net.runelite.rs.api.RSItemLayer; +import org.objectweb.asm.Label; -@Mixin(RSItemLayer.class) -public abstract class RSItemLayerMixin implements RSItemLayer +public class LocalVariable { - @Inject - private int itemLayerPlane; + private final String name; + private final String desc; + private final String signature; + private final Label start; + private final Label end; + private final int index; - @Inject - @Override - public int getPlane() + public LocalVariable(String name, String desc, String signature, Label start, Label end, int index) { - return itemLayerPlane; + this.name = name; + this.desc = desc; + this.signature = signature; + this.start = start; + this.end = end; + this.index = index; } - @Inject - @Override - public void setPlane(int plane) + public String getName() { - this.itemLayerPlane = plane; + return name; } - @Inject - @Override - public Area getClickbox() + public String getDesc() { - throw new UnsupportedOperationException(); + return desc; + } + + public String getSignature() + { + return signature; + } + + public Label getStart() + { + return start; + } + + public Label getEnd() + { + return end; + } + + public int getIndex() + { + return index; } } diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSIgnoreMixin.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Parameter.java similarity index 71% rename from runelite-mixins/src/main/java/net/runelite/mixins/RSIgnoreMixin.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/Parameter.java index 98bcd7b3b2..b42a41a4b5 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSIgnoreMixin.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/Parameter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Adam + * Copyright (c) 2018 Morgan Lewis * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,28 +22,37 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.mixins; +package net.runelite.asm.attributes.code; -import net.runelite.api.mixins.Inject; -import net.runelite.api.mixins.Mixin; -import net.runelite.rs.api.RSIgnore; -import net.runelite.rs.api.RSName; - -@Mixin(RSIgnore.class) -public abstract class RSIgnoreMixin implements RSIgnore +public class Parameter { - @Override - @Inject + private final String name; + private final int access; + private LocalVariable localVariable; + + public Parameter(String name, int access) + { + this.name = name; + this.access = access; + } + public String getName() { - return getRsName().getName(); + return name; } - @Override - @Inject - public String getPrevName() + public int getAccess() { - RSName prevName = getRsPrevName(); - return prevName == null ? null : prevName.getName(); + return access; + } + + public LocalVariable getLocalVariable() + { + return localVariable; + } + + public void setLocalVariable(LocalVariable localVariable) + { + this.localVariable = localVariable; } } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/AdditionInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/AdditionInstruction.java new file mode 100644 index 0000000000..0fbb69ab1d --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/AdditionInstruction.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code.instruction.types; + +import net.runelite.asm.Field; +import net.runelite.asm.attributes.code.Instruction; +import net.runelite.asm.execution.InstructionContext; +import net.runelite.asm.execution.StackContext; +import net.runelite.deob.deobfuscators.mapping.MappingExecutorUtil; +import net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping; + +public interface AdditionInstruction extends MappableInstruction +{ + default InstructionContext findArrayLoad(InstructionContext ic1, InstructionContext ic2) + { + Instruction i1 = ic1.getInstruction(); + Instruction i2 = ic2.getInstruction(); + + if (i1 instanceof ArrayLoad && !(i2 instanceof ArrayLoad)) + { + return ic1; + } + if (i2 instanceof ArrayLoad && !(i1 instanceof ArrayLoad)) + { + return ic2; + } + + return null; + } + + @Override + default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) + { + /* lhs/rhs of addition instructions are randomally swapped, but + * we still map if each side is recognizable + * + * N.B. since the lhs/rhs of nested iadds can be swapped, and + * the mapper maps the first that it encounters, this can certainly + * attempt to map the wrong instructions even when mapping the correct + * method, so be careful. + */ + StackContext ctx1 = ctx.getPops().get(0); + StackContext ctx2 = ctx.getPops().get(1); + + StackContext other1 = other.getPops().get(0); + StackContext other2 = other.getPops().get(1); + + InstructionContext rc1 = ctx1.getPushed().resolve(ctx1); + InstructionContext rc2 = ctx2.getPushed().resolve(ctx2); //iaload + + InstructionContext ro1 = other1.getPushed().resolve(other1); + InstructionContext ro2 = other2.getPushed().resolve(other2); //iaload + + // There are a couple static final arrays that are only ever read from 1 or 2 places.. and never written + InstructionContext al1 = findArrayLoad(rc1, rc2); + InstructionContext al2 = findArrayLoad(ro1, ro2); + + if (al1 == null || al2 == null) + { + return; + } + + StackContext array1 = al1.getPops().get(1); + StackContext array2 = al2.getPops().get(1); + + InstructionContext field1 = array1.getPushed().resolve(array1); + InstructionContext field2 = array2.getPushed().resolve(array2); + + if (!(field1.getInstruction() instanceof GetFieldInstruction) || !(field2.getInstruction() instanceof GetFieldInstruction)) + { + return; + } + + GetFieldInstruction gf1 = (GetFieldInstruction) field1.getInstruction(); + GetFieldInstruction gf2 = (GetFieldInstruction) field2.getInstruction(); + + Field f1 = gf1.getMyField(); + Field f2 = gf2.getMyField(); + + if (f1 == null || f2 == null || !MappingExecutorUtil.isMaybeEqual(f1, f2)) + { + return; + } + + mappings.map((Instruction) this, f1, f2); + } + + @Override + default boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + return this.getClass() == otherIc.getInstruction().getClass(); + } + + @Override + default boolean canMap(InstructionContext thisIc) + { + return true; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayLoad.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayLoad.java new file mode 100644 index 0000000000..da196f0056 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayLoad.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code.instruction.types; + +import net.runelite.asm.attributes.code.Instruction; +import net.runelite.asm.execution.InstructionContext; +import net.runelite.asm.execution.StackContext; +import net.runelite.deob.deobfuscators.mapping.MappingExecutorUtil; +import net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping; + +public interface ArrayLoad extends MappableInstruction +{ + @Override + default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) + { + StackContext index1 = ctx.getPops().get(0), + index2 = other.getPops().get(0); + + InstructionContext ctx1 = MappingExecutorUtil.resolve(index1.getPushed(), index1), + ctx2 = MappingExecutorUtil.resolve(index2.getPushed(), index2); + + assert ctx1.getInstruction() instanceof GetFieldInstruction; + assert ctx2.getInstruction() instanceof GetFieldInstruction; + + GetFieldInstruction gf1 = (GetFieldInstruction) ctx1.getInstruction(); + GetFieldInstruction gf2 = (GetFieldInstruction) ctx2.getInstruction(); + mappings.map((Instruction) this, gf1.getMyField(), gf2.getMyField()); + } + + @Override + default boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + if (thisIc.getInstruction().getType() != otherIc.getInstruction().getType()) + { + return false; + } + + StackContext index1 = thisIc.getPops().get(0), + index2 = otherIc.getPops().get(0); + + InstructionContext ctx1 = MappingExecutorUtil.resolve(index1.getPushed(), index1), + ctx2 = MappingExecutorUtil.resolve(index2.getPushed(), index2); + + assert ctx1.getInstruction() instanceof GetFieldInstruction; + assert ctx2.getInstruction() instanceof GetFieldInstruction; + + GetFieldInstruction gf1 = (GetFieldInstruction) ctx1.getInstruction(); + GetFieldInstruction gf2 = (GetFieldInstruction) ctx2.getInstruction(); + + return MappingExecutorUtil.isMaybeEqual(gf1.getMyField(), gf2.getMyField()); + } + + @Override + default boolean canMap(InstructionContext thisIc) + { + // assume that obfuscation can't remove a load with a variable + // index. map field access. + StackContext index = thisIc.getPops().get(0); + InstructionContext ctx = MappingExecutorUtil.resolve(index.getPushed(), index); + return ctx.getInstruction() instanceof GetFieldInstruction; + } +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayStoreInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayStoreInstruction.java new file mode 100644 index 0000000000..de019ce9e0 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ArrayStoreInstruction.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code.instruction.types; + +public interface ArrayStoreInstruction extends MappableInstruction +{ + +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClanMember.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ComparisonInstruction.java similarity index 91% rename from runescape-api/src/main/java/net/runelite/rs/api/RSClanMember.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ComparisonInstruction.java index ba65238fa4..25e0cdf1da 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClanMember.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ComparisonInstruction.java @@ -22,10 +22,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; -import net.runelite.api.ClanMember; +package net.runelite.asm.attributes.code.instruction.types; -public interface RSClanMember extends RSChatPlayer, ClanMember +public interface ComparisonInstruction { + } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ConversionInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ConversionInstruction.java new file mode 100644 index 0000000000..099b281725 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/ConversionInstruction.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code.instruction.types; + +public interface ConversionInstruction +{ + +} diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DivisionInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DivisionInstruction.java new file mode 100644 index 0000000000..f682748a65 --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DivisionInstruction.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code.instruction.types; + +import net.runelite.asm.Field; +import net.runelite.asm.attributes.code.Instruction; +import net.runelite.asm.execution.InstructionContext; +import net.runelite.asm.execution.StackContext; +import net.runelite.deob.deobfuscators.mapping.MappingExecutorUtil; +import net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping; + +public interface DivisionInstruction extends MappableInstruction +{ + @Override + default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) + { + StackContext s1 = ctx.getPops().get(0), + s2 = ctx.getPops().get(1); + + StackContext o1 = other.getPops().get(0), + o2 = other.getPops().get(1); + + InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1); + InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2); + + InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1); + InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2); + + if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction(); + GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction(); + + Field fi1 = f1.getMyField(), fi2 = f2.getMyField(); + + if (fi1 != null && fi2 != null) + mappings.map((Instruction) this, fi1, fi2); + } + + if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction(); + GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction(); + + Field fi1 = f1.getMyField(), fi2 = f2.getMyField(); + + if (fi1 != null && fi2 != null) + mappings.map((Instruction) this, fi1, fi2); + } + } + + @Override + default boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + return this.getClass() == otherIc.getInstruction().getClass(); + } + + @Override + default boolean canMap(InstructionContext thisIc) + { + return true; + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSObjectComposition.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DupInstruction.java similarity index 67% rename from runescape-api/src/main/java/net/runelite/rs/api/RSObjectComposition.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DupInstruction.java index 3df00175f5..93ccb70e45 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSObjectComposition.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/DupInstruction.java @@ -22,38 +22,30 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; -import net.runelite.api.ObjectComposition; -import net.runelite.mapping.Import; +package net.runelite.asm.attributes.code.instruction.types; -public interface RSObjectComposition extends ObjectComposition +import java.util.List; +import net.runelite.asm.execution.InstructionContext; +import net.runelite.asm.execution.StackContext; + +public interface DupInstruction { - @Import("id") - @Override - int getId(); + StackContext getOriginal(StackContext sctx); + + StackContext getOtherBranch(StackContext sctx); - @Import("name") - @Override - String getName(); + /** + * get the duplicated stackcontexts (which is popped from this) + * @param ictx instruction context for this instruction + * @return + */ + List getDuplicated(InstructionContext ictx); - @Import("actions") - @Override - String[] getActions(); - - @Import("mapSceneId") - @Override - int getMapSceneId(); - - @Import("mapIconId") - @Override - int getMapIconId(); - - @Import("impostorIds") - @Override - int[] getImpostorIds(); - - @Import("getImpostor") - @Override - RSObjectComposition getImpostor(); + /** + * get the copied stackcontexts (pushed from this) + * @param ictx + * @return + */ + List getCopies(InstructionContext ictx); } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSCombatInfo1.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/FieldInstruction.java similarity index 86% rename from runescape-api/src/main/java/net/runelite/rs/api/RSCombatInfo1.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/FieldInstruction.java index 7f9519718b..e9ed4999ff 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSCombatInfo1.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/FieldInstruction.java @@ -22,15 +22,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; +package net.runelite.asm.attributes.code.instruction.types; -import net.runelite.mapping.Import; +import net.runelite.asm.pool.Field; -public interface RSCombatInfo1 +public interface FieldInstruction { - @Import("healthRatio") - int getHealthRatio(); + Field getField(); - @Import("health") - int getHealth(); + void setField(Field field); + + net.runelite.asm.Field getMyField(); } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/GetFieldInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/GetFieldInstruction.java new file mode 100644 index 0000000000..f5a5af480a --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/GetFieldInstruction.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.asm.attributes.code.instruction.types; + +public interface GetFieldInstruction extends FieldInstruction +{ +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSDeque.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/IntInstruction.java similarity index 89% rename from runescape-api/src/main/java/net/runelite/rs/api/RSDeque.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/IntInstruction.java index 9a0c2aa303..2bc361ef44 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSDeque.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/IntInstruction.java @@ -22,15 +22,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; -import net.runelite.mapping.Import; +package net.runelite.asm.attributes.code.instruction.types; -public interface RSDeque +public interface IntInstruction { - @Import("current") - RSNode getCurrent(); + int getOperand(); - @Import("head") - RSNode getHead(); + void setOperand(int operand); } diff --git a/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/InvokeInstruction.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/InvokeInstruction.java new file mode 100644 index 0000000000..9396f974de --- /dev/null +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/InvokeInstruction.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.asm.attributes.code.instruction.types; + +import java.util.List; +import net.runelite.asm.Method; + +public interface InvokeInstruction extends MappableInstruction +{ + void removeParameter(int idx); + + net.runelite.asm.pool.Method getMethod(); + + void setMethod(net.runelite.asm.pool.Method method); + + List getMethods(); +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSHashTable.java b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/JumpingInstruction.java similarity index 83% rename from runescape-api/src/main/java/net/runelite/rs/api/RSHashTable.java rename to deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/JumpingInstruction.java index e1462ce1dd..fc1dda4b3a 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSHashTable.java +++ b/deobfuscator/src/main/java/net/runelite/asm/attributes/code/instruction/types/JumpingInstruction.java @@ -22,20 +22,16 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.rs.api; +package net.runelite.asm.attributes.code.instruction.types; -import net.runelite.api.HashTable; -import net.runelite.mapping.Import; +import java.util.List; +import net.runelite.asm.attributes.code.Label; -public interface RSHashTable extends HashTable +public interface JumpingInstruction { - @Import("get") - @Override - RSNode get(long value); + List