Fold the duplicated per-browser promotion loop into a helper - #352
Open
dchaudhari7177 wants to merge 1 commit into
Open
Fold the duplicated per-browser promotion loop into a helper#352dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
The Chrome and Firefox branches of run() carried near-verbatim copies of
the same parsed_artifacts/parsed_storage/version/preferences folding, the
same session_structure promotion, and the same {presentation, data}
promotion loop.
The drift that predicts had already happened: session_structure promotion
existed only in the Chrome branch, so when Firefox started producing one
it rendered nothing until the same seven lines were copied across.
absorb_browser_analysis() folds the collections by attribute name rather
than by branching on the browser, so Chrome's parsed_extension_data and
parsed_sync_data need no special case and a browser that grows a
collection later needs no edit here.
installed_extensions stays in the Chrome branch. It is the one thing in
the two branches that is a genuine difference rather than duplication,
and moving it is not behaviour-preserving: Firefox does produce an
installed_extensions block, it is simply never promoted, and promoting it
emits a Firefox profile's add-ons as "Chrome Extensions" with data_type
chrome:extension:installed. That is worth fixing, but it is a different
change from removing this duplication.
Output is byte-identical on the test fixtures, 377 records before and
after.
Closes RyanDFIR#335
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.
Closes #335.
absorb_browser_analysis()takes abrowser_analysisand folds the common collections plus the promotion loop, and both branches ofrun()become one line each.The collections are folded by attribute name rather than by branching on the browser, as the issue asks:
Chrome's
parsed_extension_dataandparsed_sync_datatherefore need no special case, and Firefox growing one later needs no edit here.On the
installed_extensionsdecisionThe issue asks whether that block stays outside the helper. It stays outside, and the reason turned out to be stronger than "it is different": moving it in is not behaviour-preserving.
I moved it in first and diffed the output. It produced one extra record:
So Firefox does produce an
installed_extensionsblock. It is parsed and then dropped, for exactly the same reasonsession_structureused to be — the promotion lives only in the Chrome branch. But promoting it as-is sends a Firefox profile's add-ons through the Chrome shape, and they come out labelledChrome Extensionswithdata_typechrome:extension:installed, which is wrong for a Firefox profile.That is a real finding and probably its own issue, but it is a behaviour change, and this issue is about removing duplication. Rather than smuggle it in, the block stays in the Chrome branch with a comment, and the helper's docstring records what is waiting there. Happy to open a separate issue for the Firefox side, or to fold it in here with the labelling fixed if you would rather have it in one go.
Two small notes on faithfulness
session_structurecheck stayshasattr, not a truthiness test.getattr(..., None) is not Nonewould quietly change what an empty-but-present structure does, and this is the promotion that had already gone missing once.browser_analysis.__dict__.items()instead of indexing__dict__[item]three times. Same values, same order, same broadexcept— I did not narrow it, since a promotion failure is deliberately non-fatal here.Verification
Output equivalence, which is the thing that actually matters for a refactor. Same fixtures, JSONL, before and after:
The 120-line diff is 69 insertions / 51 deletions, most of which is the helper's docstring explaining the
installed_extensionsdecision.