-
Notifications
You must be signed in to change notification settings - Fork 1
Fix parameter annotation ordering in both DEX and Smali parsers #188
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
Conversation
…already in correct order Co-authored-by: futpib <4330357+futpib@users.noreply.github.com>
|
@copilot this test fails |
…ffers from DEX Co-authored-by: futpib <4330357+futpib@users.noreply.github.com>
You're right - I've reverted the changes in commit e0e1e4a. My original assumption that baksmali outputs methods in the same order as the DEX annotations directory was incorrect. Baksmali uses its own method ordering which can differ from the DEX file's annotation order. The |
|
@copilot undo you undo, make sure both our dex and smali parsers output annotations in correct order |
…rect order Co-authored-by: futpib <4330357+futpib@users.noreply.github.com>
Fixed in commit 4246184. Both parsers now output parameter annotations sorted by method index in the class's method list (directMethods + virtualMethods). Removed |
Pull Request Test Coverage Report for Build 19378316675Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Removed the
sortParameterAnnotationsfunction from tests and fixed both the DEX and Smali parsers to output parameter annotations in the correct order.Investigation Findings
Original Hypothesis (incorrect):
annotationsDirectoryItem.parameterAnnotationsActual Behavior:
Baksmali generates smali files with methods in its own ordering, which differs from the order in the DEX file's annotations directory. Additionally, DEX files may not always have parameter annotations in strictly sorted order.
Example from
android/os/LocaleListbefore fix:<init>,equals,forLanguageTags<init>,forLanguageTags,equalsRoot Cause
Neither parser was enforcing consistent ordering of parameter annotations. The correct order according to the DEX file format specification is: parameter annotations sorted by method index in the class's method list (directMethods + virtualMethods).
Solution
Fixed both parsers to ensure parameter annotations are always sorted by method index:
Smali Parser (
src/smaliParser.ts):directMethods + virtualMethodsarrayDEX Parser (
src/dalvikExecutableParser.ts):Test File (
src/dalvikExecutableParserAgainstSmaliParser.test.ts):sortParameterAnnotationsfunction (no longer needed)Result
Both parsers now output parameter annotations in consistent order:
directMethods + virtualMethodsExample from
android/os/LocaleListafter fix (both parsers):<init>(index 1),forLanguageTags(index 2),equals(index 4)Note:
sortFieldAnnotationsis retained as field annotations still require ordering normalization.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.