use of com.googlecode.d2j.smali.BaksmaliDumper in project dex2jar by pxb1988.
the class BaksmaliTest method dotest.
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);
}
}
use of com.googlecode.d2j.smali.BaksmaliDumper in project dex2jar by pxb1988.
the class DexWaveTest method toStd.
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();
}
use of com.googlecode.d2j.smali.BaksmaliDumper in project dex2jar by pxb1988.
the class TestUtils method translateAndCheck.
public static byte[] translateAndCheck(DexFileNode fileNode, DexClassNode clzNode) throws AnalyzerException, IllegalAccessException {
// 1. convert to .class
Dex2Asm dex2Asm = new Dex2Asm() {
@Override
public void convertCode(DexMethodNode methodNode, MethodVisitor mv, ClzCtx clzCtx) {
try {
super.convertCode(methodNode, mv, clzCtx);
} 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, "Failed to convert code for %s", methodNode.method);
}
}
};
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final LambadaNameSafeClassAdapter rca = new LambadaNameSafeClassAdapter(cw);
ClassVisitorFactory cvf = new ClassVisitorFactory() {
@Override
public ClassVisitor create(String classInternalName) {
return rca;
}
};
if (fileNode != null) {
dex2Asm.convertClass(clzNode, cvf, fileNode);
} else {
dex2Asm.convertClass(clzNode, cvf);
}
byte[] data = cw.toByteArray();
// 2. verify .class
ClassReader cr = new ClassReader(data);
TestUtils.verify(cr);
// 3. convert back to dex
CfOptions cfOptions = new CfOptions();
cfOptions.strictNameCheck = false;
DexOptions dexOptions = new DexOptions();
if (fileNode != null && fileNode.dexVersion >= DexConstants.DEX_037) {
dexOptions.minSdkVersion = 26;
}
DirectClassFile dcf = new DirectClassFile(data, rca.getClassName() + ".class", true);
dcf.setAttributeFactory(new StdAttributeFactory());
com.android.dx.dex.file.DexFile dxFile = new com.android.dx.dex.file.DexFile(dexOptions);
try {
CfTranslator.translate(new DxContext(), dcf, data, cfOptions, dexOptions, dxFile);
} catch (ParseException e) {
if ("MethodHandle not supported".equals(e.getMessage())) {
e.printStackTrace();
} else {
throw e;
}
}
return data;
}
use of com.googlecode.d2j.smali.BaksmaliDumper in project dex2jar by pxb1988.
the class SmaliTest method test.
@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();
}
}
use of com.googlecode.d2j.smali.BaksmaliDumper in project dex2jar by pxb1988.
the class SmaliTest method pbaksmali.
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();
}
Aggregations