Search in sources :

Example 1 with DexFileNode

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

the class Smali method smaliFile2Node.

public static DexClassNode smaliFile2Node(String name, String buff) throws IOException {
    DexFileNode dfn = new DexFileNode();
    smaliFile(name, buff, dfn);
    return dfn.clzs.size() > 0 ? dfn.clzs.get(0) : null;
}
Also used : DexFileNode(com.googlecode.d2j.node.DexFileNode)

Example 2 with DexFileNode

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

the class Smali method smaliFile2Node.

public static DexClassNode smaliFile2Node(String name, InputStream in) throws IOException {
    DexFileNode dfn = new DexFileNode();
    smaliFile(name, in, dfn);
    return dfn.clzs.size() > 0 ? dfn.clzs.get(0) : null;
}
Also used : DexFileNode(com.googlecode.d2j.node.DexFileNode)

Example 3 with DexFileNode

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

the class SkipDupMethod method test.

@Test
public void test() throws IOException {
    InputStream is = SkipDupMethod.class.getClassLoader().getResourceAsStream("i200.dex");
    Assert.assertNotNull(is);
    DexFileReader reader = new DexFileReader(is);
    DexFileNode dfn1 = new DexFileNode();
    reader.accept(dfn1, DexFileReader.KEEP_ALL_METHODS);
    DexFileNode dfn2 = new DexFileNode();
    reader.accept(dfn2, 0);
    Assert.assertTrue(dfn1.clzs.get(0).methods.size() > dfn2.clzs.get(0).methods.size());
}
Also used : InputStream(java.io.InputStream) DexFileNode(com.googlecode.d2j.node.DexFileNode) DexFileReader(com.googlecode.d2j.reader.DexFileReader) Test(org.junit.Test)

Example 4 with DexFileNode

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

the class Dex2jarMultiThreadCmd method run0.

private void run0(String fileName, final ExecutorService executorService) throws IOException {
    // long baseTS = System.currentTimeMillis();
    String baseName = getBaseName(new File(fileName).toPath());
    Path currentDir = new File(".").toPath();
    Path file = currentDir.resolve(baseName + "-dex2jar.jar");
    final Path errorFile = currentDir.resolve(baseName + "-error.zip");
    System.err.println("dex2jar " + fileName + " -> " + file);
    final BaksmaliBaseDexExceptionHandler exceptionHandler = new BaksmaliBaseDexExceptionHandler();
    BaseDexFileReader reader = MultiDexFileReader.open(Files.readAllBytes(new File(fileName).toPath()));
    DexFileNode fileNode = new DexFileNode();
    try {
        reader.accept(fileNode, DexFileReader.SKIP_DEBUG | DexFileReader.IGNORE_READ_EXCEPTION);
    } catch (Exception ex) {
        exceptionHandler.handleFileException(ex);
        throw ex;
    }
    final FileSystem fs = createZip(file);
    final Path dist = fs.getPath("/");
    ClassVisitorFactory cvf = new ClassVisitorFactory() {

        @Override
        public ClassVisitor create(final String name) {
            return new ClassVisitor(Opcodes.ASM4, new ClassWriter(ClassWriter.COMPUTE_MAXS)) {

                @Override
                public void visitEnd() {
                    super.visitEnd();
                    ClassWriter cw = (ClassWriter) super.cv;
                    byte[] data;
                    try {
                        // FIXME handle 'java.lang.RuntimeException: Method code too large!'
                        data = cw.toByteArray();
                    } catch (Exception ex) {
                        System.err.println(String.format("ASM fail to generate .class file: %s", name));
                        exceptionHandler.handleFileException(ex);
                        return;
                    }
                    try {
                        Path dist1 = dist.resolve(name + ".class");
                        BaseCmd.createParentDirectories(dist1);
                        Files.write(dist1, data);
                    } catch (IOException e) {
                        exceptionHandler.handleFileException(e);
                    }
                }
            };
        }
    };
    new ExDex2Asm(exceptionHandler) {

        @Override
        public void convertDex(DexFileNode fileNode, final ClassVisitorFactory cvf) {
            if (fileNode.clzs != null) {
                final Map<String, Clz> classes = collectClzInfo(fileNode);
                final List<Future<?>> results = new ArrayList<>(fileNode.clzs.size());
                for (final DexClassNode classNode : fileNode.clzs) {
                    results.add(executorService.submit(new Runnable() {

                        @Override
                        public void run() {
                            convertClass(classNode, cvf, classes);
                        }
                    }));
                }
                executorService.submit(new Runnable() {

                    @Override
                    public void run() {
                        for (Future<?> result : results) {
                            try {
                                result.get();
                            } catch (InterruptedException | ExecutionException e) {
                                e.printStackTrace();
                            }
                        }
                        BaksmaliBaseDexExceptionHandler exceptionHandler1 = (BaksmaliBaseDexExceptionHandler) exceptionHandler;
                        if (exceptionHandler1.hasException()) {
                            exceptionHandler1.dump(errorFile, new String[0]);
                        }
                        try {
                            fs.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        }
    }.convertDex(fileNode, cvf);
}
Also used : Path(java.nio.file.Path) ClassVisitor(org.objectweb.asm.ClassVisitor) IOException(java.io.IOException) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter) DexClassNode(com.googlecode.d2j.node.DexClassNode) FileSystem(java.nio.file.FileSystem) DexFileNode(com.googlecode.d2j.node.DexFileNode) ClassVisitorFactory(com.googlecode.d2j.dex.ClassVisitorFactory) BaseDexFileReader(com.googlecode.d2j.reader.BaseDexFileReader) File(java.io.File) ExDex2Asm(com.googlecode.d2j.dex.ExDex2Asm)

Example 5 with DexFileNode

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

the class DexWaveTest method test0.

private void test0(DexWeaver iw, String prefix) throws IOException, RecognitionException {
    DexClassNode before = Smali.smaliFile2Node(prefix + "-before.smali", getClass().getResourceAsStream("/weave/smali/" + prefix + "-before.smali"));
    DexClassNode expectedAfter = Smali.smaliFile2Node(prefix + "-after.smali", getClass().getResourceAsStream("/weave/smali/" + prefix + "-after.smali"));
    DexFileNode dfn = new DexFileNode();
    before.accept(iw.wrap(dfn));
    assertEqual(expectedAfter, dfn.clzs.get(0));
    DexClassNode expectedGen = Smali.smaliFile2Node(prefix + "-gen.j", getClass().getResourceAsStream("/weave/smali/" + prefix + "-gen.smali"));
    dfn.clzs.clear();
    iw.buildInvocationClz(dfn);
    assertEqual(expectedGen, dfn.clzs.get(0));
}
Also used : DexClassNode(com.googlecode.d2j.node.DexClassNode) DexFileNode(com.googlecode.d2j.node.DexFileNode)

Aggregations

DexFileNode (com.googlecode.d2j.node.DexFileNode)9 DexClassNode (com.googlecode.d2j.node.DexClassNode)4 DexFileReader (com.googlecode.d2j.reader.DexFileReader)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 ClassVisitorFactory (com.googlecode.d2j.dex.ClassVisitorFactory)2 Test (org.junit.Test)2 ClassVisitor (org.objectweb.asm.ClassVisitor)2 ClassWriter (org.objectweb.asm.ClassWriter)2 IR2JConverter (com.googlecode.d2j.converter.IR2JConverter)1 Dex2Asm (com.googlecode.d2j.dex.Dex2Asm)1 ExDex2Asm (com.googlecode.d2j.dex.ExDex2Asm)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1 BaseDexFileReader (com.googlecode.d2j.reader.BaseDexFileReader)1 BaksmaliDumpOut (com.googlecode.d2j.smali.BaksmaliDumpOut)1 BaksmaliDumper (com.googlecode.d2j.smali.BaksmaliDumper)1 IrMethod (com.googlecode.dex2jar.ir.IrMethod)1 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)1 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)1 File (java.io.File)1