Skip to content

fix: don't try to guess a better class name when "use source file name" is on#2260

Closed
pubiqq wants to merge 1 commit intoskylot:masterfrom
pubiqq:use-source-file-name-as-class-name
Closed

fix: don't try to guess a better class name when "use source file name" is on#2260
pubiqq wants to merge 1 commit intoskylot:masterfrom
pubiqq:use-source-file-name-as-class-name

Conversation

@pubiqq
Copy link
Copy Markdown
Contributor

@pubiqq pubiqq commented Aug 29, 2024

This PR makes the app use source file name as class name alias if the "Use source file name as class name alias" checkbox is checked, without implicit attempts to guess a better name.

@pubiqq pubiqq force-pushed the use-source-file-name-as-class-name branch from ee03f0d to eec3ed9 Compare August 29, 2024 21:29
@skylot
Copy link
Copy Markdown
Owner

skylot commented Aug 29, 2024

Hm, source file name in most cases contains garbage, so I prefer to keep this renames as safe as possible.
Also in jadx-gui this option is global and enabling it only for some projects can be annoying.
Possible solutions:

  1. make this option local or "per project" - this way it can be enabled only if needed in the current project.
    Big downside here is that this requires a lot of changes in jadx-gui settings UI to allow to change and distinguish global and local parameters. I plan to implement this someday along with custom and predefined profiles support.
  2. change this option into "enum" with entries like Always, If better, Never.
    Small downside is to compatibility/migration issue, so it is actually easier to create new option apply source file name and deprecate old one (internally switching to use only new one).
  3. improve better name algorithm.
    I don't know what case you encounter, but it will be nice if you share it (in format original vs source names) 🙂

I like the second solution, it is just easier. And maybe we can use If better option as default (disabled now).

Related to #1913.

@pubiqq
Copy link
Copy Markdown
Contributor Author

pubiqq commented Aug 30, 2024

Well, the checkbox is called "Use source file name as class name alias", I explicitly checked it, and I expect it to work that way. The checkbox is unchecked by default, so the PR won't change the default behavior of the program and class names will remain the same as before.

Your proposal can be implemented, but I think that's material for a separate issue/discussion/PR.

I don't know what case you encounter, but it will be nice if you share it (in format original vs source names) 🙂

Sure, here are some examples:

currentAlias: "C2937kh",         alias: "Room"         => betterName: "C2937kh", but should be "Room"
currentAlias: "C1428qi",         alias: "Fade"         => betterName: "C1428qi", but should be "Fade"
currentAlias: "C4063yi",         alias: "Scene"        => betterName: "C4063yi", but should be "Scene"
currentAlias: "AbstractC3038lk", alias: "PagerAdapter" => betterName: "AbstractC3038lk", but should be "PagerAdapter"

@skylot
Copy link
Copy Markdown
Owner

skylot commented Aug 30, 2024

I explicitly checked it, and I expect it to work that way

That is why I suggested to use more explicit options/names instead of just boolean, it will be easier to understand what it does.

The checkbox is unchecked by default, so the PR won't change the default behavior of the program and class names will remain the same as before.

This option works only for some apks/projects, enabling it will affect all projects and might apply worse names and this is the reason why it disabled by default.

here are some examples

Oh, so we just need to not select names generated by jadx or names with many numbers.
This is actually will be the easiest fix for this issue 🤣

So, as a conclusion to this PR: I don't want to remove better name check. We need to apply suggested solutions, and it looks like we will need all of them eventually.
@pubiqq you can change this PR into one of solutions or close it and open a new one if you want to.

And BTW, another solutions is to provide API to change better name implementation and allow users to implement own rules via scripts or plugins (similar as it was done for deobfuscator).

@pubiqq
Copy link
Copy Markdown
Contributor Author

pubiqq commented Aug 31, 2024

It looks like you've thought of something more global than what I had in mind in this PR. 😂

That is why I suggested to use more explicit options/names instead of just boolean, it will be easier to understand what it does.

This option works only for some apks/projects, enabling it will affect all projects and might apply worse names and this is the reason why it disabled by default.

I have no problem understanding the option name.
I'm not suggesting changing the default renaming behavior.

I just want the checkbox with the name
"Use source file name as class name alias"
to make the app
use source file name as class name alias,
without hidden mechanics and surprises.

I have other changes to improve the renaming mechanism as well, including the ones you suggested

Trust me <deleted>

, I'm just going to submit them in separate PRs.

--

And BTW, another solutions is to provide API to change better name implementation and allow users to implement own rules via scripts or plugins (similar as it was done for deobfuscator).

It would be great if deobfuscation/renaming could be implemented as a separate plugin (if possible of course).

@skylot
Copy link
Copy Markdown
Owner

skylot commented Aug 31, 2024

Trust me, I'm just going to submit them in separate PRs.

Sure, if you have better implementation and want to open a new PR, I will close this one.

It would be great if deobfuscation/renaming could be implemented as a separate plugin (if possible of course).

It is possible, all renaming happen in jadx passes, so it can be done in a jadx plugin (short guide)

@skylot skylot closed this Aug 31, 2024
@pubiqq
Copy link
Copy Markdown
Contributor Author

pubiqq commented Sep 2, 2024

<nevermind>

@pubiqq pubiqq changed the title feat: don't try to guess a better class name when "use source file name" is on fix: don't try to guess a better class name when "use source file name" is on Sep 2, 2024
@pubiqq pubiqq deleted the use-source-file-name-as-class-name branch September 2, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants