From 2483b9c8883c050733b787eb055b9b8bf37b7e72 Mon Sep 17 00:00:00 2001 From: Rabbit0w0 Date: Tue, 22 Oct 2024 18:32:17 +0800 Subject: [PATCH] test and comment done --- .../main/java/com/googlecode/d2j/dex/DexFix.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dex-translator/src/main/java/com/googlecode/d2j/dex/DexFix.java b/dex-translator/src/main/java/com/googlecode/d2j/dex/DexFix.java index 7222c00a..9b89073e 100644 --- a/dex-translator/src/main/java/com/googlecode/d2j/dex/DexFix.java +++ b/dex-translator/src/main/java/com/googlecode/d2j/dex/DexFix.java @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * 1. Dex omits the value of static-final filed if it is the default value. + * 1. Dex omits the value of static-final field if it is the default value. *

* 2. static-final field init by zero, but assigned in clinit *

@@ -120,6 +120,12 @@ public void visitFieldStmt(Op op, int a, int b, Field field) { } + /** + * Target: Method + *

+ * Fixes too long strings not being translated correctly + *

+ */ public static void fixTooLongStringConstant(final DexMethodNode methodNode) { if ((methodNode.access & 0x100) != 0 || (methodNode.access & 0x400) != 0) { return; // in case of unimplemented method @@ -160,7 +166,9 @@ public static void fixTooLongStringConstant(final DexMethodNode methodNode) { )); for (String part : parts) { + // const-string v1 "xxx" generatedStringConcat.add(new ConstStmtNode(Op.CONST_STRING, register + 1, part)); + // invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; generatedStringConcat.add(new MethodStmtNode( Op.INVOKE_VIRTUAL, new int[]{register, register + 1}, @@ -169,6 +177,7 @@ public static void fixTooLongStringConstant(final DexMethodNode methodNode) { )); } + // invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String; generatedStringConcat.add(new MethodStmtNode( Op.INVOKE_VIRTUAL, new int[]{register}, @@ -176,12 +185,14 @@ public static void fixTooLongStringConstant(final DexMethodNode methodNode) { new String[]{}, "Ljava/lang/String;") )); + // move-result-object v0 generatedStringConcat.add(new Stmt1RNode(Op.MOVE_RESULT_OBJECT, register)); toBeReplaced.put(insn, generatedStringConcat); maxRegister.set(Math.max(register + 1, maxRegister.get())); } }); + methodNode.codeNode.totalRegister = maxRegister.get(); toBeReplaced.keySet().forEach(i -> { int index = methodNode.codeNode.stmts.indexOf(i);