use of com.googlecode.d2j.DexException in project dex2jar by pxb1988.
the class TestUtils method verify.
@SuppressWarnings("rawtypes")
public static void verify(final ClassReader cr, PrintWriter out) throws AnalyzerException, IllegalArgumentException, IllegalAccessException {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
List methods = cn.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
List tryCatchBlocks = method.tryCatchBlocks;
for (int j = 0; j < tryCatchBlocks.size(); j++) {
TryCatchBlockNode tcn = (TryCatchBlockNode) tryCatchBlocks.get(j);
if (tcn.start.equals(tcn.end)) {
throw new DexException("try/catch block %d in %s has same start(%s) and end(%s)", j, method.name, tcn.start.getLabel(), tcn.end.getLabel());
}
}
BasicVerifier verifier = new BasicVerifier();
Analyzer a = new Analyzer(verifier);
try {
a.analyze(cn.name, method);
} catch (Exception e) {
out.println(cr.getClassName() + "." + method.name + method.desc);
printAnalyzerResult(method, a, out);
e.printStackTrace(out);
out.flush();
throw new DexException("method " + method.name + " " + method.desc, e);
}
}
}
use of com.googlecode.d2j.DexException in project dex2jar by pxb1988.
the class ExDex2Asm method convertCode.
@Override
public void convertCode(DexMethodNode methodNode, MethodVisitor mv) {
if (!AsmBridge.isMethodWriter(mv)) {
throw new RuntimeException("We use a MethodWriter tricky here!");
}
MethodNode mn = new MethodNode(Opcodes.ASM4, methodNode.access, methodNode.method.getName(), methodNode.method.getDesc(), null, null);
try {
super.convertCode(methodNode, mn);
} catch (Exception ex) {
if (exceptionHandler == null) {
throw new DexException(ex, "fail convert code for %s", methodNode.method);
} else {
mn.instructions.clear();
mn.tryCatchBlocks.clear();
exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex);
}
}
// code convert ok, copy to MethodWriter and check for Size
mn.accept(mv);
try {
AsmBridge.sizeOfMethodWriter(mv);
} catch (Exception ex) {
mn.instructions.clear();
mn.tryCatchBlocks.clear();
exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex);
AsmBridge.replaceMethodWriter(mv, mn);
}
}
use of com.googlecode.d2j.DexException 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) {
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);
}
}
};
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitorFactory cvf = new ClassVisitorFactory() {
@Override
public ClassVisitor create(String classInternalName) {
return cw;
}
};
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();
DirectClassFile dcf = new DirectClassFile(data, clzNode.className.substring(1, clzNode.className.length() - 1) + ".class", true);
dcf.setAttributeFactory(new StdAttributeFactory());
com.android.dx.dex.file.DexFile dxFile = new com.android.dx.dex.file.DexFile(dexOptions);
CfTranslator.translate(dcf, data, cfOptions, dexOptions, dxFile);
return data;
}
Aggregations