/** * equals to {@link #accept(DexFileVisitor, int)} with 0 as config * * @param dv */ @Override public void accept(DexFileVisitor dv) { this.accept(dv, 0); }
@Override public void accept(DexFileVisitor dv, int classIdx, int config) { Item item = items.get(classIdx); item.reader.accept(dv, item.idx, config); }
public void to(final Path base) { final BaksmaliDumper bs = new BaksmaliDumper(parameterRegisters, useLocals); reader.accept(new BaksmaliDexFileVisitor(base, bs), this.noDebug ? DexFileReader.SKIP_CODE : 0); }
public static void doData(byte[] data, Path destdir) throws IOException { new DexFileReader(data).accept(new ASMifierFileV(destdir, null)); }
/** * Makes the given visitor visit the dex file. * * @param dv * visitor * @param config * config flags, {@link #SKIP_CODE}, {@link #SKIP_DEBUG}, {@link #SKIP_ANNOTATION}, * {@link #SKIP_FIELD_CONSTANT} */ @Override public void accept(DexFileVisitor dv, int config) { dv.visitDexFileVersion(this.dex_version); for (int cid = 0; cid < class_defs_size; cid++) { accept(dv, cid, config); } dv.visitEnd(); }
@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()); } }
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; }
@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 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); Dex2Asm dex2Asm = new Dex2Asm(); dex2Asm.convertDex(fileNode, new ClassVisitorFactory() {
/** * equals to {@link #accept(DexFileVisitor, int)} with 0 as config * * @param dv */ @Override public void accept(DexFileVisitor dv) { this.accept(dv, 0); }
@Override public void accept(DexFileVisitor dv, int classIdx, int config) { Item item = items.get(classIdx); item.reader.accept(dv, item.idx, config); }
/** * Makes the given visitor visit the dex file. * * @param dv * visitor * @param config * config flags, {@link #SKIP_CODE}, {@link #SKIP_DEBUG}, {@link #SKIP_ANNOTATION}, * {@link #SKIP_FIELD_CONSTANT} */ @Override public void accept(DexFileVisitor dv, int config) { for (int cid = 0; cid < class_defs_size; cid++) { accept(dv, cid, config); } dv.visitEnd(); }
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; }
DexFileWriter oldWriter = new DexFileWriter(); DexFileReader reader = new DexFileReader(new File(oldDex)); reader.accept(oldWriter); oldClasses.addAll(oldWriter.cp.classDefs.values()); DexFileWriter keepWriter = new DexFileWriter(); reader = new DexFileReader(new File(keepDex)); reader.accept(keepWriter); for (ClassDefItem item : keepWriter.cp.classDefs.values()) { replaceClassMap.put(item.clazz.descriptor.stringData.string, item);
DexFileNode keepFileNode = new DexFileNode(); DexFileReader keepReader = new DexFileReader(keepFile); keepReader.accept(keepFileNode); assertNotNull(keepFileNode.clzs); assertEquals("keep class is wrong.", 1, keepFileNode.clzs.size());
@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(); } } }