use of com.googlecode.d2j.node.DexClassNode 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.node.DexClassNode in project dex2jar by pxb1988.
the class SmaliTest method dotest.
private void dotest(File dexFile) throws IOException {
DexBackedDexFile dex;
try {
dex = DexFileFactory.loadDexFile(dexFile, 14, false);
} catch (DexBackedDexFile.NotADexFile ex) {
ex.printStackTrace();
return;
}
Map<String, DexClassNode> map = readDex(dexFile);
for (DexBackedClassDef def : dex.getClasses()) {
String type = def.getType();
System.out.println(type);
DexClassNode dexClassNode = map.get(type);
Assert.assertNotNull(dexClassNode);
// original
String smali = baksmali(def);
Smali.smaliFile2Node("fake.smali", smali);
{
byte[] data = toDex(dexClassNode);
DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
// original
String baksmali3 = baksmali(def2);
Assert.assertEquals(smali, baksmali3);
}
String psmali = pbaksmali(dexClassNode);
DexClassNode dexClassNode2 = Smali.smaliFile2Node("fake.smali", psmali);
Assert.assertEquals("cmp smalip", psmali, pbaksmali(dexClassNode2));
{
byte[] data = toDex(dexClassNode2);
DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
// original
String baksmali3 = baksmali(def2);
Assert.assertEquals(smali, baksmali3);
}
}
}
use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class SmaliTest method readDex.
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;
}
Aggregations