use of net.runelite.asm.ClassFile in project runelite by runelite.
the class MixinInjector method injectFields.
/**
* Finds fields that are marked @Inject and inject them into the target
*
* @param mixinClasses
* @throws InjectionException
*/
private void injectFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
// Inject fields, and put them in injectedFields if they can be used by other mixins
for (Class<?> mixinClass : mixinClasses.keySet()) {
ClassFile mixinCf;
try {
mixinCf = loadClass(mixinClass);
} catch (IOException ex) {
throw new InjectionException(ex);
}
List<ClassFile> targetCfs = mixinClasses.get(mixinClass);
for (ClassFile cf : targetCfs) {
for (Field field : mixinCf.getFields()) {
// Always inject $assertionsEnabled if its missing.
if (ASSERTION_FIELD.equals(field.getName())) {
if (cf.findField(ASSERTION_FIELD, Type.BOOLEAN) != null) {
continue;
}
} else {
Annotation inject = field.getAnnotations().find(INJECT);
if (inject == null) {
continue;
}
}
Field copy = new Field(cf, field.getName(), field.getType());
copy.setAccessFlags(field.getAccessFlags());
copy.setPublic();
copy.setValue(field.getValue());
cf.addField(copy);
if (injectedFields.containsKey(field.getName())) {
throw new InjectionException("Injected field names must be globally unique");
}
injectedFields.put(field.getName(), copy);
}
}
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class MixinInjector method inject.
public void inject(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
injectFields(mixinClasses);
findShadowFields(mixinClasses);
for (Class<?> mixinClass : mixinClasses.keySet()) {
try {
for (ClassFile cf : mixinClasses.get(mixinClass)) {
// Make a new mixin ClassFile copy every time,
// so they don't share Code references
ClassFile mixinCf = loadClass(mixinClass);
injectMethods(mixinCf, cf, shadowFields);
}
} catch (IOException ex) {
throw new InjectionException(ex);
}
}
injectFieldHooks(mixinClasses);
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class ScriptVM method findDeobField.
private Field findDeobField(String name) throws InjectionException {
for (ClassFile c : inject.getDeobfuscated().getClasses()) {
for (Field f : c.getFields()) {
if (!f.getName().equals(name)) {
continue;
}
String obfuscatedName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
ClassFile c2 = inject.toObClass(c);
return c2.findField(obfuscatedName);
}
}
throw new InjectionException(String.format("Mapped field \"%s\" could not be found.", name));
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class DrawAfterWidgetsTest method testInjectDrawWidgetsRev160.
@Test
public void testInjectDrawWidgetsRev160() throws Exception {
// Rev 160 does not have the drawWidgets call inlined
ClassFile deobClient = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Client_deob160.class"));
ClassFile deobRasterizer = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Rasterizer2D_deob160.class"));
ClassGroup deob = new ClassGroup();
deob.addClass(deobClient);
deob.addClass(deobRasterizer);
ClassFile obClient = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Client_ob160.class"));
ClassFile obRasterizer = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Rasterizer2D_ob160.class"));
ClassGroup vanilla = new ClassGroup();
vanilla.addClass(obClient);
vanilla.addClass(obRasterizer);
Inject inject = new Inject(deob, vanilla);
new DrawAfterWidgets(inject).inject();
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class DrawAfterWidgetsTest method testInjectDrawWidgetsRev153.
@Test
public void testInjectDrawWidgetsRev153() throws Exception {
// Rev 153 has the drawWidgets call inlined
ClassFile deobClient = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Client_deob153.class"));
ClassFile deobRasterizer = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Rasterizer2D_deob153.class"));
ClassGroup deob = new ClassGroup();
deob.addClass(deobClient);
deob.addClass(deobRasterizer);
ClassFile obClient = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Client_ob153.class"));
ClassFile obRasterizer = ClassUtil.loadClass(getClass().getResourceAsStream("/drawafterwidgets/Rasterizer2D_ob153.class"));
ClassGroup vanilla = new ClassGroup();
vanilla.addClass(obClient);
vanilla.addClass(obRasterizer);
Inject inject = new Inject(deob, vanilla);
new DrawAfterWidgets(inject).inject();
}
Aggregations