use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class Renamer method run.
@Override
public void run(ClassGroup group) {
group.buildClassGraph();
group.lookup();
int classes = 0, fields = 0, methods = 0;
// rename fields
for (ClassFile cf : group.getClasses()) {
for (Field field : cf.getFields()) {
String newName = mappings.get(field.getPoolField());
if (newName == null) {
continue;
}
if (field.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
field.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", field.getName());
}
field.setName(newName);
++fields;
}
}
// rename methods
for (ClassFile cf : group.getClasses()) {
for (Method method : cf.getMethods()) {
String newName = mappings.get(method.getPoolMethod());
// rename on obfuscated signature
Annotation an = method.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE);
if (an != null) {
Signature obfuscatedSig = new Signature(an.getElement().getString());
Signature updatedSig = renameSignature(obfuscatedSig);
an.getElement().setValue(updatedSig.toString());
}
if (newName == null) {
continue;
}
List<Method> virtualMethods = VirtualMethods.getVirtualMethods(method);
assert !virtualMethods.isEmpty();
for (Method m : virtualMethods) {
if (m.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
m.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", m.getName());
}
m.setName(newName);
}
methods += virtualMethods.size();
}
}
for (ClassFile cf : group.getClasses()) {
String newName = mappings.get(cf.getPoolClass());
if (newName == null) {
continue;
}
renameClass(group, cf, newName);
++classes;
}
this.regeneratePool(group);
logger.info("Renamed {} classes, {} fields, and {} methods", classes, fields, methods);
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class CodeVisitor method visitMethodInsn.
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
InvokeInstruction ii = (InvokeInstruction) createInstructionFromOpcode(opcode);
assert ii instanceof InvokeInterface == itf;
Type type = new Type(owner);
net.runelite.asm.pool.Method entry = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(type.getInternalName()), name, new Signature(desc));
ii.setMethod(entry);
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class EnumDeobfuscator method makeEnum.
private void makeEnum(ClassFile cf) {
// make class an enum
cf.setEnum();
// enums super class is java/lang/Enum
assert cf.getParentClass().getName().equals("java/lang/Object");
cf.setSuperName("java/lang/Enum");
// all static fields of the type of the class become enum members
for (Field field : cf.getFields()) {
if (field.isStatic() && field.getType().equals(new Type("L" + cf.getName() + ";"))) {
field.setEnum();
}
}
for (Method method : cf.getMethods()) {
if (!method.getName().equals("<init>")) {
continue;
}
// Add string as first argument, which is the field name,
// and ordinal as second argument
Signature signature = new Signature.Builder().setReturnType(method.getDescriptor().getReturnValue()).addArgument(Type.STRING).addArgument(Type.INT).addArguments(method.getDescriptor().getArguments()).build();
method.setDescriptor(signature);
// Remove instructions up to invokespecial
Instructions ins = method.getCode().getInstructions();
Instruction i;
do {
i = ins.getInstructions().get(0);
ins.remove(i);
} while (i.getType() != InstructionType.INVOKESPECIAL);
// load this
ins.addInstruction(0, new ALoad(ins, 0));
// load constant name
ins.addInstruction(1, new ALoad(ins, 1));
// ordinal
ins.addInstruction(2, new ILoad(ins, 2));
// invoke enum constructor
ins.addInstruction(3, new InvokeSpecial(ins, ENUM_INIT));
// Shift all indexes after this up +2 because of the new String and int argument
for (int j = 4; j < ins.getInstructions().size(); ++j) {
i = ins.getInstructions().get(j);
if (i instanceof LVTInstruction) {
LVTInstruction lvt = ((LVTInstruction) i);
int idx = lvt.getVariableIndex();
if (idx != 0) {
lvt.setVariableIndex(idx + 2);
}
}
}
}
// Order of fields being set in clinit, which is the order
// the enum fields are actually in
List<Field> order = new ArrayList<>();
for (Method method : cf.getMethods()) {
if (!method.getName().equals("<clinit>")) {
continue;
}
Instructions ins = method.getCode().getInstructions();
int count = 0;
// sometimes there is new new invokespecial invokespecial putfield
// for eg enum member field30(1, 2, String.class, new class5());
boolean seenDup = false;
for (int j = 0; j < ins.getInstructions().size(); ++j) {
Instruction i = ins.getInstructions().get(j);
if (i.getType() == InstructionType.DUP && !seenDup) {
// XXX this should actually be the field name, but it seems to have no effect on fernflower
ins.addInstruction(j + 1, new LDC(ins, "runelite"));
ins.addInstruction(j + 2, new LDC(ins, count++));
seenDup = true;
} else if (i.getType() == InstructionType.INVOKESPECIAL) {
Instruction next = ins.getInstructions().get(j + 1);
// check if this is the invokespecial on the enum, putstatic comes next
if (next.getType() == InstructionType.PUTSTATIC) {
InvokeSpecial is = (InvokeSpecial) i;
PutStatic ps = (PutStatic) next;
net.runelite.asm.pool.Method pmethod = new net.runelite.asm.pool.Method(is.getMethod().getClazz(), is.getMethod().getName(), new Signature.Builder().setReturnType(is.getMethod().getType().getReturnValue()).addArgument(Type.STRING).addArgument(Type.INT).addArguments(is.getMethod().getType().getArguments()).build());
is.setMethod(pmethod);
Field field = ps.getMyField();
assert field != null;
order.add(field);
seenDup = false;
}
}
}
}
// Enum fields must be first. Also they are in order in clinit.
// Sort fields
Collections.sort(cf.getFields(), (f1, f2) -> {
int idx1 = order.indexOf(f1);
int idx2 = order.indexOf(f2);
if (idx1 == -1) {
idx1 = Integer.MAX_VALUE;
}
if (idx2 == -1) {
idx2 = Integer.MAX_VALUE;
}
return Integer.compare(idx1, idx2);
});
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class Frame method initialize.
public void initialize() {
// initialize LVT
int pos = 0;
if (!method.isStatic()) {
variables.set(pos++, new VariableContext(Type.getType(method.getClassFile().getPoolClass())).markParameter());
}
Signature descriptor = method.getDescriptor();
for (int i = 0; i < descriptor.size(); ++i) {
Type argumentType = descriptor.getTypeOfArg(i);
variables.set(pos, new VariableContext(argumentType).markParameter());
pos += argumentType.getSize();
}
Code code = method.getCode();
cur = code.getInstructions().getInstructions().get(0);
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class MappingDumper method dumpJson.
@Test
public void dumpJson() throws IOException {
ClassGroup group = JarUtil.loadJar(new File(properties.getRsClient()));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonObject jObject = new JsonObject();
JsonArray jFields = new JsonArray();
JsonArray jMethods = new JsonArray();
for (ClassFile cf : group.getClasses()) {
String implName = DeobAnnotations.getImplements(cf);
String className = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
for (Field f : cf.getFields()) {
String exportName = DeobAnnotations.getExportedName(f.getAnnotations());
if (exportName == null) {
continue;
}
String fieldName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
Type obfType = DeobAnnotations.getObfuscatedType(f);
Number getter = DeobAnnotations.getObfuscatedGetter(f);
JsonObject jField = new JsonObject();
jField.addProperty("name", exportName);
jField.addProperty("owner", f.isStatic() ? "" : implName);
jField.addProperty("class", className);
jField.addProperty("field", fieldName);
jField.addProperty("obfSignature", (obfType != null ? obfType.toString() : ""));
jField.addProperty("signature", f.getType().toString());
jField.addProperty("multiplier", (getter != null ? getter : 0));
jField.addProperty("static", f.isStatic());
jFields.add(jField);
}
for (Method m : cf.getMethods()) {
String exportName = DeobAnnotations.getExportedName(m.getAnnotations());
if (exportName == null) {
continue;
}
String methodName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
Signature obfSignature = DeobAnnotations.getObfuscatedSignature(m);
String predicate = DeobAnnotations.getObfuscatedValue(m);
JsonObject jMethod = new JsonObject();
jMethod.addProperty("name", exportName);
jMethod.addProperty("owner", m.isStatic() ? "" : implName);
jMethod.addProperty("class", className);
jMethod.addProperty("field", methodName);
jMethod.addProperty("obfSignature", (obfSignature != null ? obfSignature.toString() : ""));
jMethod.addProperty("signature", m.getDescriptor().toString());
jMethod.addProperty("predicate", (predicate != null ? predicate : ""));
jMethod.addProperty("static", m.isStatic());
jMethods.add(jMethod);
}
}
jObject.addProperty("runelite", "http://github.com/runelite");
jObject.addProperty("run", Instant.now().toString());
jObject.addProperty("gamepack", properties.getRsVersion());
jObject.add("fields", jFields);
jObject.add("methods", jMethods);
System.out.println(gson.toJson(jObject));
}
Aggregations