use of net.runelite.asm.Field in project runelite by runelite.
the class HookImporter method importHooks.
@Test
@Ignore
public void importHooks() {
int classes = 0, fields = 0, methods = 0, callbacks = 0;
for (String deobfuscatedClassName : hooks.keySet()) {
ClassHook ch = hooks.get(deobfuscatedClassName);
ClassFile cf = this.findClassWithObfuscatedName(ch.getClazz());
assert cf != null;
String implementsName = getAnnotation(cf.getAnnotations(), IMPLEMENTS);
if (implementsName.isEmpty()) {
cf.getAnnotations().addAnnotation(IMPLEMENTS, "value", deobfuscatedClassName);
++classes;
}
for (String deobfuscatedFieldName : ch.getFields().keySet()) {
FieldHook fh = ch.getFields().get(deobfuscatedFieldName);
String[] s = fh.getField().split("\\.");
Field f;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
f = this.findFieldWithObfuscatedName(cf2, s[1]);
} else if (s.length == 1) {
f = this.findFieldWithObfuscatedName(cf, fh.getField());
} else {
throw new RuntimeException();
}
assert f != null;
String exportedName = getAnnotation(f.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
f.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedFieldName);
++fields;
}
}
for (String deobfuscatedMethodName : ch.getMethods().keySet()) {
MethodHook mh = ch.getMethods().get(deobfuscatedMethodName);
String[] s = mh.getMethod().split("\\.");
Method m;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
m = this.findMethodWithObfuscatedName(cf2, s[1], mh.getClientDesc());
} else if (s.length == 1) {
m = this.findMethodWithObfuscatedName(cf, mh.getMethod(), mh.getClientDesc());
} else {
throw new RuntimeException();
}
assert m != null;
String exportedName = getAnnotation(m.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
++methods;
}
}
for (String deobfuscatedMethodName : ch.getCallbacks().keySet()) {
MethodHook mh = ch.getCallbacks().get(deobfuscatedMethodName);
String[] s = mh.getMethod().split("\\.");
Method m;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
m = this.findMethodWithObfuscatedName(cf2, s[1], mh.getClientDesc());
} else if (s.length == 1) {
m = this.findMethodWithObfuscatedName(cf, mh.getMethod(), mh.getClientDesc());
} else {
throw new RuntimeException();
}
assert m != null;
String exportedName = getAnnotation(m.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
++callbacks;
}
}
}
System.out.println("Imported " + classes + " classes, " + fields + " fields, " + methods + " methods, " + callbacks + " callbacks");
}
use of net.runelite.asm.Field in project runelite by runelite.
the class MappingImporter method makeMappings.
@Test
@Ignore
public void makeMappings() throws IOException {
InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(RL_INJECTION));
int fields = 0, classes = 0;
for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
ClassFile cf = this.findClassWithObfuscatedName(gii.getGetterClassName());
Assert.assertNotNull(cf);
Field f = this.findFieldWithObfuscatedName(cf, gii.getGetterFieldName());
if (f == null) {
// so they don't all exist
continue;
}
String attrName = gii.getGetterName();
attrName = Utils.toExportedName(attrName);
Annotations an = f.getAnnotations();
Annotation a = an.find(EXPORT);
if (a != null) {
String exportedName = a.getElement().getString();
if (!attrName.equals(exportedName)) {
logger.info("Exported field " + f + " with mismatched name. Theirs: " + attrName + ", mine: " + exportedName);
}
} else {
an.addAnnotation(EXPORT, "value", attrName);
logger.info("Exporting field " + f + " with name " + attrName);
++fields;
}
}
for (AddInterfaceInstruction aii : mod.getAddInterfaceInjects()) {
ClassFile cf = this.findClassWithObfuscatedName(aii.getClientClass());
Assert.assertNotNull(cf);
String iface = aii.getInterfaceClass();
iface = iface.replace("com/runeloader/api/bridge/os/accessor/", "");
Annotations an = cf.getAnnotations();
Annotation a = an.find(IMPLEMENTS);
if (a != null) {
String implementsName = a.getElement().getString();
if (!iface.equals(implementsName)) {
logger.info("Implements class " + cf + " with mismatched name. Theirs: " + iface + ", mine: " + implementsName);
}
} else {
an.addAnnotation(IMPLEMENTS, "value", iface);
logger.info("Exporting class " + cf.getName() + " with name " + iface);
++classes;
}
}
logger.info("Added {} fields, {} classes", fields, classes);
}
use of net.runelite.asm.Field in project runelite by runelite.
the class Inject method toObField.
Field toObField(Field field) {
String obfuscatedClassName = DeobAnnotations.getObfuscatedName(field.getClassFile().getAnnotations());
// obfuscated name of field
String obfuscatedFieldName = DeobAnnotations.getObfuscatedName(field.getAnnotations());
Type type = getFieldType(field);
ClassFile obfuscatedClass = vanilla.findClass(obfuscatedClassName);
assert obfuscatedClass != null;
Field obfuscatedField = obfuscatedClass.findFieldDeep(obfuscatedFieldName, type);
assert obfuscatedField != null;
return obfuscatedField;
}
use of net.runelite.asm.Field in project runelite by runelite.
the class ModArith method insertGetterSetterMuls.
private void insertGetterSetterMuls(Encryption encr) {
// before setfield insert imul * getter
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null) {
continue;
}
Instructions ins = code.getInstructions();
List<Instruction> ilist = ins.getInstructions();
for (int i = 0; i < ilist.size(); ++i) {
Instruction in = ilist.get(i);
if (in instanceof SetFieldInstruction) {
SetFieldInstruction sfi = (SetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// insert imul
if (p.getType() == Integer.class) {
ilist.add(i++, new LDC(ins, (int) p.getter));
ilist.add(i++, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(i++, new LDC(ins, (long) p.getter));
ilist.add(i++, new LMul(ins));
} else {
throw new IllegalStateException();
}
} else if (in instanceof GetFieldInstruction) {
GetFieldInstruction sfi = (GetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// imul
if (p.getType() == Integer.class) {
ilist.add(++i, new LDC(ins, (int) p.setter));
ilist.add(++i, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(++i, new LDC(ins, (long) p.setter));
ilist.add(++i, new LMul(ins));
} else {
throw new IllegalStateException();
}
}
}
}
}
}
use of net.runelite.asm.Field in project runelite by runelite.
the class FieldInliner method inlineUse.
public int inlineUse() {
int count = 0;
for (Field f : fields) {
// replace getfield with constant push
List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
Object value = f.getValue();
for (FieldInstruction fin : fins) {
// remove fin, add push constant
Instruction i = (Instruction) fin;
Instruction pushIns = new LDC(i.getInstructions(), value);
List<Instruction> instructions = i.getInstructions().getInstructions();
int idx = instructions.indexOf(i);
assert idx != -1;
i.getInstructions().remove(i);
instructions.add(idx, pushIns);
++count;
}
f.getClassFile().removeField(f);
}
return count;
}
Aggregations