From d24b835e297795c58b506db9896c43db88c269fd Mon Sep 17 00:00:00 2001 From: EBK21 Date: Mon, 1 May 2023 03:01:27 +0800 Subject: [PATCH] try fix compute_frame --- .../java/com/googlecode/d2j/dex/Dex2jar.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java index 9565d9a47..f6dfd78fe 100644 --- a/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java +++ b/dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2jar.java @@ -24,6 +24,7 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; public final class Dex2jar { @@ -56,11 +57,47 @@ private void doTranslate(final Path dist) { exceptionHandler.handleFileException(ex); } ClassVisitorFactory cvf = new ClassVisitorFactory() { + public String curSupnam = null; + public boolean isInterf = false; @Override public ClassVisitor create(final String name) { - final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES) { + @Override + protected String getCommonSuperClass(String type1, String type2) { + if(type1.equals("java/lang/Object") || type2.equals("java/lang/Object") || isInterf) + return "java/lang/Object"; + String name; + String name2 = "none"; + try { + return super.getCommonSuperClass(type1, type2); + } catch (TypeNotPresentException e) { + name = e.typeName(); + }; + if (name.equals(type1)) { + name2 = type2; + } else if (name.equals(type2)) { + name2 = type1; + } + if(name2.equals(curSupnam)) + return curSupnam; + System.err.printf("Another associated class is %s for %s\n", name2, name); + // FIXME This may be a safer choice for now but we really need to find the real one. + System.err.printf("Assuming java/lang/Object !\n"); + return "java/lang/Object"; + } + }; final LambadaNameSafeClassAdapter rca = new LambadaNameSafeClassAdapter(cw); return new ClassVisitor(Constants.ASM_VERSION, rca) { + @Override + public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { + super.visit(version, access, name, signature, superName, interfaces); + curSupnam = superName; + if((access & Opcodes.ACC_INTERFACE) != 0){ + isInterf = true; + } else { + isInterf = false; + } + } @Override public void visitEnd() { super.visitEnd();