Search in sources :

Example 6 with JadxCodeData

use of jadx.api.data.impl.JadxCodeData in project jadx by skylot.

the class RenameDialog method updateCodeRenames.

private void updateCodeRenames(Consumer<Set<ICodeRename>> updater) {
    JadxProject project = mainWindow.getProject();
    JadxCodeData codeData = project.getCodeData();
    if (codeData == null) {
        codeData = new JadxCodeData();
    }
    Set<ICodeRename> set = new HashSet<>(codeData.getRenames());
    updater.accept(set);
    List<ICodeRename> list = new ArrayList<>(set);
    Collections.sort(list);
    codeData.setRenames(list);
    project.setCodeData(codeData);
    mainWindow.getWrapper().getDecompiler().reloadCodeData();
}
Also used : ICodeRename(jadx.api.data.ICodeRename) ArrayList(java.util.ArrayList) JadxProject(jadx.gui.settings.JadxProject) JadxCodeData(jadx.api.data.impl.JadxCodeData) HashSet(java.util.HashSet)

Example 7 with JadxCodeData

use of jadx.api.data.impl.JadxCodeData in project jadx by skylot.

the class TestUserRenames method test.

@Test
public void test() {
    getArgs().setDeobfuscationOn(false);
    List<ICodeRename> renames = new ArrayList<>();
    String baseClsId = TestCls.class.getName();
    renames.add(new JadxCodeRename(JadxNodeRef.forPkg("jadx.tests"), "renamedPkgTests"));
    renames.add(new JadxCodeRename(JadxNodeRef.forPkg("jadx.tests.integration.rename"), "renamedPkgRename"));
    renames.add(new JadxCodeRename(JadxNodeRef.forCls(baseClsId), "RenamedTestCls"));
    renames.add(new JadxCodeRename(JadxNodeRef.forCls(baseClsId + "$A"), "RenamedInnerCls"));
    renames.add(new JadxCodeRename(new JadxNodeRef(RefType.FIELD, baseClsId, "intField:I"), "renamedField"));
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId, "test(I)I");
    renames.add(new JadxCodeRename(mthRef, "renamedTestMth"));
    renames.add(new JadxCodeRename(mthRef, new JadxCodeRef(CodeRefType.MTH_ARG, 0), "renamedX"));
    JadxCodeRef varDeclareRef = isJavaInput() ? JadxCodeRef.forVar(0, 1) : JadxCodeRef.forVar(0, 0);
    renames.add(new JadxCodeRename(mthRef, varDeclareRef, "renamedY"));
    IJavaCodeRef varUseRef = isJavaInput() ? JadxCodeRef.forVar(0, 4) : JadxCodeRef.forVar(1, 0);
    renames.add(new JadxCodeRename(mthRef, varUseRef, "renamedZ"));
    JadxCodeData codeData = new JadxCodeData();
    codeData.setRenames(renames);
    getArgs().setCodeData(codeData);
    ClassNode cls = getClassNode(TestCls.class);
    assertThat(cls).decompile().checkCodeOffsets().code().containsOne("package jadx.renamedPkgTests.integration.renamedPkgRename;").containsOne("public class RenamedTestCls {").containsOne("private int renamedField").containsOne("public static class RenamedInnerCls {").containsOne("public int renamedTestMth(int renamedX) {").containsOne("int renamedY = renamedX + \"test\".length();").containsOne("int renamedZ = renamedY + 1;").containsOne("return renamedZ;");
    String code = cls.getCode().getCodeStr();
    assertThat(cls).reloadCode(this).isEqualTo(code);
    ICodeRename updVarRename = new JadxCodeRename(mthRef, varUseRef, "anotherZ");
    codeData.setRenames(Collections.singletonList(updVarRename));
    jadxDecompiler.reloadCodeData();
    assertThat(cls).reloadCode(this).containsOne("int anotherZ = y + 1;").doesNotContain("int z").doesNotContain("int renamedZ");
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ICodeRename(jadx.api.data.ICodeRename) ArrayList(java.util.ArrayList) JadxCodeRef(jadx.api.data.impl.JadxCodeRef) IJavaCodeRef(jadx.api.data.IJavaCodeRef) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) JadxCodeRename(jadx.api.data.impl.JadxCodeRename) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 8 with JadxCodeData

use of jadx.api.data.impl.JadxCodeData in project jadx by skylot.

the class TestCodeComments2a method test.

@Test
public void test() {
    printOffsets();
    String baseClsId = TestCls.class.getName();
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId, "test(Z)I");
    IJavaCodeRef insnRef = JadxCodeRef.forInsn(isJavaInput() ? 22 : 18);
    ICodeComment insnComment = new JadxCodeComment(mthRef, insnRef, "return comment");
    IJavaCodeRef insnRef2 = JadxCodeRef.forInsn(isJavaInput() ? 27 : 19);
    ICodeComment insnComment2 = new JadxCodeComment(mthRef, insnRef2, "another return comment");
    JadxCodeData codeData = new JadxCodeData();
    codeData.setComments(Arrays.asList(insnComment, insnComment2));
    getArgs().setCodeData(codeData);
    assertThat(getClassNode(TestCls.class)).decompile().checkCodeOffsets().code().containsOne("// " + insnComment.getComment()).containsOne("// " + insnComment2.getComment());
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment) IJavaCodeRef(jadx.api.data.IJavaCodeRef) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 9 with JadxCodeData

use of jadx.api.data.impl.JadxCodeData in project jadx by skylot.

the class TestCodeComments2 method test.

@Test
public void test() {
    printOffsets();
    String baseClsId = TestCls.class.getName();
    JadxNodeRef mthRef = new JadxNodeRef(RefType.METHOD, baseClsId, "test(Z)I");
    IJavaCodeRef insnRef = JadxCodeRef.forInsn(isJavaInput() ? 13 : 10);
    ICodeComment insnComment = new JadxCodeComment(mthRef, insnRef, "return comment");
    IJavaCodeRef insnRef2 = JadxCodeRef.forInsn(isJavaInput() ? 15 : 11);
    ICodeComment insnComment2 = new JadxCodeComment(mthRef, insnRef2, "another return comment");
    JadxCodeData codeData = new JadxCodeData();
    codeData.setComments(Arrays.asList(insnComment, insnComment2));
    getArgs().setCodeData(codeData);
    assertThat(getClassNode(TestCls.class)).decompile().checkCodeOffsets().code().containsOne("return 1; // " + insnComment.getComment()).containsOne("return 3; // " + insnComment2.getComment());
}
Also used : ICodeComment(jadx.api.data.ICodeComment) JadxCodeComment(jadx.api.data.impl.JadxCodeComment) IJavaCodeRef(jadx.api.data.IJavaCodeRef) JadxNodeRef(jadx.api.data.impl.JadxNodeRef) JadxCodeData(jadx.api.data.impl.JadxCodeData) Test(org.junit.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Aggregations

JadxCodeData (jadx.api.data.impl.JadxCodeData)9 ICodeComment (jadx.api.data.ICodeComment)7 JadxNodeRef (jadx.api.data.impl.JadxNodeRef)6 IntegrationTest (jadx.tests.api.IntegrationTest)6 Test (org.junit.jupiter.api.Test)6 IJavaCodeRef (jadx.api.data.IJavaCodeRef)5 JadxCodeComment (jadx.api.data.impl.JadxCodeComment)5 ClassNode (jadx.core.dex.nodes.ClassNode)3 JadxProject (jadx.gui.settings.JadxProject)3 ArrayList (java.util.ArrayList)3 ICodeRename (jadx.api.data.ICodeRename)2 JadxCodeRef (jadx.api.data.impl.JadxCodeRef)1 JadxCodeRename (jadx.api.data.impl.JadxCodeRename)1 HashSet (java.util.HashSet)1