binja_frontend: Correctly get file hash for BNDBs #13
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.
We were previously hashing the BNDB itself if you saved a BNDB. Now, we cache the original hash in the database, and if it's not present, we hash the contents of the top-level BinaryView, which matches the contents of the original file (modulo any patches that have been applied).
We previously discussed the pseudocode of:
open(bv.file.original_filename).read()I'd think we should skip item 2), which is what this PR currently does. Logic is that if I've saved a DB I expect tooling to use the DB, rather than fishing around for files. But I can implement 2) if you want before merging, feel free to leave a PR comment to that effect :)
(We're already fishing around in the DB for cached metadata, so we're already in less-than-obvious-behavior territory, the question is what matches what the user means best.)
One other thing is that this PR now requires Python 3.7 (IIRC) to parse, as I'm using the walrus operator for readability. The earliest Binja release that supports Python3 supports 3.9, so that should be fine unless you're running some oddball Linux setup, of which I was probably the last ;)