use of net.runelite.asm.Method in project runelite by runelite.
the class ParallelMappingExecutorTest method testTableswitch.
@Test
public void testTableswitch() throws IOException {
InputStream in = ParallelMappingExecutorTest.class.getResourceAsStream("tests/TableSwitch.class");
Assert.assertNotNull(in);
ClassGroup group = new ClassGroup();
ClassFile cf = ClassUtil.loadClass(in);
group.addClass(cf);
in = ParallelMappingExecutorTest.class.getResourceAsStream("tests/TableSwitch.class");
Assert.assertNotNull(in);
ClassGroup group2 = new ClassGroup();
ClassFile cf2 = ClassUtil.loadClass(in);
group2.addClass(cf2);
Method m1 = cf.findMethod("method");
Method m2 = cf2.findMethod("method");
ParallelExecutorMapping map = MappingExecutorUtil.map(m1, m2);
Assert.assertEquals(cf2.findField("field2"), map.get(cf.findField("field2")));
}
use of net.runelite.asm.Method in project runelite by runelite.
the class ClassGroupFactory method addVoidMethod.
private static void addVoidMethod(ClassFile cf, String name) {
Method method = new Method(cf, name, new Signature("()V"));
method.setStatic();
cf.addMethod(method);
Code code = new Code(method);
method.setCode(code);
Instructions ins = code.getInstructions();
ins.addInstruction(new VReturn(ins));
}
use of net.runelite.asm.Method in project runelite by runelite.
the class SimpleModArithTest method checkConstants.
private void checkConstants(ClassFile cf) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
Instructions instructions = code.getInstructions();
for (Instruction i : instructions.getInstructions()) {
if (i instanceof LDC) {
LDC ldc = (LDC) i;
Integer value = (Integer) ldc.getConstantAsInt();
assertFalse(isBig(value));
}
}
}
}
use of net.runelite.asm.Method in project runelite by runelite.
the class RenameUniqueTest method checkRenamed.
private void checkRenamed() {
for (ClassFile cf : group.getClasses()) {
Assert.assertTrue(cf.getName().startsWith("class") || cf.getName().equals("client"));
for (Field f : cf.getFields()) {
// synthetic fields arent obfuscated
if (f.isSynthetic())
continue;
Assert.assertTrue(f.getName().startsWith("field"));
}
for (Method m : cf.getMethods()) {
Assert.assertTrue(m.getName().length() > 2);
checkCode(m.getCode());
}
}
}
use of net.runelite.asm.Method in project runelite by runelite.
the class UnreachedCodeTest method testRun.
@Test
public void testRun() throws IOException {
UnreachedCode uc = new UnreachedCode();
uc.run(group);
ClassFile cf = group.getClasses().get(0);
Method method = cf.findMethod("entry");
Assert.assertFalse(method.getCode().getExceptions().getExceptions().isEmpty());
method = cf.findMethod("method1Unused");
Assert.assertNotNull(method);
Assert.assertFalse(method.getCode().getInstructions().getInstructions().stream().filter(i -> !(i instanceof Label)).findAny().isPresent());
Assert.assertTrue(method.getCode().getExceptions().getExceptions().isEmpty());
// Method is now invalid, remove so jar can be saved
cf.removeMethod(method);
// constructor now has no instructions
method = cf.findMethod("<init>");
Assert.assertNotNull(method);
Assert.assertFalse(method.getCode().getInstructions().getInstructions().stream().filter(i -> !(i instanceof Label)).findAny().isPresent());
// remove it too
cf.removeMethod(method);
}
Aggregations