Search in sources :

Example 11 with Method

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")));
}
Also used : ClassFile(net.runelite.asm.ClassFile) InputStream(java.io.InputStream) ClassGroup(net.runelite.asm.ClassGroup) Method(net.runelite.asm.Method) ParallelExecutorMapping(net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping) Test(org.junit.Test)

Example 12 with Method

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));
}
Also used : Signature(net.runelite.asm.signature.Signature) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 13 with Method

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));
            }
        }
    }
}
Also used : Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 14 with Method

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());
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 15 with Method

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);
}
Also used : IOException(java.io.IOException) TemporyFolderLocation(net.runelite.deob.TemporyFolderLocation) Test(org.junit.Test) ClassGroup(net.runelite.asm.ClassGroup) JarUtil(net.runelite.deob.util.JarUtil) ClassFile(net.runelite.asm.ClassFile) Label(net.runelite.asm.attributes.code.Label) Rule(org.junit.Rule) Method(net.runelite.asm.Method) ClassUtil(net.runelite.asm.ClassUtil) After(org.junit.After) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) ClassFile(net.runelite.asm.ClassFile) Label(net.runelite.asm.attributes.code.Label) Method(net.runelite.asm.Method) Test(org.junit.Test)

Aggregations

Method (net.runelite.asm.Method)90 ClassFile (net.runelite.asm.ClassFile)64 Field (net.runelite.asm.Field)34 Instruction (net.runelite.asm.attributes.code.Instruction)29 Code (net.runelite.asm.attributes.Code)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 Signature (net.runelite.asm.signature.Signature)28 ClassGroup (net.runelite.asm.ClassGroup)20 ArrayList (java.util.ArrayList)18 Type (net.runelite.asm.Type)18 List (java.util.List)13 Test (org.junit.Test)13 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)10 DeobAnnotations (net.runelite.deob.DeobAnnotations)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)8 Label (net.runelite.asm.attributes.code.Label)8