use of net.runelite.asm.attributes.Annotations in project runelite by runelite.
the class HookImporter method findMethodWithObfuscatedName.
private Method findMethodWithObfuscatedName(ClassFile c, String name, String signature) {
Signature sig = new Signature(signature);
for (Method m : c.getMethods()) {
Annotations an = m.getAnnotations();
if (getAnnotation(an, OBFUSCATED_NAME).equals(name)) {
Signature methodSig = getObfuscatedMethodSignature(m);
if (methodSig.equals(sig)) {
return m;
} else {
methodSig.equals(sig);
getObfuscatedMethodSignature(m);
}
}
}
return null;
}
use of net.runelite.asm.attributes.Annotations 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.attributes.Annotations 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.attributes.Annotations in project runelite by runelite.
the class HookImporter method toObType.
private Type toObType(Type t) {
if (t.isPrimitive()) {
return t;
}
if (!t.getInternalName().startsWith("class") && !t.getInternalName().equals("client")) {
return t;
}
ClassFile cf = group.findClass(t.getInternalName());
assert cf != null;
Annotations an = cf.getAnnotations();
String obfuscatedName = an.find(OBFUSCATED_NAME).getElement().getString();
return Type.getType("L" + obfuscatedName + ";", t.getDimensions());
}
use of net.runelite.asm.attributes.Annotations in project runelite by runelite.
the class ConstantParameter method annotateObfuscatedSignature.
private void annotateObfuscatedSignature(ConstantMethodParameter parameter) {
for (Method m : parameter.methods) {
Object value = parameter.values.get(0);
Annotations annotations = m.getAnnotations();
Annotation obfuscatedSignature = annotations.find(DeobAnnotations.OBFUSCATED_SIGNATURE);
if (obfuscatedSignature != null && obfuscatedSignature.getElements().size() == 2) {
// already annotated
continue;
}
if (obfuscatedSignature == null) {
obfuscatedSignature = annotations.addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", m.getDescriptor().toString());
}
// Add garbage value
Element element = new Element(obfuscatedSignature);
element.setName("garbageValue");
element.setValue(value.toString());
obfuscatedSignature.addElement(element);
}
}
Aggregations