@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { smaliFile(file, dfv); return super.visitFile(file, attrs); } });
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; }
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; }
public static void smali(Path base, final DexFileVisitor dfv) throws IOException { if (Files.isDirectory(base)) { Files.walkFileTree(base, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path fn = dir.getFileName(); if (fn != null && fn.toString().startsWith(".")) { return FileVisitResult.SKIP_SUBTREE; } return super.preVisitDirectory(dir, attrs); } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { smaliFile(file, dfv); return super.visitFile(file, attrs); } }); } else if (Files.isRegularFile(base)) { smaliFile(base, dfv); } } }
smali.smaliFile("<stdin>", System.in, fv); System.err.println("smali <stdin> -> " + output);
@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(); } }
final DexFileNode fileNode = new DexFileNode(); try { smali.smaliFile(p, fileNode); } catch (IOException e) { throw new RuntimeException(e);