use of net.runelite.asm.ClassFile in project runelite by runelite.
the class ConstructorMapper method toOtherType.
private Type toOtherType(Type type) {
if (type.isPrimitive()) {
return type;
}
ClassFile cf = source.findClass(type.getInternalName());
if (cf == null) {
return type;
}
ClassFile other = (ClassFile) mapping.get(cf);
if (other == null) {
logger.debug("Unable to map other type due to no class mapping for {}", cf);
return null;
}
return new Type("L" + other.getName() + ";");
}
use of net.runelite.asm.ClassFile 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.ClassFile 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.ClassFile 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.ClassFile 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));
}
Aggregations