use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class BaksmaliDexFileVisitor method visit.
@Override
public DexClassVisitor visit(int access_flags, String className, String superClass, String[] interfaceNames) {
return new DexClassNode(access_flags, className, superClass, interfaceNames) {
@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);
}
}
};
}
use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class DexWaveTest method test0.
private void test0(DexWeaver iw, String prefix) throws IOException, RecognitionException {
DexClassNode before = Smali.smaliFile2Node(prefix + "-before.smali", getClass().getResourceAsStream("/weave/smali/" + prefix + "-before.smali"));
DexClassNode expectedAfter = Smali.smaliFile2Node(prefix + "-after.smali", getClass().getResourceAsStream("/weave/smali/" + prefix + "-after.smali"));
DexFileNode dfn = new DexFileNode();
before.accept(iw.wrap(dfn));
assertEqual(expectedAfter, dfn.clzs.get(0));
DexClassNode expectedGen = Smali.smaliFile2Node(prefix + "-gen.j", getClass().getResourceAsStream("/weave/smali/" + prefix + "-gen.smali"));
dfn.clzs.clear();
iw.buildInvocationClz(dfn);
assertEqual(expectedGen, dfn.clzs.get(0));
}
use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class Dex2jarMultiThreadCmd method run0.
private void run0(String fileName, final ExecutorService executorService) throws IOException {
// long baseTS = System.currentTimeMillis();
String baseName = getBaseName(new File(fileName).toPath());
Path currentDir = new File(".").toPath();
Path file = currentDir.resolve(baseName + "-dex2jar.jar");
final Path errorFile = currentDir.resolve(baseName + "-error.zip");
System.err.println("dex2jar " + fileName + " -> " + file);
final BaksmaliBaseDexExceptionHandler exceptionHandler = new BaksmaliBaseDexExceptionHandler();
BaseDexFileReader reader = MultiDexFileReader.open(Files.readAllBytes(new File(fileName).toPath()));
DexFileNode fileNode = new DexFileNode();
try {
reader.accept(fileNode, DexFileReader.SKIP_DEBUG | DexFileReader.IGNORE_READ_EXCEPTION);
} catch (Exception ex) {
exceptionHandler.handleFileException(ex);
throw ex;
}
final FileSystem fs = createZip(file);
final Path dist = fs.getPath("/");
ClassVisitorFactory cvf = new ClassVisitorFactory() {
@Override
public ClassVisitor create(final String name) {
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final LambadaNameSafeClassAdapter rca = new LambadaNameSafeClassAdapter(cw);
return new ClassVisitor(Opcodes.ASM4, rca) {
@Override
public void visitEnd() {
super.visitEnd();
String className = rca.getClassName();
byte[] data;
try {
// FIXME handle 'java.lang.RuntimeException: Method code too large!'
data = cw.toByteArray();
} catch (Exception ex) {
System.err.println(String.format("ASM fail to generate .class file: %s", className));
exceptionHandler.handleFileException(ex);
return;
}
try {
Path dist1 = dist.resolve(className + ".class");
BaseCmd.createParentDirectories(dist1);
Files.write(dist1, data);
} catch (IOException e) {
exceptionHandler.handleFileException(e);
}
}
};
}
};
new ExDex2Asm(exceptionHandler) {
@Override
public void convertDex(final DexFileNode fileNode, final ClassVisitorFactory cvf) {
if (fileNode.clzs != null) {
final Map<String, Clz> classes = collectClzInfo(fileNode);
final List<Future<?>> results = new ArrayList<>(fileNode.clzs.size());
for (final DexClassNode classNode : fileNode.clzs) {
results.add(executorService.submit(new Runnable() {
@Override
public void run() {
convertClass(fileNode, classNode, cvf, classes);
}
}));
}
executorService.submit(new Runnable() {
@Override
public void run() {
for (Future<?> result : results) {
try {
result.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
BaksmaliBaseDexExceptionHandler exceptionHandler1 = (BaksmaliBaseDexExceptionHandler) exceptionHandler;
if (exceptionHandler1.hasException()) {
exceptionHandler1.dump(errorFile, new String[0]);
}
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
}.convertDex(fileNode, cvf);
}
use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class DexTranslatorRunner method methodInvoker.
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
if (method.getMethod().getParameterTypes().length > 0) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
// 1.invoke the method
DexClassNode clzNode = new DexClassNode(DexConstants.ACC_PUBLIC, "La;", "Ljava/lang/Object;", null);
if (method.isStatic()) {
method.invokeExplosively(null, clzNode);
} else {
method.invokeExplosively(test, clzNode);
}
// 2. convert and verify
TestUtils.translateAndCheck(clzNode);
}
};
} else {
return super.methodInvoker(method, test);
}
}
use of com.googlecode.d2j.node.DexClassNode in project dex2jar by pxb1988.
the class TestUtils method testDexASMifier.
public static byte[] testDexASMifier(Class<?> clz, String methodName, String generateClassName) throws Exception {
DexClassNode clzNode = new DexClassNode(DexConstants.ACC_PUBLIC, "L" + generateClassName + ";", "Ljava/lang/Object;", null);
Method m = clz.getMethod(methodName, DexClassVisitor.class);
if (m == null) {
throw new java.lang.NoSuchMethodException(methodName);
}
m.setAccessible(true);
if (Modifier.isStatic(m.getModifiers())) {
m.invoke(null, clzNode);
} else {
m.invoke(clz.newInstance(), clzNode);
}
return translateAndCheck(clzNode);
}
Aggregations