Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] Why not add code editing features #2215

Open
1 of 3 tasks
shinjaxu opened this issue Jul 12, 2024 · 3 comments
Open
1 of 3 tasks

[gui] Why not add code editing features #2215

shinjaxu opened this issue Jul 12, 2024 · 3 comments
Labels
bug GUI Issues in jadx-gui module

Comments

@shinjaxu
Copy link

Issue details

Is it a problem with the positioning of the software?

Jadx version

1.5

Java version

12

OS

  • Windows
  • Linux
  • macOS
@shinjaxu shinjaxu added bug GUI Issues in jadx-gui module labels Jul 12, 2024
@jpstotz
Copy link
Collaborator

jpstotz commented Jul 19, 2024

As far as I know no such feature is planned. May be because decompiling, editing and recompiling is 100 times more difficult to implement.

For simple APK files you can use the function "Save as gradle project" which will create a project that you can compile using Android SDK.

For more complex apps I strongly recommend to use apktool.

@Mino260806
Copy link
Contributor

May be because decompiling, editing and recompiling is 100 times more difficult to implement.

@jpstotz what if we only compile one java method at a time (not recompile the entire project, nor the entire class). If we consider how .smali files are structeredn all methods are independant from each others, so each method would still compile fine even when it's isolated.

For example say we have a class Example

package com.example;

public class Example {
    int field1;
    Object field2;
    // ...
    String field_n;

    public void targetMethod() {
        System.out.println("To be edited");
    }

    public void methodOne() {
         // Very long body
    }

    public void methodTwo() {
         // ...
    }

    public void methodThree() {
         // ...
    }

   // and so on
}

Say the user would finish editing "targetMethod", Jadx would isolate the method in an internal temp .java file like this

package com.example;

public class Example {
    int field1;
    Object field2;
    // ...
    String field_n;

    public void targetMethod() {
        System.out.println("Editing finished");
    }
}

It would also convert other compiled files to some library.jar

And then compile with the command

javac -cp library.jar com/example/Example.java

Then convert it using baksmali to .smali file, copy the target method only using simple regex to find it, paste it in the original .smali file and recompile the entire project from .smali files.

The only problem that remains to be solved is for invalid java class and method names (like those starting with digits) which will cause compilation error, maybe we'd do some naming convention that replaces the names back afterwards, but I'm sure it's solvable. Let's have a minimal working example first.

I can give it a shot if you confirm that it may be added

@jpstotz
Copy link
Collaborator

jpstotz commented Jul 26, 2024

In general you are correct for Java and class files but Jadx doesn't work on class files, but DEX files. I just outline the problems for modifying Android code as this is the main purpose of Jadx. Complexity increases when different source formats have to be considered.

  1. For compiling a Java source file you need the imported classes in JAR format. But Jadx usually works on DEX files, not on class files. Therefore you would need an additional tool like dex2jar or you would need to develop at least a dex-to-class file generator that reconstructs the class structure and the methods so that the to be compiler could link to them when compiling the Java source file.
  2. Jadx uses deobfuscation for making class- and method and other names easier to understand for humans. For compiling you would have to reverse all the renamings to make the code compilable.
  3. The re-compiled class files have to be converted to DEX which is also not that simple considering that there are (depending on the Android target platform) techniques necessary like desugaring lambda or certain API calls.
  4. The DEX code needs to be integrated into a DEX file. A DEX file contains strings, constants and many more elements of multiple classfiles in a merged way, e.g. all Strings are combined into one table. Therefore simply replacing DEX code of one class with a recompiled version requires rebuilding the whole dex file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug GUI Issues in jadx-gui module
Projects
None yet
Development

No branches or pull requests

3 participants