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

[feature] Support manual constant uninlining #2395

Open
NebelNidas opened this issue Jan 18, 2025 · 3 comments
Open

[feature] Support manual constant uninlining #2395

NebelNidas opened this issue Jan 18, 2025 · 3 comments

Comments

@NebelNidas
Copy link
Contributor

NebelNidas commented Jan 18, 2025

Describe your idea

javac tends to inline constants, leading to magic numbers appearing all over the decompiled code. A method like this:

boolean place(ItemPlacementContext context, BlockState state) {
   return context.getWorld().setBlockState(context.getBlockPos(), state, Block.NOTIFY_LISTENERS | Block.REDRAW_ON_MAIN_THREAD | Block.FORCE_STATE);
}

will be turned into this:

boolean place(ItemPlacementContext context, BlockState state) {
   return context.getWorld().setBlockState(context.getBlockPos(), state, 26);
}

Using Unpick, a tool developed by the Minecraft modding community, this process can be manually reversed. Unpick itself operates on Java bytecode, so it is not applicable to Android apps, but the file format for these "unpick definitions" is bytecode-independent and support for it could be integrated into JADX too. I'm bringing this up now since there's currently a discussion going on in its issue tracker regarding a potential v3 format, intended to be integrated natively into the Vineflower decompiler.

@skylot
Copy link
Owner

skylot commented Jan 18, 2025

Nice idea for a new jadx plugin!
Similar plugin for Android: jadx-android-linter-plugin developed by @nitram84

@Beast833
Copy link

Nice idea for a new jadx plugin!
Similar plugin for Android: jadx-android-linter-plugin developed by @nitram84

Give me cli command to use this but no gui

@nitram84
Copy link
Contributor

@Beast833
Android linter plugin works in cli mode and as a library with embedded jadx (cli, publish it to maven local and use it as dependency). For cli mode you just have to build the plugin and place it e.g in ~/.config/jadx/plugins/dropins/ folder. It will be active by default - no configuration or parameters needed. Gui is only needed for updating the linter rules. But you don't have to update the rules online to use the plugin. You can stay with the bundled rules or you can generate recent rules manually before building the plugin.

@NebelNidas
The plugin is not android specific, the rules are. There should be technically no problem to add an unpick v3 definition loader. The only additional requirement is a list of constant definitions with constant names and their values. If you decompile a jar file e.g. depending on LWJGL and LWJGL is not included (no fat jar), the ASM approach would not work in this case. You need to provide the constant values.

Adding an unpick definition loader to Android linter plugin should not break anything: I'm sure Android linter rules don't break Minecraft Java Edition and Minecraft Java Edition rules don't break Minecraft Bedrock Edition for Android.

Would it be possible to distribute the unpick v3 definitions and the loader as a library? This way the unpick support library and definitions could be used as a dependency in Android linter plugin. You just have to load unpick definitions into Android linter plugin and it should work.

Bonus: If LWJGL definitions would be completely separated from Minecraft definitions, Android linter plugin could also be used to detect dependencies to LWJGL. LWJGL and JDK definitions are reusable for other Java based programs than Minecraft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants