Skip to content

Commit

Permalink
fix: handle move-result after invoke-custom with string concat
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Dec 11, 2021
1 parent 2d6f819 commit 0f00fb9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ private static void initJumps(MethodNode mth, InsnNode[] insnByOffset) {
}
break;

case STR_CONCAT:
// invoke-custom with string concatenation translated directly to STR_CONCAT, merge next move-result
if (insn.getResult() == null) {
mergeMoveResult(insnByOffset, offset, insn, ArgType.STRING);
}
break;

case FILLED_NEW_ARRAY:
ArgType arrType = ((FilledNewArrayNode) insn).getArrayType();
mergeMoveResult(insnByOffset, offset, insn, arrType);
Expand Down
2 changes: 2 additions & 0 deletions jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import jadx.core.xmlgen.ResourceStorage;
import jadx.core.xmlgen.entry.ResourceEntry;
import jadx.tests.api.compiler.DynamicCompiler;
import jadx.tests.api.compiler.JavaUtils;
import jadx.tests.api.compiler.StaticCompiler;
import jadx.tests.api.utils.TestUtils;

Expand Down Expand Up @@ -490,6 +491,7 @@ protected void useEclipseCompiler() {
}

protected void useTargetJavaVersion(int version) {
Assumptions.assumeTrue(JavaUtils.checkJavaVersion(version), "skip test for higher java version");
this.targetJavaVersion = version;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.junit.jupiter.api.Test;

import jadx.tests.api.RaungTest;
import jadx.tests.api.extensions.inputs.InputPlugin;
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

Expand Down Expand Up @@ -40,7 +42,7 @@ public void test() {
}

@Test
public void testJava() {
public void testJava8() {
noDebugInfo();
assertThat(getClassNode(TestCls.class))
.code()
Expand All @@ -49,4 +51,14 @@ public void testJava() {
"return str + \"test\" + str + 7;",
"return str + \"test\" + str + \"7\";"); // dynamic concat add const to string recipe
}

@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
public void testJava11() {
useTargetJavaVersion(11);
noDebugInfo();
assertThat(getClassNode(TestCls.class))
.code()
.containsOne("return str + \"test\";")
.containsOne("return str + \"test\" + str + \"7\";");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ private static void convertSimpleJar(ConvertResult result, Path path) throws Exc

try {
DxConverter.run(path, tempDirectory);
} catch (Exception e) {
} catch (Throwable e) {
LOG.warn("DX convert failed, trying D8, path: {}", path);
D8Converter.run(path, tempDirectory);
try {
D8Converter.run(path, tempDirectory);
} catch (Throwable ex) {
LOG.error("D8 convert failed: {}", ex.getMessage());
}
}

LOG.debug("Converted to dex: {}", path.toAbsolutePath());
Expand Down

0 comments on commit 0f00fb9

Please sign in to comment.