use of net.runelite.asm.ClassFile in project runelite by runelite.
the class InjectMojo method getClassFile.
private File getClassFile(File base, ClassFile cf) {
File f = base;
String[] parts = cf.getName().split("/");
for (int i = 0; i < parts.length - 1; ++i) {
String part = parts[i];
f = new File(f, part);
}
f.mkdirs();
f = new File(f, parts[parts.length - 1] + ".class");
return f;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class DrawAfterWidgets method findStaticMethod.
private Method findStaticMethod(String name) {
for (ClassFile c : inject.getDeobfuscated().getClasses()) {
for (Method m : c.getMethods()) {
if (!m.getName().equals(name)) {
continue;
}
String obfuscatedName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
Signature obfuscatedSignature = DeobAnnotations.getObfuscatedSignature(m);
ClassFile c2 = inject.toObClass(c);
return c2.findMethod(obfuscatedName, (obfuscatedSignature != null) ? obfuscatedSignature : m.getDescriptor());
}
}
return null;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class InjectConstruct method inject.
public void inject(Map<ClassFile, java.lang.Class> implemented) throws InjectionException {
for (Entry<ClassFile, java.lang.Class> entry : implemented.entrySet()) {
Class<?> clazz = entry.getValue();
ClassFile cf = entry.getKey();
if (clazz == null) {
continue;
}
for (java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
if (method.isSynthetic()) {
continue;
}
Construct construct = method.getAnnotation(Construct.class);
if (construct == null) {
continue;
}
String obfuscatedName = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
if (obfuscatedName == null) {
obfuscatedName = cf.getName();
}
ClassGroup vanilla = inject.getVanilla();
ClassFile other = vanilla.findClass(obfuscatedName);
assert other != null : "unable to find vanilla class from obfuscated name: " + obfuscatedName;
injectConstruct(other, method);
}
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class InjectInvoker method process.
/**
* Inject an invoker for a method
*
* @param m Method in the deobfuscated client to inject an invoker for
* @param other Class in the vanilla client of the same class m is a
* member of
* @param implementingClass Java class for the API interface the class
* will implement
*/
public void process(Method m, ClassFile other, java.lang.Class<?> implementingClass) {
Annotations an = m.getAnnotations();
if (an == null || an.find(EXPORT) == null) {
// not an exported method
return;
}
String exportedName = DeobAnnotations.getExportedName(an);
String obfuscatedName = DeobAnnotations.getObfuscatedName(an);
if (obfuscatedName == null) {
obfuscatedName = m.getName();
}
String garbage = DeobAnnotations.getObfuscatedValue(m);
Method otherm = other.findMethod(obfuscatedName, inject.getMethodSignature(m));
assert otherm != null;
assert m.isStatic() == otherm.isStatic();
ClassGroup vanilla = inject.getVanilla();
ClassFile targetClass = m.isStatic() ? vanilla.findClass("client") : other;
// Place into implementing class, unless the method is static
java.lang.Class<?> targetClassJava = m.isStatic() ? Inject.CLIENT_CLASS : implementingClass;
if (targetClassJava == null) {
assert !m.isStatic();
// non static exported method on non exported interface, weird.
logger.debug("Non static exported method {} on non exported interface", exportedName);
return;
}
// api method to invoke 'otherm'
java.lang.reflect.Method apiMethod = inject.findImportMethodOnApi(targetClassJava, exportedName, null);
if (apiMethod == null) {
logger.debug("Unable to find api method on {} with imported name {}, not injecting invoker", targetClassJava, exportedName);
return;
}
injectInvoker(targetClass, apiMethod, m, otherm, garbage);
++injectedInvokers;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class MixinInjector method findShadowFields.
/**
* Find fields which are marked @Shadow, and what they shadow
*
* @param mixinClasses
* @throws InjectionException
*/
private void findShadowFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
// Injected static fields take precedence when looking up shadowed fields
for (Class<?> mixinClass : mixinClasses.keySet()) {
ClassFile mixinCf;
try {
mixinCf = loadClass(mixinClass);
} catch (IOException ex) {
throw new InjectionException(ex);
}
for (Field field : mixinCf.getFields()) {
Annotation shadow = field.getAnnotations().find(SHADOW);
if (shadow != null) {
if (!field.isStatic()) {
throw new InjectionException("Can only shadow static fields");
}
// shadow this field
String shadowName = shadow.getElement().getString();
Field injectedField = injectedFields.get(shadowName);
if (injectedField != null) {
// Shadow a field injected by a mixin
shadowFields.put(field.getPoolField(), injectedField);
} else {
// Shadow a field already in the gamepack
Field shadowField = findDeobField(shadowName);
if (shadowField == null) {
throw new InjectionException("Shadow of nonexistent field " + shadowName);
}
Field obShadow = inject.toObField(shadowField);
assert obShadow != null;
shadowFields.put(field.getPoolField(), obShadow);
}
}
}
}
}
Aggregations