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

Add Line Numbers to Dex Dump #19

Merged
merged 2 commits into from
May 2, 2024
Merged

Conversation

alonalbert
Copy link
Contributor

I rewrote the DexDump parsing into a dedicated class.

I changed the implementation to be (IMO) less brittle and more readable.

Copy link
Owner

@romainguy romainguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I left a couple of comments. A few more things:

  • There are now 2 empty lines between methods in the output instead of just 1. I remember I had to do something to deal with this in the original implementation as well.
  • There seems to be a bug with naming classes. For instance I got this in a dump: class IntOffset..ExternalSyntheticBackport0 (note the two dots)
  • Could you add a menu to turn debug line numbers on/off? It would make it more obvious to users what those numbers are, but more importantly it would make copy/pasting out of the tool easier when line numbers are disabled.
  • Your change breaks another feature: when clicking on a line with a jump (goto/if/etc.) in the DEX output, the tool will draw a line to show where the jump will go. If the target line has a debug line number in the output, the feature stops working (prob. because the regex I use assumes whitespace at the beginning; one of the reasons why I wanted to change the parsers to output a list of class/methods/instructions)

build.gradle.kts Outdated
implementation("org.jetbrains.compose.components:components-splitpane-desktop:${extra["compose.version"] as String}")
implementation("com.fifesoft:rsyntaxtextarea:${extra["rsyntaxtextarea.version"] as String}")
implementation("com.fifesoft:rstaui:${extra["rstaui.version"] as String}")
implementation("net.java.dev.jna:jna:${extra["jna.version"] as String}")
implementation("androidx.collection:collection:${extra["collections.version"] as String}")
implementation("org.jetbrains.androidx.lifecycle:lifecycle-runtime:${extra["lifecycle.version"] as String}")
runtimeOnly("org.jetbrains.skiko:skiko-awt-runtime-linux-x64:${extra["skiko.version"] as String}")
runtimeOnly("org.jetbrains.skiko:skiko-awt-runtime-macos-arm64:${extra["skiko.version"] as String}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks on macOS, the native library can't be found if it's not implementation() :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


private val PositionRegex = Regex("^\\s*0x(?<address>[0-9a-f]+) line=(?<line>\\d+)$")

private const val CLASS_START = "Class #"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been following the SnakeCase style for constants here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}
return classes
.filter { it.methods.isNotEmpty() }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine those two filters in a single one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

val code = buildString {
instructions.forEach {
val lineNumber = positions[it.address]
val prefix = when (lineNumber != null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an if/else here instead of when/true/false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, though as an aside, I really like using when-true-false in these cases because is more readable. At least IMO.

@alonalbert alonalbert force-pushed the class-parser branch 2 times, most recently from 0d0343f to 7d0370d Compare May 2, 2024 15:21
@romainguy
Copy link
Owner

Thanks for the updates! One last issue, there are still 2 empty lines between methods in the dump instead of 1.

@alonalbert alonalbert force-pushed the class-parser branch 2 times, most recently from 2c556be to 4f9ec31 Compare May 2, 2024 17:02
Copy link
Owner

@romainguy romainguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@romainguy romainguy merged commit 52ac2ba into romainguy:main May 2, 2024
1 check passed
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.

2 participants