use of net.runelite.asm.ClassFile 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.ClassFile in project runelite by runelite.
the class Inject method validateTypeIsConvertibleTo.
private boolean validateTypeIsConvertibleTo(Type from, Type to) throws InjectionException {
if (from.getDimensions() != to.getDimensions()) {
throw new InjectionException("Array dimension mismatch");
}
if (from.isPrimitive()) {
return true;
}
ClassFile vanillaClass = vanilla.findClass(from.getInternalName());
if (vanillaClass == null) {
return true;
}
boolean okay = false;
for (Class inter : vanillaClass.getInterfaces().getInterfaces()) {
java.lang.Class c;
try {
c = java.lang.Class.forName(inter.getName().replace('/', '.'));
} catch (ClassNotFoundException ex) {
continue;
}
okay |= check(c, to);
}
return okay;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class InjectHookMethod method process.
public void process(Method method) throws InjectionException {
Annotations an = method.getAnnotations();
if (an == null) {
return;
}
Annotation a = an.find(DeobAnnotations.HOOK);
if (a == null) {
return;
}
// Method is hooked
// String hookName = DeobAnnotations.getHookName(an); // hook name
// Find equivalent method in vanilla, and insert callback at the beginning
ClassFile cf = method.getClassFile();
String obfuscatedMethodName = DeobAnnotations.getObfuscatedName(an), obfuscatedClassName = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
// might be a constructor
if (obfuscatedMethodName == null && method.getName().equals("<init>")) {
obfuscatedMethodName = "<init>";
}
assert obfuscatedClassName != null : "hook on method in class with no obfuscated name";
assert obfuscatedMethodName != null : "hook on method with no obfuscated name";
Signature obfuscatedSignature = inject.getMethodSignature(method);
ClassGroup vanilla = inject.getVanilla();
ClassFile vanillaClass = vanilla.findClass(obfuscatedClassName);
Method vanillaMethod = vanillaClass.findMethod(obfuscatedMethodName, obfuscatedSignature);
// Insert instructions at beginning of method
injectHookMethod(a, method, vanillaMethod);
}
use of net.runelite.asm.ClassFile 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.ClassFile in project runelite by runelite.
the class ControlFlowDeobfuscator method run.
@Override
public void run(ClassGroup group) {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null || !code.getExceptions().getExceptions().isEmpty()) {
continue;
}
split(code);
run(code);
runJumpLabel(code);
}
}
logger.info("Inserted {} jumps, reordered {} blocks, and removed {} jumps. jump delta {}", insertedJump, placedBlocks, removedJumps, insertedJump - removedJumps);
}
Aggregations