Skip to content

binwalk.py

ofrak_components.binwalk

BinwalkAnalyzer (Analyzer)

analyze(self, resource, config=None) async

Analyze a resource for to extract specific ResourceAttributes.

Users should not call this method directly; rather, they should run Resource.run or Resource.analyze.

Parameters:

Name Type Description Default
resource Resource

The resource that is being analyzed

required
config

Optional config for analyzing. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

None

Returns:

Type Description
BinwalkAttributes

The analysis results

Source code in ofrak_components/binwalk.py
async def analyze(self, resource: Resource, config=None) -> BinwalkAttributes:
    with tempfile.NamedTemporaryFile() as temp_file:
        data = await resource.get_data()
        temp_file.write(data)
        temp_file.flush()

        # Should errors be handled the way they are in the `DataSummaryAnalyzer`? Likely to be
        # overkill here.
        offsets = await asyncio.get_running_loop().run_in_executor(
            self.pool, _run_binwalk_on_file, temp_file.name
        )
    return BinwalkAttributes(offsets)

BinwalkAttributes (ResourceAttributes) dataclass

BinwalkAttributes(offsets: Dict[int, str])