Speed up compilation unit export and fix related CU range matching#360
Open
Raincarnator wants to merge 3 commits into
Open
Speed up compilation unit export and fix related CU range matching#360Raincarnator wants to merge 3 commits into
Raincarnator wants to merge 3 commits into
Conversation
Author
|
Note: this PR includes one export-time optimization commit from #359 , because this branch is based on that work. Please review #359 first, or only consider the last two commits in this PR. @joxeankoret |
Owner
|
Thank you very much! It will take me a while to review it, but looks robust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR improves compilation unit handling in two places:
Changes
Speed up compilation unit export
The exporter previously matched functions to LFA compilation-unit ranges by repeatedly scanning all cached functions for each module. On large databases this becomes very expensive, e.g. thousands of modules times hundreds of thousands of functions.
This PR builds sorted function-address arrays and uses binary search to find the functions inside each module range. It also batches the
compilation_unit_functionsandsource_fileupdates withexecutemany().The source-string-to-module lookup was also changed to use sorted LFA module ranges instead of linearly scanning every module for each source-string function.
This keeps the exported compilation unit data equivalent, but avoids the large nested scans.
Fix related compilation unit range matching
find_related_compilation_unit()selected bothstart_eaandend_ea, but assigned the end variables fromstart_ea:That made the later
between start and endquery only cover the start address, so the heuristic was effectively restricted to a single address instead of the compilation unit range.This PR changes those assignments to use
end_ea, matching the selected columns and the intended range-based heuristic.Verification
python -m py_compile diaphora.py diaphora_ida.py.