Deob changes for injector and general usability

This commit is contained in:
Lucwousin
2019-10-30 10:30:37 +01:00
parent c84f0d5b10
commit f93984a743
29 changed files with 365 additions and 305 deletions

View File

@@ -0,0 +1,17 @@
package net.runelite.asm;
import java.util.Iterator;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import org.jetbrains.annotations.NotNull;
public interface Annotated extends Iterable<Annotation>
{
Annotations getAnnotations();
@NotNull
default Iterator<Annotation> iterator()
{
return getAnnotations().iterator();
}
}

View File

@@ -31,13 +31,12 @@ import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.pool.Class;
import net.runelite.asm.signature.Signature;
import static net.runelite.deob.DeobAnnotations.*;
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
public class ClassFile implements Annotated, Named
{
private ClassGroup group;
@@ -100,10 +99,9 @@ public class ClassFile
visitor.visit(version, access, name.getName(), null, super_class.getName(), ints);
visitor.visitSource(source, null);
for (Annotation annotation : annotations.getAnnotations())
for (Annotation annotation : annotations)
{
AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
annotation.accept(av);
annotation.accept(visitor.visitAnnotation(annotation.getType().toString(), true));
}
for (Field field : fields)

View File

@@ -27,13 +27,16 @@ package net.runelite.asm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import net.runelite.asm.attributes.Code;
import net.runelite.asm.signature.Signature;
import static net.runelite.deob.DeobAnnotations.*;
import org.jetbrains.annotations.NotNull;
public class ClassGroup
public class ClassGroup implements Iterable<ClassFile>
{
private final List<ClassFile> classes = new ArrayList<>(); // to keep order
private final Map<String, ClassFile> classMap = new HashMap<>();
@@ -156,4 +159,17 @@ public class ClassGroup
return findClass(name);
}
@NotNull
@Override
public Iterator<ClassFile> iterator()
{
return this.classes.iterator();
}
@Override
public void forEach(Consumer<? super ClassFile> action)
{
this.classes.forEach(action);
}
}

View File

@@ -27,15 +27,13 @@ package net.runelite.asm;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.deob.DeobAnnotations;
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 class Field implements Annotated, Named
{
public static final int ACCESS_MODIFIERS = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED;
@@ -53,15 +51,14 @@ public class Field
this.name = name;
this.type = type;
annotations = new Annotations();
this.annotations = new Annotations();
}
public void accept(FieldVisitor visitor)
{
for (Annotation annotation : annotations.getAnnotations())
{
AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
annotation.accept(av);
annotation.accept(visitor.visitAnnotation(annotation.getType().toString(), true));
}
visitor.visitEnd();

View File

@@ -25,12 +25,14 @@
package net.runelite.asm;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import net.runelite.asm.pool.Class;
import net.runelite.deob.DeobAnnotations;
import org.jetbrains.annotations.NotNull;
public class Interfaces
public class Interfaces implements Iterable<Class>
{
private final ClassFile classFile;
@@ -107,4 +109,10 @@ public class Interfaces
return names;
}
@NotNull
public Iterator<Class> iterator()
{
return this.interfaces.iterator();
}
}

View File

@@ -36,7 +36,6 @@ import net.runelite.asm.attributes.code.Parameter;
import net.runelite.asm.attributes.code.instruction.types.LVTInstruction;
import net.runelite.asm.signature.Signature;
import net.runelite.deob.DeobAnnotations;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
@@ -47,7 +46,7 @@ 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 class Method implements Annotated, Named
{
public static final int ACCESS_MODIFIERS = ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED;
@@ -92,8 +91,7 @@ public class Method
for (Annotation annotation : annotations.getAnnotations())
{
AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
annotation.accept(av);
annotation.accept(visitor.visitAnnotation(annotation.getType().toString(), true));
}
if (code != null)

View File

@@ -0,0 +1,6 @@
package net.runelite.asm;
public interface Named
{
String getName();
}

View File

@@ -26,13 +26,16 @@
package net.runelite.asm.attributes;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.SimpleElement;
import org.jetbrains.annotations.NotNull;
public class Annotations
public class Annotations implements Iterable<Annotation>
{
private final List<Annotation> annotations = new ArrayList<>();
@@ -40,7 +43,7 @@ public class Annotations
{
return annotations;
}
public void addAnnotation(Annotation annotation)
{
annotations.add(annotation);
@@ -55,7 +58,7 @@ public class Annotations
{
annotations.clear();
}
public Annotation find(Type type)
{
for (Annotation a : annotations)
@@ -68,18 +71,22 @@ public class Annotations
{
return annotations.size();
}
public Annotation addAnnotation(Type type, String name, Object value)
{
Annotation annotation = new Annotation(this);
annotation.setType(type);
Annotation annotation = new Annotation(type);
addAnnotation(annotation);
Element element = new Element(annotation);
element.setName(name);
element.setValue(value);
Element element = new SimpleElement(name, value);
annotation.addElement(element);
return annotation;
}
@NotNull
@Override
public Iterator<Annotation> iterator()
{
return this.annotations.iterator();
}
}

View File

@@ -41,11 +41,11 @@ public class Code
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);
}
@@ -59,12 +59,12 @@ public class Code
{
return maxStack;
}
public void setMaxStack(int maxStack)
{
this.maxStack = maxStack;
}
private int getMaxLocalsFromSig()
{
Method m = getMethod();
@@ -77,12 +77,11 @@ public class Code
/**
* 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)
@@ -96,19 +95,19 @@ public class Code
}
}
}
int fromSig = getMaxLocalsFromSig();
if (fromSig > max)
max = fromSig;
return max;
}
public Exceptions getExceptions()
{
return exceptions;
}
public Instructions getInstructions()
{
return instructions;

View File

@@ -26,30 +26,26 @@
package net.runelite.asm.attributes.annotation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.Annotations;
import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.AnnotationVisitor;
public class Annotation
public class Annotation extends Element<List<Element>> implements Iterable<Element>
{
private final Annotations annotations;
private Type type;
private final List<Element> elements = new ArrayList<>();
private final Type type;
public Annotation(Annotations annotations)
public Annotation(Type type)
{
this.annotations = annotations;
this.value = new ArrayList<>();
this.type = type;
}
public Annotations getAnnotations()
{
return annotations;
}
public void setType(Type type)
public Annotation(String name, Type type)
{
this.value = new ArrayList<>();
this.name = name;
this.type = type;
}
@@ -60,23 +56,44 @@ public class Annotation
public List<Element> getElements()
{
return elements;
return value;
}
public Element getElement()
{
return elements.get(0);
return value.get(0);
}
public void addElement(Element element)
{
elements.add(element);
value.add(element);
}
@Override
public final void setValue(List<Element> value)
{
throw new UnsupportedOperationException();
}
public void accept(AnnotationVisitor visitor)
{
for (Element element : elements)
visitor.visit(element.getName(), element.getValue());
if (visitor == null)
{
return;
}
for (Element element : this)
{
accept(visitor, element.name, element.value);
}
visitor.visitEnd();
}
@NotNull
@Override
public Iterator<Element> iterator()
{
return this.value.iterator();
}
}

View File

@@ -0,0 +1,42 @@
package net.runelite.asm.attributes.annotation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
public class ArrayElement extends Element<List> implements Iterable<Object>
{
public ArrayElement(String name)
{
this.name = name;
this.value = new ArrayList<>();
}
@SuppressWarnings("unchecked")
public void addValue(Object value)
{
this.value.add(value);
}
@Override
public final void setValue(List value)
{
throw new UnsupportedOperationException();
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public Iterator<Object> iterator()
{
return this.value.iterator();
}
@SuppressWarnings("unchecked")
public Stream<Object> stream()
{
return this.value.stream();
}
}

View File

@@ -25,21 +25,14 @@
package net.runelite.asm.attributes.annotation;
public class Element
{
private final Annotation annotation;
private String name;
private Object value;
public Element(Annotation annotation)
{
this.annotation = annotation;
}
import java.util.List;
import org.objectweb.asm.AnnotationVisitor;
public Annotation getAnnotation()
{
return annotation;
}
public abstract class Element<T>
{
String name = "value";
T value;
public String getName()
{
@@ -51,18 +44,48 @@ public class Element
this.name = name;
}
public Object getValue()
public T getValue()
{
return value;
}
public void setValue(Object value)
public void setValue(T value)
{
this.value = value;
}
public String getString()
{
return value.toString();
}
public static void accept(AnnotationVisitor visitor, final String name, final Object value)
{
if (visitor == null)
{
return;
}
if (value instanceof Annotation)
{
Annotation annotation = (Annotation) value;
annotation.accept(visitor.visitAnnotation(name, annotation.getType().toString()));
}
else if (value instanceof List)
{
AnnotationVisitor arr = visitor.visitArray(name);
List<?> arrayValue = (List<?>) value;
for (Object o : arrayValue)
{
accept(arr, null, o);
}
arr.visitEnd();
}
else
{
visitor.visit(name, value);
}
}
}

View File

@@ -0,0 +1,15 @@
package net.runelite.asm.attributes.annotation;
public class SimpleElement extends Element<Object>
{
public SimpleElement(Object value)
{
this.value = value;
}
public SimpleElement(String name, Object value)
{
this.name = name;
this.value = value;
}
}

View File

@@ -26,11 +26,14 @@ package net.runelite.asm.attributes.code;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import net.runelite.asm.attributes.Code;
import org.jetbrains.annotations.NotNull;
public class Instructions
public class Instructions implements Iterable<Instruction>
{
private final Code code;
private final List<Instruction> instructions = new ArrayList<>();
@@ -186,4 +189,25 @@ public class Instructions
return i;
}
public int size()
{
return this.instructions.size();
}
@NotNull
public Iterator<Instruction> iterator()
{
return this.instructions.iterator();
}
public ListIterator<Instruction> listIterator()
{
return this.instructions.listIterator();
}
public ListIterator<Instruction> listIterator(int i)
{
return this.instructions.listIterator(i);
}
}

View File

@@ -25,44 +25,59 @@
package net.runelite.asm.visitors;
import net.runelite.asm.Method;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.ArrayElement;
import net.runelite.asm.attributes.annotation.SimpleElement;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;
public class MethodAnnotationVisitor extends AnnotationVisitor
public class AnnotationElementVisitor extends AnnotationVisitor
{
private final Method method;
private final Type type;
private final Annotation annotation;
public MethodAnnotationVisitor(Method method, Type type)
AnnotationElementVisitor(Annotation annotation)
{
super(Opcodes.ASM5);
this.method = method;
this.type = type;
annotation = new Annotation(method.getAnnotations());
annotation.setType(type);
this.annotation = annotation;
}
@Override
public void visit(String name, Object value)
{
Element element = new Element(annotation);
element.setName(name);
element.setValue(value);
SimpleElement element = new SimpleElement(name, value);
annotation.addElement(element);
}
@Override
public void visitEnd()
public AnnotationVisitor visitArray(String name)
{
method.getAnnotations().addAnnotation(annotation);
ArrayElement element = new ArrayElement(name);
this.annotation.addElement(element);
return new AnnotationVisitor(Opcodes.ASM5)
{
@Override
public void visit(String name, Object value)
{
element.addValue(value);
}
@Override
public AnnotationVisitor visitAnnotation(String name, String descriptor)
{
Annotation annotation = new Annotation(name, new Type(descriptor));
element.addValue(annotation);
return new AnnotationElementVisitor(annotation);
}
};
}
@Override
public AnnotationVisitor visitAnnotation(String name, String descriptor)
{
Annotation annotation = new Annotation(name, new Type(descriptor));
this.annotation.addElement(annotation);
return new AnnotationElementVisitor(annotation);
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* 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.visitors;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;
public class ClassAnnotationVisitor extends AnnotationVisitor
{
private final ClassFile classFile;
private final Type type;
private final Annotation annotation;
public ClassAnnotationVisitor(ClassFile classFile, Type type)
{
super(Opcodes.ASM5);
this.classFile = classFile;
this.type = type;
annotation = new Annotation(classFile.getAnnotations());
annotation.setType(type);
}
@Override
public void visit(String name, Object value)
{
Element element = new Element(annotation);
element.setName(name);
element.setValue(value);
annotation.addElement(element);
}
@Override
public void visitEnd()
{
classFile.getAnnotations().addAnnotation(annotation);
}
}

View File

@@ -22,12 +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.asm.visitors;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Field;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.FieldVisitor;
@@ -35,25 +35,25 @@ import org.objectweb.asm.Opcodes;
public class ClassFieldVisitor extends FieldVisitor
{
private final ClassFile classFile;
private final Field field;
public ClassFieldVisitor(ClassFile cf, int access, String name, Type desc, Object value)
ClassFieldVisitor(ClassFile cf, int access, String name, Type desc, Object value)
{
super(Opcodes.ASM5);
this.classFile = cf;
this.field = new Field(cf, name, desc);
this.field.setAccessFlags(access);
this.field.setValue(value);
field = new Field(cf, name, desc);
field.setAccessFlags(access);
field.setValue(value);
cf.addField(field);
}
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
{
Type type = new Type(desc);
return new FieldAnnotationVisitor(field, type);
Annotation element = new Annotation(new Type(desc));
this.field.getAnnotations().addAnnotation(element);
return new AnnotationElementVisitor(element);
}
@Override
@@ -61,10 +61,4 @@ public class ClassFieldVisitor extends FieldVisitor
{
System.out.println(attr);
}
@Override
public void visitEnd()
{
classFile.addField(field);
}
}

View File

@@ -27,6 +27,7 @@ package net.runelite.asm.visitors;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.signature.Signature;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
@@ -55,7 +56,7 @@ public class ClassFileVisitor extends ClassVisitor
classFile.setSuperName(superName);
classFile.setVersion(version);
classFile.setAccess(access);
for (String inter : interfaces)
classFile.getInterfaces().addInterface(new net.runelite.asm.pool.Class(inter));
}
@@ -69,8 +70,10 @@ public class ClassFileVisitor extends ClassVisitor
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
{
Type type = new Type(desc);
return new ClassAnnotationVisitor(classFile, type);
Annotation annotation = new Annotation(new Type(desc));
classFile.getAnnotations().addAnnotation(annotation);
return new AnnotationElementVisitor(annotation);
}
@Override

View File

@@ -32,6 +32,7 @@ import net.runelite.asm.ClassFile;
import net.runelite.asm.Method;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.Code;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.code.Exceptions;
import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.InstructionType;
@@ -72,18 +73,14 @@ import static org.objectweb.asm.Opcodes.ICONST_5;
import static org.objectweb.asm.Opcodes.ICONST_M1;
import static org.objectweb.asm.Opcodes.LCONST_0;
import static org.objectweb.asm.Opcodes.LCONST_1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CodeVisitor extends MethodVisitor
{
private static final Logger logger = LoggerFactory.getLogger(CodeVisitor.class);
private final ClassFile classFile;
private final Method method;
private Code code;
public CodeVisitor(ClassFile classFile, int access, String name, Signature signature, String[] sexceptions)
CodeVisitor(ClassFile classFile, int access, String name, Signature signature, String[] sexceptions)
{
super(Opcodes.ASM5);
@@ -111,8 +108,9 @@ public class CodeVisitor extends MethodVisitor
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible)
{
Type type = new Type(desc);
return new MethodAnnotationVisitor(method, type);
Annotation element = new Annotation(new Type(desc));
this.method.getAnnotations().addAnnotation(element);
return new AnnotationElementVisitor(element);
}
@Override
@@ -333,7 +331,7 @@ public class CodeVisitor extends MethodVisitor
if (cst instanceof org.objectweb.asm.Type)
{
org.objectweb.asm.Type t = (org.objectweb.asm.Type) cst;
entry = new net.runelite.asm.pool.Class((String) t.getClassName());
entry = new net.runelite.asm.pool.Class(t.getClassName());
}
LDC ldc = new LDC(code.getInstructions(), entry);

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* 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.visitors;
import net.runelite.asm.Field;
import net.runelite.asm.Type;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;
public class FieldAnnotationVisitor extends AnnotationVisitor
{
private final Field field;
private final Type type;
private final Annotation annotation;
public FieldAnnotationVisitor(Field field, Type type)
{
super(Opcodes.ASM5);
this.field = field;
this.type = type;
annotation = new Annotation(field.getAnnotations());
annotation.setType(type);
}
@Override
public void visit(String name, Object value)
{
Element element = new Element(annotation);
element.setName(name);
element.setValue(value);
annotation.addElement(element);
}
@Override
public void visitEnd()
{
field.getAnnotations().addAnnotation(annotation);
}
}

View File

@@ -95,7 +95,7 @@ public class DeobAnnotations
{
return null;
}
return (Number) an.getElement().getValue();
}

View File

@@ -193,6 +193,7 @@ public class Renamer implements Deobfuscator
}
@Override
@SuppressWarnings("unchecked")
public void run(ClassGroup group)
{
group.buildClassGraph();

View File

@@ -37,6 +37,7 @@ import net.runelite.asm.Method;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.SimpleElement;
import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.InstructionType;
import net.runelite.asm.attributes.code.Instructions;
@@ -113,7 +114,6 @@ public class ConstantParameter implements Deobfuscator
List<StackContext> pops = invokeCtx.getPops();
outer:
// object is popped first, then param 1, 2, 3, etc. double and long take two slots.
for (int lvtOffset = offset, parameterIndex = 0;
parameterIndex < method.getDescriptor().size();
@@ -451,9 +451,7 @@ public class ConstantParameter implements Deobfuscator
}
// Add garbage value
Element element = new Element(obfuscatedSignature);
element.setName("garbageValue");
element.setValue(value.toString());
Element element = new SimpleElement("garbageValue", value.toString());
obfuscatedSignature.addElement(element);
}
}
@@ -464,12 +462,12 @@ public class ConstantParameter implements Deobfuscator
public void run(ClassGroup group)
{
Execution execution = new Execution(group);
execution.addExecutionVisitor(i -> findParameters(i));
execution.addExecutionVisitor(this::findParameters);
execution.populateInitialMethods();
execution.run();
execution = new Execution(group);
execution.addMethodContextVisitor(mc -> findDeadParameters(mc));
execution.addMethodContextVisitor(this::findDeadParameters);
execution.populateInitialMethods();
execution.run();

View File

@@ -32,6 +32,7 @@ import net.runelite.asm.Method;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.SimpleElement;
import net.runelite.deob.DeobAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +40,7 @@ import org.slf4j.LoggerFactory;
public class AnnotationMapper
{
private static final Logger logger = LoggerFactory.getLogger(AnnotationMapper.class);
private final ClassGroup source, target;
private final ParallelExecutorMapping mapping;
@@ -119,20 +120,17 @@ public class AnnotationMapper
if (from.getAnnotations() == null)
return count;
for (Annotation a : from.getAnnotations())
{
if (isCopyable(a))
{
Annotation annotation = new Annotation(to);
annotation.setType(a.getType());
Annotation annotation = new Annotation(a.getType());
to.addAnnotation(annotation);
for (Element e : a.getElements())
{
Element element = new Element(annotation);
element.setName(e.getName());
element.setValue(e.getValue());
Element element = new SimpleElement(e.getName(), e.getValue());
annotation.addElement(element);
}
@@ -155,7 +153,6 @@ public class AnnotationMapper
private boolean isCopyable(Annotation a)
{
return a.getType().equals(DeobAnnotations.EXPORT)
|| a.getType().equals(DeobAnnotations.IMPLEMENTS)
|| a.getType().equals(DeobAnnotations.HOOK);
|| a.getType().equals(DeobAnnotations.IMPLEMENTS);
}
}

View File

@@ -8,6 +8,7 @@ import net.runelite.asm.Method;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.SimpleElement;
import net.runelite.deob.Deob;
import net.runelite.deob.DeobAnnotations;
import org.slf4j.Logger;
@@ -23,6 +24,7 @@ public class AnnotationAdder
private final ClassGroup group;
private final Logger log = LoggerFactory.getLogger(AnnotationAdder.class);
@SuppressWarnings("unchecked")
public void run()
{
int impl = 0;
@@ -50,12 +52,9 @@ public class AnnotationAdder
{
Annotations an = c.getAnnotations();
Annotation implAn = new Annotation(an);
implAn.setType(DeobAnnotations.IMPLEMENTS);
Annotation implAn = new Annotation(DeobAnnotations.IMPLEMENTS);
Element value = new Element(implAn);
value.setValue(c.getClassName());
value.setName("value");
Element value = new SimpleElement(c.getClassName());
implAn.addElement(value);
an.addAnnotation(implAn);
@@ -81,12 +80,9 @@ public class AnnotationAdder
Annotation a = an.find(DeobAnnotations.EXPORT);
if (a == null)
{
a = new Annotation(an);
a.setType(DeobAnnotations.EXPORT);
a = new Annotation(DeobAnnotations.EXPORT);
Element value = new Element(a);
value.setValue(fieldName);
value.setName("value");
Element value = new SimpleElement(fieldName);
a.addElement(value);
an.addAnnotation(a);
@@ -114,12 +110,9 @@ public class AnnotationAdder
Annotation a = an.find(DeobAnnotations.EXPORT);
if (a == null)
{
a = new Annotation(an);
a.setType(DeobAnnotations.EXPORT);
a = new Annotation(DeobAnnotations.EXPORT);
Element value = new Element(a);
value.setValue(methodName);
value.setName("value");
Element value = new SimpleElement(methodName);
a.addElement(value);
an.addAnnotation(a);

View File

@@ -34,6 +34,7 @@ import net.runelite.asm.Type;
import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.attributes.annotation.SimpleElement;
public class AnnotationCopier
{
@@ -97,15 +98,12 @@ public class AnnotationCopier
{
if (!isType(a.getType()))
continue;
Annotation a2 = new Annotation(an2);
a2.setType(a.getType());
Annotation a2 = new Annotation(a.getType());
for (Element element : a.getElements())
{
Element element2 = new Element(a2);
element2.setName(element.getName());
element2.setValue(element.getValue());
Element element2 = new SimpleElement(element.getName(), element.getValue());
a2.addElement(element2);
}

View File

@@ -34,13 +34,9 @@ import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.deob.DeobAnnotations;
import net.runelite.deob.deobfuscators.Renamer;
import net.runelite.deob.util.NameMappings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AnnotationRenamer
{
private static final Logger logger = LoggerFactory.getLogger(AnnotationRenamer.class);
private ClassGroup group;
public AnnotationRenamer(ClassGroup group)

View File

@@ -25,9 +25,11 @@
package net.runelite.deob.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -79,6 +81,41 @@ public class JarUtil
return group;
}
public static ClassFile loadClass(byte[] bytes)
{
ClassReader reader = new ClassReader(bytes);
ClassFileVisitor cv = new ClassFileVisitor();
reader.accept(cv, ClassReader.SKIP_FRAMES);
return cv.getClassFile();
}
public static ClassGroup loadClasses(Collection<File> files) throws IOException
{
final ClassGroup group = new ClassGroup();
for (File file : files)
{
if (!file.getName().endsWith(".class"))
{
continue;
}
try (InputStream is = new FileInputStream(file))
{
ClassReader reader = new ClassReader(is);
ClassFileVisitor cv = new ClassFileVisitor();
reader.accept(cv, ClassReader.SKIP_FRAMES);
group.addClass(cv.getClassFile());
}
}
group.initialize();
return group;
}
public static void saveJar(ClassGroup group, File jarfile) throws IOException
{
try (JarOutputStream jout = new JarOutputStream(new FileOutputStream(jarfile), new Manifest()))

View File

@@ -276,8 +276,7 @@ public class HookImporter
{
for (Element e : a.getElements())
{
String str = (String) e.getValue();
return str;
return (String) e.getValue();
}
}
}
@@ -288,7 +287,7 @@ public class HookImporter
private Signature getObfuscatedMethodSignature(Method method)
{
String sig = getAnnotation(method.getAnnotations(), OBFUSCATED_SIGNATURE);
if (sig.isEmpty() == false)
if (!sig.isEmpty())
{
return toObSignature(new Signature(sig)); // if it is annoted, use that
}