Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor data relocation diffing to improve accuracy and fix bugs #157

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

LagoLunatic
Copy link
Contributor

This rewrites how data relocation diffs are performed to be less hacky and more accurate.

The way it was originally implemented in #154 was to first perform a diff on the raw bytes of each side as normal, then diff the relocations, and then attempt to modify the diff of bytes after the fact to slice the diffs up and keep track of changed relocations in there.
This appeared to work when the bytes containing the relocations were unchanged and the same length on both sides.
But when the bytes themselves also changed (e.g. because dtk detected bytes that look like a pointer as being a relocation) it becomes practically impossible to modify the diff of bytes in a way that makes sense, which would result in the GUI code displaying the data as incorrectly shifted around, and scrolling to the bottom of the section would result in an index out of bounds error in some cases.
Furthermore, even when the bytes were the same, there were some other edge cases where the relocations could be displayed at the wrong offsets within the section.

The new way it's implemented in this PR simplifies how objdiff-core keeps track of relocation diffs: it now has a second list of diffs specifically for relocations, and the original list of diffs of bytes is reverted to how it worked in objdiff 2.6.0, without relocation data in it.
Instead, the GUI code now looks at both the list of byte diffs and the list of relocation diffs and merges them together per-row, and then displays each byte within a diff with its own color so that the bytes that contain a relocation can be colored differently from other bytes in the same diff.
The diffs no longer seem to get shifted around or cause errors.

image

I also made the hover tooltip show the source address of data relocations so that it's easier to tell exactly where they originate from (because multiple relocs can appear on one line, and the address objdiff shows in the left gutter isn't accurate anyway).

Comment on lines 44 to +45
let data = section_diff.data_diff.iter().map(|d| DataDiff::new(obj, d)).collect();
// TODO: section_diff.reloc_diff
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't entirely sure what this section of the code does, but I think it's something for objdiff-cli, and I don't think that can diff data sections anyway? So I don't think leaving data relocation diffs unimplemented here would have any effect, but I might be wrong.

Copy link
Owner

Choose a reason for hiding this comment

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

Correct, I’ll be adding this for CLI and VS Code extension eventually.

@encounter
Copy link
Owner

Thank you!

@encounter encounter merged commit b7730b3 into encounter:main Jan 22, 2025
18 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants