[high] fix(binary): request JSON from capa and FLOSS with the flag they define - #116
Draft
elhoim wants to merge 1 commit into
Draft
[high] fix(binary): request JSON from capa and FLOSS with the flag they define#116elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
Both wrappers passed "--format json". In capa 9.4.0 and FLOSS 3.1.0 alike, -f/--format selects the tool's *input* format -- capa accepts auto|pe|dotnet| elf|sc32|sc64|cape|drakvuf|vmray|freeze|binexport2|binja_database and FLOSS accepts auto|pe|sc32|sc64 -- while JSON output is -j/--json. "json" is not a valid choice for either, so argparse rejected the command line before the sample was opened: capa exited 2 and FLOSS exited 255. Every run_capa and run_floss call failed. FLOSS had a second defect on the same command line. --only and --no are both nargs="+" with choices, so the bare "--only" emitted when include_static is False consumed the positional sample path as one of its values and failed with "invalid choice: 'sample.bin'". Skipping static extraction is "--no static", and the sample has to precede any list-valued flag. Verified against the pinned release binaries: capa 9.4.0 and floss v3.1.0-0-gdb9af41, downloaded from the URLs in assets/manifest.py. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
BLUF
run_capaandrun_flossnever work. Both pass--format json, which neither tool accepts, so argparse rejects the command line before the sample is opened.-f/--formatselects the input format; JSON output is-j/--json. Verified against the pinned releases: capa exits 2, FLOSS exits 255.--onlyemitted wheninclude_static=Falseisnargs="+"withchoices, so it swallows the sample path —invalid choice: 'sample.bin'.--jsonfor both; use--no staticinstead of a bare--only; move the positional sample ahead of any list-valued flag.src/mulder/server/tools/binary.py, the twocmdlists only. No shared helper, no new abstraction, nothing else in the module.The bug
Run against the pinned binaries (
capa 9.4.0,floss v3.1.0-0-gdb9af41, fetched from the URLs inassets/manifest.py):And with the format flag corrected, the bare
--onlystill eats the sample:The fix
With the corrected argv,
capa --json --quiet sample.binexits 0, and FLOSS gets past argparse intoINFO: floss: extracting static strings— the line that only appears once argument parsing has succeeded.Why capa and FLOSS are one PR, not two
One root cause, one module, one mechanical correction: both are FLARE tools whose
--formatis an input-format selector, and both were givenjsonas if it were an output format. Splitting this into two near-identical two-line PRs would obscure that they are the same mistake, and the FLOSS half cannot be verified without establishing the same grammar fact for capa. The--only/--nocorrection is part of building a FLOSS command line that parses at all, so it belongs in the same change.Deliberately out of scope
_parse_floss_outputreads keys FLOSS does not emit — that is a separate defect with its own PR, recovered from closed [high] fix(binary): read the keys the wrapped tools actually emit #80.run_detect_it_easyalready uses--jsoncorrectly and is untouched.Verification
uvx pre-commit run --all-files(new test staged first, so the hooks actually see it) → ruff, ruff-format, mypy all pass.uv run --locked --extra dev pytest tests/ -q→ 863 passed, nothing deselected, nothing skipped.binary.pyrestored toorigin/mainand the new tests kept, 6 of 8 fail:The two that pass on both trees are the narrowness guards — the sample is still passed exactly once, and
--minimum-lengthis unchanged — so they pin the fix rather than the bug. The tests assert on the argv actually built and check it against the realchoicestuples from each pinned release, so they cannot pass against a codebase where the bug never existed.Context
Recovered from closed PR #69 (
fix/tool-cli-invocations), which changed every wrapped tool at once. Only thebinary.pyportion is here; the chainsaw/hayabusa/zircolite parts of that branch are separate tools and are not included. The rejected outcome framework and itsclassify_tool_exithelper are not reintroduced — this PR adds no status taxonomy and no shared abstraction. Per the review on #32:Branched fresh from current
main(2e5432c); the closed branch was not revised in place.🤖 Generated with Claude Code