Search in sources :

Example 11 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class UnusedClassTest method before.

@Before
public void before() throws IOException {
    group = new ClassGroup();
    load("EmptyInterface.class");
    load("ClassA.class");
    ClassFile emptyClass = load("EmptyClass.class");
    emptyClass.removeMethod(emptyClass.findMethod("<init>"));
}
Also used : ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Before(org.junit.Before)

Example 12 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class UnusedClassTest method load.

private ClassFile load(String name) throws IOException {
    InputStream in = UnusedClassTest.class.getResourceAsStream("unusedclass/" + name);
    Assert.assertNotNull(in);
    ClassFile cf = ClassUtil.loadClass(in);
    group.addClass(cf);
    return cf;
}
Also used : ClassFile(net.runelite.asm.ClassFile) InputStream(java.io.InputStream)

Example 13 with ClassFile

use of net.runelite.asm.ClassFile 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 14 with ClassFile

use of net.runelite.asm.ClassFile 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)

Example 15 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class GetStatic method getMyField.

@Override
public net.runelite.asm.Field getMyField() {
    Class clazz = field.getClazz();
    ClassFile cf = this.getInstructions().getCode().getMethod().getClassFile().getGroup().findClass(clazz.getName());
    if (cf == null) {
        return null;
    }
    net.runelite.asm.Field f2 = cf.findFieldDeep(field.getName(), field.getType());
    return f2;
}
Also used : ClassFile(net.runelite.asm.ClassFile) Class(net.runelite.asm.pool.Class)

Aggregations

ClassFile (net.runelite.asm.ClassFile)103 Method (net.runelite.asm.Method)62 Field (net.runelite.asm.Field)39 ClassGroup (net.runelite.asm.ClassGroup)32 Code (net.runelite.asm.attributes.Code)21 Instruction (net.runelite.asm.attributes.code.Instruction)18 Test (org.junit.Test)18 Signature (net.runelite.asm.signature.Signature)17 Type (net.runelite.asm.Type)16 Instructions (net.runelite.asm.attributes.code.Instructions)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)9 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)9 HashMap (java.util.HashMap)8 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)7