public static Dex2jar from(ByteBuffer in) throws IOException { return from(new DexFileReader(in)); }
public static Baksmali from(byte[] in) throws IOException { return from(new DexFileReader(in)); }
public static Baksmali from(ByteBuffer in) throws IOException { return from(new DexFileReader(in)); }
public static Dex2jar from(InputStream in) throws IOException { return from(new DexFileReader(in)); }
public static Dex2jar from(byte[] in) throws IOException { return from(new DexFileReader(ZipUtil.readDex(in))); }
public static void doData(byte[] data, Path destdir) throws IOException { new DexFileReader(data).accept(new ASMifierFileV(destdir, null)); }
public static BaseDexFileReader open(byte[] data) throws IOException { if (data.length < 3) { throw new IOException("File too small to be a dex/zip"); } if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex return new DexFileReader(data); } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>(); try (ZipFile zipFile = new ZipFile(data)) { for (ZipEntry e : zipFile.entries()) { String entryName = e.getName(); if (entryName.startsWith("classes") && entryName.endsWith(".dex")) { if (!dexFileReaders.containsKey(entryName)) { // only the first one dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e)))); } } } } if (dexFileReaders.size() == 0) { throw new IOException("Can not find classes.dex in zip file"); } else if (dexFileReaders.size() == 1) { return dexFileReaders.firstEntry().getValue(); } else { return new MultiDexFileReader(dexFileReaders.values()); } } throw new IOException("the src file not a .dex or zip file"); }
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; }
for (String f : remainingArgs) { byte[] data = ZipUtil.readDex(new File(f).toPath()); DexFileReader r = new DexFileReader(data); r.accept(fv); DexFileReader r = new DexFileReader(data); r.accept(new DexFileVisitor(out) { @Override
@Override public void evaluate() throws Throwable { File dex = TestUtils.dexP(child.files, new File(dir, child.name + ".dex")); File distFile = new File(dex.getParentFile(), getBaseName(dex.getName()) + "_d2j.jar"); DexFileNode fileNode = new DexFileNode(); DexFileReader r = new DexFileReader(dex); r.accept(fileNode); for (DexClassNode classNode : fileNode.clzs) { TestUtils.translateAndCheck(fileNode, classNode); } } }, describeChild(child), notifier);
private DexFileNode readDex(Path f) { DexFileNode fileNode = new DexFileNode(); DexFileReader reader = null; try { reader = new DexFileReader(ZipUtil.readDex(f)); } catch (IOException e) { throw new RuntimeException("Fail to read dex:" + f); } reader.accept(fileNode); return fileNode; }
@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()); } }
@Test public void test4() throws IOException { DexFileWriter w = new DexFileWriter(); DexFileReader dexFileReader = new DexFileReader(new File("../dex-translator/src/test/resources/dexes/i_jetty.dex")); dexFileReader.accept(w); w.toByteArray(); } }
private void doDex(ByteBuffer bs, final Path out) { DexFileReader reader = new DexFileReader(bs); DexFileNode fileNode = new DexFileNode(); reader.accept(fileNode, DexFileReader.SKIP_CODE);
public static BaseDexFileReader open(byte[] data) throws IOException { if (data.length < 3) { throw new IOException("File too small to be a dex/zip"); } if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex return new DexFileReader(data); } else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>(); try (ZipFile zipFile = new ZipFile(data)) { for (ZipEntry e : zipFile.entries()) { String entryName = e.getName(); if (entryName.startsWith("classes") && entryName.endsWith(".dex")) { if (!dexFileReaders.containsKey(entryName)) { // only the first one dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e)))); } } } } if (dexFileReaders.size() == 0) { throw new IOException("Can not find classes.dex in zip file"); } else if (dexFileReaders.size() == 1) { return dexFileReaders.firstEntry().getValue(); } else { return new MultiDexFileReader(dexFileReaders.values()); } } throw new IOException("the src file not a .dex or zip file"); }
public static void doData(byte[] data, Path destdir) throws IOException { new DexFileReader(data).accept(new ASMifierFileV(destdir, null)); }
public static String rewriteDex(String oldDex) throws IOException { DexFileWriter oldWriter = new DexFileWriter(); DexFileReader reader = new DexFileReader(new File(oldDex)); reader.accept(oldWriter); String rewriteDex = uniqueFileName("rewrite.dex", "."); DiffDexFileWriter.getInstance().build(oldWriter.cp.classDefs.values(), new File(rewriteDex)); return rewriteDex; }
DexFileReader reader = new DexFileReader(new File(oldDex)); reader.accept(oldWriter); oldClasses.addAll(oldWriter.cp.classDefs.values()); if (null != keepDex) { DexFileWriter keepWriter = new DexFileWriter(); reader = new DexFileReader(new File(keepDex)); reader.accept(keepWriter); for (ClassDefItem item : keepWriter.cp.classDefs.values()) {
DexFileReader keepReader = new DexFileReader(keepFile); keepReader.accept(keepFileNode); assertNotNull(keepFileNode.clzs);
@Test public void testDiffV1() { File keepFile = null; try { String oldFile = "src/test/resource/1.dex"; String newFile = "src/test/resource/2.dex"; TwoTuple<String, String> ret = DiffUtils.diff(oldFile, newFile, null); assertNotNull(ret.first); assertNull(ret.second); keepFile = new File(ret.first); DexFileNode fileNode = new DexFileNode(); DexFileReader reader = new DexFileReader(keepFile); reader.accept(fileNode); assertNotNull(fileNode.clzs); assertEquals("keep class is wrong.", 1, fileNode.clzs.size()); } catch (IOException e) { fail(stringify(e)); } finally { if (null != keepFile) { keepFile.delete(); } } }