use of net.runelite.asm.Method in project runelite by runelite.
the class Mapper method mapMemberMethods.
private void mapMemberMethods(ParallelExecutorMapping mapping) {
for (ClassFile cf : source.getClasses()) {
ClassFile other = (ClassFile) mapping.get(cf);
if (other == null) {
continue;
}
List<Method> methods1 = cf.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
List<Method> methods2 = other.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
for (Method method : methods1) {
if (// already mapped
mapping.get(method) != null) {
continue;
}
List<Method> possible = methods2.stream().filter(m -> MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), method.getDescriptor())).collect(Collectors.toList());
// Run over execution mapper
ExecutionMapper em = new ExecutionMapper(method, possible);
ParallelExecutorMapping map = em.run();
if (map == null) {
continue;
}
map.map(null, map.m1, map.m2);
logger.debug("Mapped {} -> {} based on exiting class mapping and method signatures", map.m1, map.m2);
mapping.merge(map);
}
}
}
use of net.runelite.asm.Method in project runelite by runelite.
the class StaticInitializerIndexer method index.
public void index() {
for (ClassFile cf : group.getClasses()) {
Method method = cf.findMethod("<clinit>");
if (method == null) {
continue;
}
Instructions instructions = method.getCode().getInstructions();
for (Instruction i : instructions.getInstructions()) {
if (i.getType() != InstructionType.PUTSTATIC) {
continue;
}
PutStatic putstatic = (PutStatic) i;
if (!putstatic.getField().getClazz().equals(cf.getPoolClass()) || putstatic.getMyField() == null) {
continue;
}
fields.add(putstatic.getMyField());
}
}
logger.debug("Indexed {} statically initialized fields", fields.size());
}
use of net.runelite.asm.Method in project runelite by runelite.
the class AnnotationTest method testAnnotation.
@Test
public void testAnnotation() throws IOException {
InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/asm/annotations/TestClass.class");
Assert.assertNotNull(in);
ClassGroup group = new ClassGroup();
ClassFile cf = ClassUtil.loadClass(in);
group.addClass(cf);
byte[] out = JarUtil.writeClass(group, cf);
// parse it again
cf = ClassUtil.loadClass(new ByteArrayInputStream(out));
Method method = cf.getMethods().get(1);
Assert.assertEquals("method1", method.getName());
Annotations annotations = method.getAnnotations();
Assert.assertNotNull(annotations);
Optional<Annotation> annotation = annotations.getAnnotations().stream().filter(a -> a.getType().equals(new Type("Lnet/runelite/asm/annotations/MyAnnotation;"))).findFirst();
Assert.assertTrue(annotation.isPresent());
Annotation an = annotation.get();
List<Element> elements = an.getElements();
Assert.assertEquals(1, elements.size());
Element element = elements.get(0);
Assert.assertEquals("value", element.getName());
Assert.assertEquals("method1", element.getValue());
}
use of net.runelite.asm.Method in project runelite by runelite.
the class ParallellMappingExecutorTest method testStaticStep.
@Test
public void testStaticStep() throws Exception {
ClassFile cf1 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
ClassFile cf2 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
ClassGroup group1 = new ClassGroup();
ClassGroup group2 = new ClassGroup();
group1.addClass(cf1);
group2.addClass(cf2);
group1.buildClassGraph();
group1.lookup();
group2.buildClassGraph();
group2.lookup();
Method m1 = cf1.findMethod("entry");
Method m2 = cf2.findMethod("entry");
Method map1 = cf1.findMethod("map"), map2 = cf2.findMethod("map");
Assert.assertNotNull(map1);
Assert.assertNotNull(map2);
ParallelExecutorMapping map = MappingExecutorUtil.map(m1, m2);
Assert.assertEquals(map2, map.get(map1));
}
use of net.runelite.asm.Method in project runelite by runelite.
the class OpcodeReplacer method run.
public void run(ClassGroup group, Collection<PacketWrite> writes) {
int count = 0;
ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
assert runeliteOpcodes != null : "Opcodes class must exist";
for (PacketWrite wp : writes) {
Instructions ins = wp.getInstructions();
Instruction param = wp.getOpcodeIns();
if (!(param instanceof PushConstantInstruction)) {
continue;
}
final String fieldName = "PACKET_CLIENT_" + wp.getOpcode();
net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(RUNELITE_OPCODES), fieldName, Type.INT);
ins.replace(param, new GetStatic(ins, field));
if (runeliteOpcodes.findField(fieldName) == null) {
Field opField = new Field(runeliteOpcodes, fieldName, Type.INT);
// ACC_FINAL causes javac to inline the fields, which prevents
// the mapper from doing field mapping
opField.setAccessFlags(ACC_PUBLIC | ACC_STATIC);
// setting a non-final static field value
// doesn't work with fernflower
opField.setValue(wp.getOpcode());
runeliteOpcodes.addField(opField);
// add initialization
Method clinit = runeliteOpcodes.findMethod("<clinit>");
assert clinit != null;
Instructions instructions = clinit.getCode().getInstructions();
instructions.addInstruction(0, new LDC(instructions, wp.getOpcode()));
instructions.addInstruction(1, new PutStatic(instructions, opField));
}
++count;
}
logger.info("Injected {} packet writes", count);
}
Aggregations