Skip to content

Commit

Permalink
Finally fix handling of large arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Apr 1, 2022
1 parent 0e26919 commit 8496704
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,14 @@ public void convertClass(int dexVersion, DexClassNode classNode, ClassVisitorFac
cv.visitEnd();
}

private static final String HEX_CLASS_LOCATION = "res/Hex";

private static final Set<String> HEX_DECODE_METHODS =
new HashSet<>(Arrays.asList("decode_J", "decode_I", "decode_S", "decode_B"));

private void addHexDecodeMethod(ClassVisitor outCV, String className, String hexDecodeMethodNameBase) {
// the .data is a class-file compiled from res.Hex
try (InputStream is = Dex2Asm.class.getResourceAsStream("/res/Hex.class")) {
System.err.println(className);
try (InputStream is = Dex2Asm.class.getResourceAsStream("/" + HEX_CLASS_LOCATION + ".class")) {
ClassReader cr = new ClassReader(is);
cr.accept(new ClassVisitor(Constants.ASM_VERSION) {
@Override
Expand All @@ -570,14 +572,16 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
if (HEX_DECODE_METHODS.contains(name)) {
return new MethodVisitor(Constants.ASM_VERSION,
outCV.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
hexDecodeMethodNameBase + "$" + name,
desc, signature, exceptions
)) {
hexDecodeMethodNameBase + "$" + name, desc, signature, exceptions)) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor,
boolean isInterface) {
super.visitMethodInsn(opcode, owner.equals("res/Hex") ? className : owner, name,
descriptor, isInterface);
if (owner.equals(HEX_CLASS_LOCATION)) {
super.visitMethodInsn(opcode, className, hexDecodeMethodNameBase + "$" + name,
descriptor, isInterface);
} else {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
}
};
} else {
Expand All @@ -586,7 +590,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String descri
}
}, ClassReader.EXPAND_FRAMES);
} catch (Throwable t) {
throw new RuntimeException("Failed to add Hex.decode_*", t);
throw new RuntimeException("Failed to add " + HEX_CLASS_LOCATION + ".decode_*", t);
}
}

Expand Down

0 comments on commit 8496704

Please sign in to comment.