-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle super case for invokespecial opcode (#1300)
- Loading branch information
Showing
9 changed files
with
165 additions
and
9 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
20 changes: 20 additions & 0 deletions
20
jadx-core/src/test/java/jadx/tests/api/extensions/inputs/InputPlugin.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,20 @@ | ||
package jadx.tests.api.extensions.inputs; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
public enum InputPlugin implements Consumer<IntegrationTest> { | ||
DEX { | ||
@Override | ||
public void accept(IntegrationTest test) { | ||
test.useDexInput(); | ||
} | ||
}, | ||
JAVA { | ||
@Override | ||
public void accept(IntegrationTest test) { | ||
test.useJavaInput(); | ||
} | ||
}; | ||
} |
65 changes: 65 additions & 0 deletions
65
jadx-core/src/test/java/jadx/tests/api/extensions/inputs/JadxInputPluginsExtension.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,65 @@ | ||
package jadx.tests.api.extensions.inputs; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; | ||
import org.junit.jupiter.api.extension.Extension; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; | ||
import org.junit.platform.commons.util.AnnotationUtils; | ||
import org.junit.platform.commons.util.Preconditions; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated; | ||
|
||
public class JadxInputPluginsExtension implements TestTemplateInvocationContextProvider { | ||
|
||
@Override | ||
public boolean supportsTestTemplate(ExtensionContext context) { | ||
return isAnnotated(context.getTestMethod(), TestWithInputPlugins.class); | ||
} | ||
|
||
@Override | ||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { | ||
Preconditions.condition(IntegrationTest.class.isAssignableFrom(context.getRequiredTestClass()), | ||
"@TestWithInputPlugins should be used only in IntegrationTest subclasses"); | ||
|
||
Method testMethod = context.getRequiredTestMethod(); | ||
boolean testAnnAdded = AnnotationUtils.findAnnotation(testMethod, Test.class).isPresent(); | ||
Preconditions.condition(!testAnnAdded, "@Test annotation should be removed"); | ||
|
||
TestWithInputPlugins inputPluginAnn = AnnotationUtils.findAnnotation(testMethod, TestWithInputPlugins.class).get(); | ||
return Stream.of(inputPluginAnn.value()) | ||
.sorted() | ||
.map(RunWithInputPlugin::new); | ||
} | ||
|
||
private static class RunWithInputPlugin implements TestTemplateInvocationContext { | ||
private final InputPlugin plugin; | ||
|
||
public RunWithInputPlugin(InputPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public String getDisplayName(int invocationIndex) { | ||
return plugin.name().toLowerCase(Locale.ROOT) + " input"; | ||
} | ||
|
||
@Override | ||
public List<Extension> getAdditionalExtensions() { | ||
return Collections.singletonList(beforeTest()); | ||
} | ||
|
||
private BeforeTestExecutionCallback beforeTest() { | ||
return execContext -> plugin.accept((IntegrationTest) execContext.getRequiredTestInstance()); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
jadx-core/src/test/java/jadx/tests/api/extensions/inputs/TestWithInputPlugins.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,18 @@ | ||
package jadx.tests.api.extensions.inputs; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@TestTemplate | ||
@ExtendWith(JadxInputPluginsExtension.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.METHOD, ElementType.TYPE }) | ||
public @interface TestWithInputPlugins { | ||
|
||
InputPlugin[] value(); | ||
} |
29 changes: 29 additions & 0 deletions
29
jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvoke2.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,29 @@ | ||
package jadx.tests.integration.invoke; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
import jadx.tests.api.extensions.inputs.InputPlugin; | ||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestSuperInvoke2 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
@Override | ||
public String toString() { | ||
return super.toString(); | ||
} | ||
|
||
public void check() { | ||
assertThat(new TestCls().toString()).containsOne("@"); | ||
} | ||
} | ||
|
||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA }) | ||
public void test() { | ||
noDebugInfo(); | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsOne("return super.toString();"); | ||
} | ||
} |
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