Update smali debug .line info from JADX output for better debugging #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When debugging decompiled source there are challenges and various annoyances due to discrepancies between the line numbers in the "debug_info_item" structures of the Dex files and those in the decompiled source code. This discrepancy arises because the process of decompilation usually does not produce an accurate representation of the original source code. These inconsistencies can make it difficult to map the source code to the bytecode, leading to misleading breakpoints, inaccurate step-by-step execution, and confusion in interpreting variable values and exception handling.
This PR adds a feature where the .line debug information in the smali files is updated to match the lines of JADX decompiled source code, making it easier to trace the execution flow of the application and understand its behavior. This significantly improves the debugging process when working with APKs where the original source code is not available.
This is enabled by the JADX '--add-debug-lines' flag which includes original source line information from the dex as comments in the decompiled code. This extension will parse these debug sourcelinie comments, map them to the line they appear in the decompiled source file, and apply these mappings by updatingthe associated smali files.
The core function of the fork is implemented in the updateSmaliDebugLines function, which is triggered from the context menu when right-clicking the apktool.yml file. The function starts by determining the project directory and the java decompiled sources directory. If the java source directory does not exist, the task aborts. Otherwise, the function proceeds to back up the original smali files, collect all source and smali files, and create mappings between them based on the line comments in the decompiled code from JADX. Finally, it iterates through the mappings and updates the smali file line information according to the JADX decompiled source code.