private void dumpMethod(BufferedWriter writer, DexMethodNode dexMethodNode, Exception ex) throws IOException { writer.append(dexMethodNode.method.toString()); writer.newLine(); writer.flush(); ex.printStackTrace(new PrintWriter(writer, true)); writer.newLine(); new BaksmaliDumper().baksmaliMethod(dexMethodNode, writer); writer.flush(); }
public void baksmaliClass(DexClassNode n, BufferedWriter writer) { baksmaliClass(n, new BaksmaliDumpOut(writer)); }
public static String toStd(DexClassNode expected) throws IOException { StringWriter stringWriter = new StringWriter(); BufferedWriter bufferedWriter = new BufferedWriter(stringWriter); BaksmaliDumpOut out = new BaksmaliDumpOut(bufferedWriter); final BaksmaliDumper bs = new BaksmaliDumper(true, false); bs.baksmaliClass(expected, out); bufferedWriter.close(); return stringWriter.toString(); } }
appendAccess(n.access, buff); buff.append(escapeType(n.className)); out.s(buff.toString()); if (n.superClass != null) { out.s(".super %s", escapeType(n.superClass)); out.s(".implements %s", escapeType(itf)); out.s(".source " + escapeValue(n.source)); dumpAnns(n.anns, out); buff.setLength(0); buff.append(".field "); appendAccess(f.access | ACCESS_FIELD, buff); Field field = f.field; buff.append(escapeId(f.field.getName())).append(":").append(escapeType(field.getType())); if (f.cst != null) { buff.append(" = "); buff.append(escapeValue(f.cst)); dumpAnns(f.anns, out); out.pop(); out.s(".end field"); baksmaliMethod(m, out);
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); }
buff.append(".method "); Method method = m.method; appendAccess(m.access, buff); buff.append(escapeId(method.getName())).append(escapeMethodDesc(method)); out.s(buff.toString()); out.push(); if (m.anns != null) { dumpAnns(m.anns, out); String debugName = parameterNames == null ? null : i < parameterNames.size() ? parameterNames.get(i) : null; if (debugName != null) { out.s(".parameter \"" + escapeId(debugName) + "\" # " + type); } else { out.s(".parameter # " + type); if (ps != null && ps.size() != 0) { out.push(); dumpAnns(ps, out); out.pop(); out.s(".end parameter"); baksmaliCode(m, m.codeNode, out);
public void baksmaliMethod(DexMethodNode m, BufferedWriter writer) { baksmaliMethod(m, new BaksmaliDumpOut(writer)); }
accept(out, codeNode, dexCodeVisitor); dexCodeVisitor.visitEnd();
private static String pbaksmali(DexClassNode dcn) throws IOException { StringWriter bufWriter = new StringWriter(); BufferedWriter w = new BufferedWriter(bufWriter); new BaksmaliDumper(true, true).baksmaliClass(dcn, new BaksmaliDumpOut(w)); w.flush(); bufWriter.flush(); return bufWriter.toString(); }
private void dotest(Path f) throws Exception { Path smali0 = new File("target/" + f.getFileName() + "-smali0.zip").toPath(); try (FileSystem fs0 = BaseCmd.createZip(smali0)) { Baksmali.from(f).to(fs0.getPath("/")); } Path smali1 = new File("target/" + f.getFileName() + "-smali1.zip").toPath(); try (FileSystem fs0 = BaseCmd.openZip(smali0); FileSystem fs1 = BaseCmd.createZip(smali1)) { BaksmaliDumper baksmaliDumper = new BaksmaliDumper(); BaksmaliDexFileVisitor v = new BaksmaliDexFileVisitor(fs1.getPath("/"), baksmaliDumper); Smali.smali(fs0.getPath("/"), v); } } }
@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(); } }
@Override public void convertCode(DexMethodNode methodNode, MethodVisitor mv) { try { super.convertCode(methodNode, mv); } catch (Exception ex) { BaksmaliDumper d = new BaksmaliDumper(); try { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.err, "UTF-8")); d.baksmaliMethod(methodNode, out); out.flush(); } catch (IOException e) { e.printStackTrace(); } throw new DexException(ex, "fail convert code %s", methodNode.method); } } };
@Override public void visitEnd() { super.visitEnd(); Path smaliFile = dir .resolve(rebuildFileName(className.substring(1, className.length() - 1)) + ".smali"); try { Path parent = smaliFile.getParent(); if (parent != null && !Files.exists(parent)) { Files.createDirectories(parent); } } catch (IOException e) { throw new RuntimeException(e); } try (BufferedWriter writer = Files.newBufferedWriter(smaliFile, StandardCharsets.UTF_8)) { BaksmaliDumpOut out = new BaksmaliDumpOut(writer); bs.baksmaliClass(this, out); writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } } };