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

Preserve names of parameters and locals in dex2jar #384

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

paulo-raca
Copy link
Contributor

@paulo-raca paulo-raca commented Jun 23, 2020

I'm using dex2jar + CFR to extract Java sources from Android 11's framework.jar (AFAICT they didn't release the Java sources for the betas yet -- Please prove me wrong)

Unfortunately, the source code doesn't preserve variable names and, most importantly, method parameter names.

But when examining the output of dex2smali, I noticed parameter names were there, show with the .param p#, "name" syntax.

This PR copies parameter and local variable names from debug section in into java bytecode, using both MethodVisitor.visitParameter (Which AFAICT translates into Java 8's MethodParameters attribute) and MethodVisitor.visitLocalVariable (Which translates into LocalVariableTable attribute).

Those are intended for debugging, but are also used by decompilers to assign names

However there are a few issues:

  • Argument names are unknown in interfaces -- Probably cannot be fixed if the information isn't there?
  • I don't know how to translate DexLabel into a Asm Label, therefore the entries in my LocalVariableTable have start=stop=0
  • Decompilers successfully decode parameter names, but local variable names are mixed up -- E.g., https://gist.github.com/paulo-raca/2551cc5da2ecc86877c6f0ccb6153970. Please help me mapping it properly
  • Code can probably be improved, please make suggestions :)

I would love to have this information, but variable names are not being assigned to the wrong variables in disassembled code,
so I'm probably assigning the wrong registers.

Missing info is better than wrong info, so I'm removing it for now.
@omeraydindev
Copy link
Contributor

@pxb1988 Any chance you could take a look at this? Being able to translate debug info properly would be a huge plus for dex2jar.

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

Successfully merging this pull request may close these issues.

None yet

2 participants