use of net.runelite.asm.Field in project runelite by runelite.
the class SubtractionInstruction method isSame.
@Override
default boolean isSame(InstructionContext thisIc, InstructionContext otherIc) {
if (this.getClass() != otherIc.getInstruction().getClass()) {
return false;
}
StackContext s1 = thisIc.getPops().get(0), s2 = thisIc.getPops().get(1);
StackContext o1 = otherIc.getPops().get(0), o2 = otherIc.getPops().get(1);
InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1);
InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2);
if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction();
GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction();
Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
if (!MappingExecutorUtil.isMaybeEqual(fi1, fi2)) {
return false;
}
}
if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction();
GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction();
Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
if (!MappingExecutorUtil.isMaybeEqual(fi1, fi2)) {
return false;
}
}
return true;
}
use of net.runelite.asm.Field in project runelite by runelite.
the class DivisionInstruction method map.
@Override
default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) {
StackContext s1 = ctx.getPops().get(0), s2 = ctx.getPops().get(1);
StackContext o1 = other.getPops().get(0), o2 = other.getPops().get(1);
InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1);
InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2);
if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction();
GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction();
Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
if (fi1 != null && fi2 != null)
mappings.map((Instruction) this, fi1, fi2);
}
if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction();
GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction();
Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
if (fi1 != null && fi2 != null)
mappings.map((Instruction) this, fi1, fi2);
}
}
use of net.runelite.asm.Field in project runelite by runelite.
the class MixinInjector method setOwnersToTargetClass.
private void setOwnersToTargetClass(ClassFile mixinCf, ClassFile cf, Method method, Map<net.runelite.asm.pool.Field, Field> shadowFields, Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods) throws InjectionException {
ListIterator<Instruction> iterator = method.getCode().getInstructions().getInstructions().listIterator();
while (iterator.hasNext()) {
Instruction i = iterator.next();
if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
CopiedMethod copiedMethod = copiedMethods.get(ii.getMethod());
if (copiedMethod != null) {
ii.setMethod(copiedMethod.obMethod.getPoolMethod());
// Pass through garbage value if the method has one
if (copiedMethod.hasGarbageValue) {
int garbageIndex = copiedMethod.obMethod.isStatic() ? copiedMethod.obMethod.getDescriptor().size() - 1 : copiedMethod.obMethod.getDescriptor().size();
iterator.previous();
iterator.add(new ILoad(method.getCode().getInstructions(), garbageIndex));
iterator.next();
}
} else if (ii.getMethod().getClazz().getName().equals(mixinCf.getName())) {
ii.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(cf.getName()), ii.getMethod().getName(), ii.getMethod().getType()));
}
} else if (i instanceof FieldInstruction) {
FieldInstruction fi = (FieldInstruction) i;
Field shadowed = shadowFields.get(fi.getField());
if (shadowed != null) {
fi.setField(shadowed.getPoolField());
} else if (fi.getField().getClazz().getName().equals(mixinCf.getName())) {
fi.setField(new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(cf.getName()), fi.getField().getName(), fi.getField().getType()));
}
} else if (i instanceof PushConstantInstruction) {
PushConstantInstruction pi = (PushConstantInstruction) i;
if (mixinCf.getPoolClass().equals(pi.getConstant())) {
pi.setConstant(cf.getPoolClass());
}
}
verify(mixinCf, i);
}
}
use of net.runelite.asm.Field 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);
}
}
}
}
}
use of net.runelite.asm.Field 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);
}
}
}
}
Aggregations