-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: additional checks for loop exit edges and 'for' conversion (#483)
- Loading branch information
Showing
6 changed files
with
184 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 7 additions & 8 deletions
15
jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexedLoop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
jadx-core/src/test/java/jadx/tests/integration/loops/TestNotIndexedLoop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package jadx.tests.integration.loops; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
public class TestNotIndexedLoop extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
public File test(File[] files) { | ||
File file; | ||
if (files != null) { | ||
int length = files.length; | ||
if (length == 0) { | ||
file = null; | ||
} else { | ||
int i = 0; | ||
while (true) { | ||
if (i >= length) { | ||
file = null; | ||
break; | ||
} | ||
file = files[i]; | ||
if (file.getName().equals("f")) { | ||
break; | ||
} | ||
i++; | ||
} | ||
} | ||
} else { | ||
file = null; | ||
} | ||
if (file != null) { | ||
file.deleteOnExit(); | ||
} | ||
return file; | ||
} | ||
|
||
public void check() { | ||
assertThat(test(null), nullValue()); | ||
assertThat(test(new File[]{}), nullValue()); | ||
|
||
File file = new File("f"); | ||
assertThat(test(new File[]{new File("a"), file}), is(file)); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, not(containsString("for ("))); | ||
assertThat(code, containsOne("while (true) {")); | ||
} | ||
|
||
@Test | ||
public void testNoDebug() { | ||
noDebugInfo(); | ||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, not(containsString("for ("))); | ||
assertThat(code, containsOne("while (true) {")); | ||
} | ||
} |