Skip to content

Commit

Permalink
test and comment done
Browse files Browse the repository at this point in the history
  • Loading branch information
Rabbit0w0 committed Oct 22, 2024
1 parent e6f54e0 commit 2483b9c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dex-translator/src/main/java/com/googlecode/d2j/dex/DexFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 2. static-final field init by zero, but assigned in clinit
* <p>
Expand Down Expand Up @@ -120,6 +120,12 @@ public void visitFieldStmt(Op op, int a, int b, Field field) {

}

/**
* Target: Method
* <p>
* Fixes too long strings not being translated correctly
* </p>
*/
public static void fixTooLongStringConstant(final DexMethodNode methodNode) {
if ((methodNode.access & 0x100) != 0 || (methodNode.access & 0x400) != 0) {
return; // in case of unimplemented method
Expand Down Expand Up @@ -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},
Expand All @@ -169,19 +177,22 @@ 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},
new Method("Ljava/lang/StringBuilder;", "toString",
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);
Expand Down

0 comments on commit 2483b9c

Please sign in to comment.