Skip to content

Commit a52229e

Browse files
committed
Add documentation for reconstruct_all_subresponses
1 parent c74c323 commit a52229e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- `Stoq.reconstruct_all_subresponses()` method to allow for reconstructing `StoqResponse` objects iteratively (@maydewd)
13+
1014
### Changed
1115

1216
- Force payload content to be of type bytes

docs/_static/reconstruct-results.png

13 KB
Loading

stoq/core.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,25 @@
267267
>>> results = s.scan_payload(payload)
268268
>>> results.split()
269269
270+
Reconstructing Subresponse Results
271+
----------------------------------
272+
273+
stoQ can produce complex results depending on the recursion depth and extracted payload objects.
274+
In order to help handle complex results and limit redundant processing of payloads when using
275+
stoQ as a framework, a method exists that will allow for iterating over each result as if it
276+
were the original root object. This is especially useful when handling compressed archives, such
277+
as `zip` or `apk` files that may have multiple levels of archived content. Additionally, the
278+
defined decorators will be run against each newly constructed `StoqResponse` and added to the
279+
results.
280+
281+
>>> for result in s.reconstruct_all_subresponses(results):
282+
... print(result)
283+
284+
Below is a simple flow diagram of the iterated results when being reconstructed.
285+
286+
.. image:: /_static/reconstruct-results.png
287+
288+
270289
.. _multiplugindir:
271290
272291
Multiple Plugin directories
@@ -286,7 +305,6 @@
286305
"""
287306

288307
import os
289-
import json
290308
import queue
291309
import logging
292310
import configparser
@@ -837,7 +855,9 @@ def _apply_decorators(self, response: StoqResponse) -> None:
837855
if decorator_response.errors:
838856
response.errors[plugin_name].extend(decorator_response.errors)
839857

840-
def reconstruct_all_subresponses(self, stoq_response: StoqResponse) -> Iterable[StoqResponse]:
858+
def reconstruct_all_subresponses(
859+
self, stoq_response: StoqResponse
860+
) -> Iterable[StoqResponse]:
841861
for i, new_root_result in enumerate(stoq_response.results):
842862
parent_payload_ids = {stoq_response.results[i].payload_id}
843863
relevant_results: List[PayloadResults] = [new_root_result]
@@ -850,7 +870,7 @@ def reconstruct_all_subresponses(self, stoq_response: StoqResponse) -> Iterable[
850870
request_meta=stoq_response.request_meta,
851871
errors=stoq_response.errors,
852872
time=stoq_response.time,
853-
scan_id=stoq_response.scan_id
873+
scan_id=stoq_response.scan_id,
854874
)
855875
self._apply_decorators(new_response)
856876
yield new_response

0 commit comments

Comments
 (0)