Search in sources :

Example 6 with DexClassNode

use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.

the class SmaliTest method test.

@Test
public void test() throws IOException {
    DexFileNode dfn = new DexFileNode();
    try (InputStream is = SmaliTest.class.getResourceAsStream("/a.smali")) {
        Smali.smaliFile("a.smali", is, dfn);
    }
    for (DexClassNode dcn : dfn.clzs) {
        BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
        new BaksmaliDumper(true, true).baksmaliClass(dcn, new BaksmaliDumpOut(w));
        w.flush();
    }
}
Also used : DexClassNode(com.googlecode.d2j.node.DexClassNode) BaksmaliDumper(com.googlecode.d2j.smali.BaksmaliDumper) DexFileNode(com.googlecode.d2j.node.DexFileNode) BaksmaliDumpOut(com.googlecode.d2j.smali.BaksmaliDumpOut) Test(org.junit.Test)

Example 7 with DexClassNode

use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.

the class SmaliTest method dotest.

private void dotest(File dexFile) throws IOException {
    DexBackedDexFile dex;
    try {
        dex = DexFileFactory.loadDexFile(dexFile, 14, false);
    } catch (DexBackedDexFile.NotADexFile ex) {
        ex.printStackTrace();
        return;
    }
    Map<String, DexClassNode> map = readDex(dexFile);
    for (DexBackedClassDef def : dex.getClasses()) {
        String type = def.getType();
        System.out.println(type);
        DexClassNode dexClassNode = map.get(type);
        Assert.assertNotNull(dexClassNode);
        // original
        String smali = baksmali(def);
        Smali.smaliFile2Node("fake.smali", smali);
        {
            byte[] data = toDex(dexClassNode);
            DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
            // original
            String baksmali3 = baksmali(def2);
            Assert.assertEquals(smali, baksmali3);
        }
        String psmali = pbaksmali(dexClassNode);
        DexClassNode dexClassNode2 = Smali.smaliFile2Node("fake.smali", psmali);
        Assert.assertEquals("cmp smalip", psmali, pbaksmali(dexClassNode2));
        {
            byte[] data = toDex(dexClassNode2);
            DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
            // original
            String baksmali3 = baksmali(def2);
            Assert.assertEquals(smali, baksmali3);
        }
    }
}
Also used : DexClassNode(com.googlecode.d2j.node.DexClassNode) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) Opcodes(org.jf.dexlib2.Opcodes) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef)

Example 8 with DexClassNode

use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.

the class SmaliTest method readDex.

Map<String, DexClassNode> readDex(File path) throws IOException {
    DexFileReader dexFileReader = new DexFileReader(ZipUtil.readDex(path));
    DexFileNode dexFileNode = new DexFileNode();
    dexFileReader.accept(dexFileNode);
    Map<String, DexClassNode> map = new HashMap<>();
    for (DexClassNode c : dexFileNode.clzs) {
        map.put(c.className, c);
    }
    return map;
}
Also used : DexClassNode(com.googlecode.d2j.node.DexClassNode) HashMap(java.util.HashMap) DexFileNode(com.googlecode.d2j.node.DexFileNode) DexFileReader(com.googlecode.d2j.reader.DexFileReader)

Aggregations

DexClassNode (com.googlecode.d2j.node.DexClassNode)8 DexFileNode (com.googlecode.d2j.node.DexFileNode)4 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ClassVisitorFactory (com.googlecode.d2j.dex.ClassVisitorFactory)1 ExDex2Asm (com.googlecode.d2j.dex.ExDex2Asm)1 LambadaNameSafeClassAdapter (com.googlecode.d2j.dex.LambadaNameSafeClassAdapter)1 BaseDexFileReader (com.googlecode.d2j.reader.BaseDexFileReader)1 DexFileReader (com.googlecode.d2j.reader.DexFileReader)1 BaksmaliDumpOut (com.googlecode.d2j.smali.BaksmaliDumpOut)1 BaksmaliDumper (com.googlecode.d2j.smali.BaksmaliDumper)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 FileSystem (java.nio.file.FileSystem)1 HashMap (java.util.HashMap)1 Opcodes (org.jf.dexlib2.Opcodes)1 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1 Test (org.junit.Test)1