Annotations: signature -> descriptor; use linkedhashmap
This commit is contained in:
@@ -25,10 +25,9 @@
|
||||
package net.runelite.asm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import lombok.Getter;
|
||||
import net.runelite.asm.attributes.Annotated;
|
||||
import net.runelite.asm.pool.Class;
|
||||
@@ -55,7 +54,7 @@ public class ClassFile implements Annotated, Named
|
||||
private final List<Field> fields = new ArrayList<>();
|
||||
private final List<Method> methods = new ArrayList<>();
|
||||
@Getter
|
||||
private final Map<Type, Annotation> annotations = new TreeMap<>(Comparator.comparing(Type::toString));
|
||||
private final Map<Type, Annotation> annotations = new LinkedHashMap<>();
|
||||
|
||||
public ClassFile(ClassGroup group)
|
||||
{
|
||||
|
||||
@@ -24,9 +24,8 @@
|
||||
*/
|
||||
package net.runelite.asm;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import lombok.Getter;
|
||||
import net.runelite.asm.attributes.Annotated;
|
||||
import net.runelite.deob.DeobAnnotations;
|
||||
@@ -47,7 +46,7 @@ public class Field implements Annotated, Named
|
||||
private Type type;
|
||||
private Object value; // ConstantValue
|
||||
@Getter
|
||||
private final Map<Type, Annotation> annotations = new TreeMap<>(Comparator.comparing(Type::toString));
|
||||
private final Map<Type, Annotation> annotations = new LinkedHashMap<>();
|
||||
|
||||
public Field(ClassFile classFile, String name, Type type)
|
||||
{
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
package net.runelite.asm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import lombok.Getter;
|
||||
import net.runelite.asm.attributes.Annotated;
|
||||
import net.runelite.asm.attributes.Code;
|
||||
@@ -60,7 +59,7 @@ public class Method implements Annotated, Named
|
||||
private Signature arguments;
|
||||
private final Exceptions exceptions;
|
||||
@Getter
|
||||
private final Map<Type, Annotation> annotations = new TreeMap<>(Comparator.comparing(Type::toString));
|
||||
private final Map<Type, Annotation> annotations = new LinkedHashMap<>();
|
||||
private List<Parameter> parameters;
|
||||
private Code code;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Signature
|
||||
{
|
||||
final int rvStart = str.indexOf(')');
|
||||
if (rvStart == -1)
|
||||
throw new IllegalArgumentException("Signature has no return value!");
|
||||
throw new IllegalArgumentException("Descriptor has no return value!");
|
||||
|
||||
rv = new Type(str.substring(rvStart + 1));
|
||||
arguments = findArgs(str, new ArrayList<>(), str.indexOf('(') + 1, rvStart);
|
||||
|
||||
@@ -79,66 +79,63 @@ public class Deob
|
||||
|
||||
ClassGroup group = JarUtil.loadJar(new File(args[0]));
|
||||
|
||||
if (args.length <= 2 || !args[2].equals("rl"))
|
||||
{
|
||||
// remove except RuntimeException
|
||||
run(group, new RuntimeExceptions());
|
||||
// remove except RuntimeException
|
||||
run(group, new RuntimeExceptions());
|
||||
|
||||
run(group, new ControlFlowDeobfuscator());
|
||||
run(group, new ControlFlowDeobfuscator());
|
||||
|
||||
run(group, new RenameUnique());
|
||||
run(group, new RenameUnique());
|
||||
|
||||
// remove unused methods - this leaves Code with no instructions,
|
||||
// which is not valid, so unused methods is run after
|
||||
run(group, new UnreachedCode());
|
||||
run(group, new UnusedMethods());
|
||||
// remove unused methods - this leaves Code with no instructions,
|
||||
// which is not valid, so unused methods is run after
|
||||
run(group, new UnreachedCode());
|
||||
run(group, new UnusedMethods());
|
||||
|
||||
// remove illegal state exceptions, frees up some parameters
|
||||
run(group, new IllegalStateExceptions());
|
||||
// remove illegal state exceptions, frees up some parameters
|
||||
run(group, new IllegalStateExceptions());
|
||||
|
||||
// remove constant logically dead parameters
|
||||
run(group, new ConstantParameter());
|
||||
// remove constant logically dead parameters
|
||||
run(group, new ConstantParameter());
|
||||
|
||||
// remove unhit blocks
|
||||
run(group, new UnreachedCode());
|
||||
run(group, new UnusedMethods());
|
||||
// remove unhit blocks
|
||||
run(group, new UnreachedCode());
|
||||
run(group, new UnusedMethods());
|
||||
|
||||
// remove unused parameters
|
||||
run(group, new UnusedParameters());
|
||||
// remove unused parameters
|
||||
run(group, new UnusedParameters());
|
||||
|
||||
// remove unused fields
|
||||
run(group, new UnusedFields());
|
||||
// remove unused fields
|
||||
run(group, new UnusedFields());
|
||||
|
||||
run(group, new FieldInliner());
|
||||
run(group, new FieldInliner());
|
||||
|
||||
// order uses class name order for sorting fields/methods,
|
||||
// so run it before removing classes below
|
||||
run(group, new Order());
|
||||
// order uses class name order for sorting fields/methods,
|
||||
// so run it before removing classes below
|
||||
run(group, new Order());
|
||||
|
||||
run(group, new UnusedClass());
|
||||
run(group, new UnusedClass());
|
||||
|
||||
runMath(group);
|
||||
runMath(group);
|
||||
|
||||
run(group, new ExprArgOrder());
|
||||
run(group, new ExprArgOrder());
|
||||
|
||||
run(group, new Lvt());
|
||||
run(group, new Lvt());
|
||||
|
||||
run(group, new CastNull());
|
||||
run(group, new CastNull());
|
||||
|
||||
run(group, new EnumDeobfuscator());
|
||||
run(group, new EnumDeobfuscator());
|
||||
|
||||
new OpcodesTransformer().transform(group);
|
||||
//run(group, new PacketHandlerOrder());
|
||||
//run(group, new PacketWriteDeobfuscator());
|
||||
new OpcodesTransformer().transform(group);
|
||||
//run(group, new PacketHandlerOrder());
|
||||
//run(group, new PacketWriteDeobfuscator());
|
||||
|
||||
run(group, new MenuActionDeobfuscator());
|
||||
run(group, new MenuActionDeobfuscator());
|
||||
|
||||
new GetPathTransformer().transform(group);
|
||||
new ClientErrorTransformer().transform(group);
|
||||
new ReflectionTransformer().transform(group);
|
||||
//new MaxMemoryTransformer().transform(group);
|
||||
//new RuneliteBufferTransformer().transform(group);
|
||||
}
|
||||
new GetPathTransformer().transform(group);
|
||||
new ClientErrorTransformer().transform(group);
|
||||
new ReflectionTransformer().transform(group);
|
||||
//new MaxMemoryTransformer().transform(group);
|
||||
//new RuneliteBufferTransformer().transform(group);
|
||||
|
||||
JarUtil.saveJar(group, new File(args[1]));
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import net.runelite.asm.Named;
|
||||
import net.runelite.asm.Type;
|
||||
import net.runelite.asm.attributes.Annotated;
|
||||
import net.runelite.asm.attributes.Code;
|
||||
import net.runelite.asm.Annotation;
|
||||
import net.runelite.asm.attributes.code.Exceptions;
|
||||
import net.runelite.asm.attributes.code.Instruction;
|
||||
import net.runelite.asm.attributes.code.LocalVariable;
|
||||
@@ -138,12 +137,7 @@ public class Renamer implements Deobfuscator
|
||||
|
||||
if (!method.getDescriptor().equals(newSignature))
|
||||
{
|
||||
//Signature was updated. Annotate it
|
||||
if (method.findAnnotation(OBFUSCATED_SIGNATURE) == null)
|
||||
{
|
||||
//Signature was not previously renamed
|
||||
method.addAnnotation(OBFUSCATED_SIGNATURE, "signature", method.getDescriptor().toString());
|
||||
}
|
||||
method.findAnnotation(OBFUSCATED_SIGNATURE, true).setElement( "descriptor", method.getDescriptor().toString());
|
||||
}
|
||||
|
||||
method.setDescriptor(newSignature);
|
||||
@@ -160,12 +154,7 @@ public class Renamer implements Deobfuscator
|
||||
{
|
||||
if (field.getType().getInternalName().equals(cf.getName()))
|
||||
{
|
||||
if (field.findAnnotation(OBFUSCATED_SIGNATURE) == null)
|
||||
{
|
||||
//Signature was updated. Annotate it
|
||||
field.addAnnotation(OBFUSCATED_SIGNATURE, "signature", field.getType().toString());
|
||||
}
|
||||
|
||||
field.findAnnotation(OBFUSCATED_SIGNATURE, true).setElement("descriptor", field.getType().toString());
|
||||
field.setType(Type.getType("L" + name + ";", field.getType().getDimensions()));
|
||||
}
|
||||
}
|
||||
@@ -206,7 +195,7 @@ public class Renamer implements Deobfuscator
|
||||
|
||||
addObfuscatedName(field);
|
||||
|
||||
assert DeobAnnotations.getExportedName(field) == null || DeobAnnotations.getExportedName(field).equals(newName) : "Tried changing field name to something other than the exported name!";
|
||||
assert DeobAnnotations.getExportedName(field) == null || newName.equals(DeobAnnotations.getExportedName(field)) : "Tried changing field name to something other than the exported name!";
|
||||
|
||||
field.setName(newName);
|
||||
++fields;
|
||||
@@ -221,13 +210,6 @@ public class Renamer implements Deobfuscator
|
||||
String newName = mappings.get(method.getPoolMethod());
|
||||
String[] newParams = mappings.getP(method.getPoolMethod());
|
||||
|
||||
// rename on obfuscated signature
|
||||
Annotation an = method.findAnnotation(OBFUSCATED_SIGNATURE);
|
||||
if (an != null)
|
||||
{
|
||||
an.setElement(renameSignature(new Signature(an.getValueString())).toString());
|
||||
}
|
||||
|
||||
if (newName == null)
|
||||
{
|
||||
continue;
|
||||
@@ -292,38 +274,6 @@ public class Renamer implements Deobfuscator
|
||||
logger.info("Renamed {} classes, {} fields, {} methods, and {} parameters", classes, fields, methods, parameters);
|
||||
}
|
||||
|
||||
private Type renameType(Type t)
|
||||
{
|
||||
if (t.isPrimitive())
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
String className = t.getInternalName();
|
||||
String newName = mappings.get(new net.runelite.asm.pool.Class(className));
|
||||
if (newName == null)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
Type type = Type.getType("L" + newName + ";", t.getDimensions());
|
||||
|
||||
logger.debug("Renamed {} -> {}", t, type);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
private Signature renameSignature(Signature s)
|
||||
{
|
||||
Signature.Builder builder = new Signature.Builder()
|
||||
.setReturnType(renameType(s.getReturnValue()));
|
||||
for (Type t : s.getArguments())
|
||||
{
|
||||
builder.addArgument(renameType(t));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static <T extends Annotated & Named> void addObfuscatedName(T object)
|
||||
{
|
||||
object.findAnnotation(OBFUSCATED_NAME, true).setElement(object.getName());
|
||||
|
||||
@@ -100,7 +100,7 @@ public class UnusedParameters implements Deobfuscator
|
||||
final var a = m.findAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE);
|
||||
if (a == null)
|
||||
return false;
|
||||
final var str = a.get("signature");
|
||||
final var str = a.get("descriptor");
|
||||
|
||||
return parameter + 1 == new Signature((String) str).size();
|
||||
}
|
||||
|
||||
@@ -439,8 +439,12 @@ public class ConstantParameter implements Deobfuscator
|
||||
// already annotated
|
||||
continue;
|
||||
}
|
||||
obfuscatedSignature.setElement("signature", m.getDescriptor().toString());
|
||||
obfuscatedSignature.setElement("garbageValue", value);
|
||||
else if (obfuscatedSignature.size() == 0)
|
||||
{
|
||||
obfuscatedSignature.setElement("descriptor", m.getDescriptor().toString());
|
||||
}
|
||||
|
||||
obfuscatedSignature.setElement("garbageValue", String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ public class MappingDumper
|
||||
jField.addProperty("class", className);
|
||||
jField.addProperty("field", fieldName);
|
||||
jField.addProperty("obfSignature", (obfType != null ? obfType.toString() : ""));
|
||||
jField.addProperty("signature", f.getType().toString());
|
||||
jField.addProperty("descriptor", f.getType().toString());
|
||||
jField.addProperty("multiplier", (getter != null ? getter : 0));
|
||||
jField.addProperty("static", f.isStatic());
|
||||
|
||||
@@ -379,7 +379,7 @@ public class MappingDumper
|
||||
jMethod.addProperty("class", className);
|
||||
jMethod.addProperty("field", methodName);
|
||||
jMethod.addProperty("obfSignature", (obfSignature != null ? obfSignature.toString() : ""));
|
||||
jMethod.addProperty("signature", m.getDescriptor().toString());
|
||||
jMethod.addProperty("descriptor", m.getDescriptor().toString());
|
||||
jMethod.addProperty("predicate", (predicate != null ? predicate : ""));
|
||||
jMethod.addProperty("static", m.isStatic());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user