267
267
>>> results = s.scan_payload(payload)
268
268
>>> results.split()
269
269
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
+
270
289
.. _multiplugindir:
271
290
272
291
Multiple Plugin directories
286
305
"""
287
306
288
307
import os
289
- import json
290
308
import queue
291
309
import logging
292
310
import configparser
@@ -837,7 +855,9 @@ def _apply_decorators(self, response: StoqResponse) -> None:
837
855
if decorator_response .errors :
838
856
response .errors [plugin_name ].extend (decorator_response .errors )
839
857
840
- def reconstruct_all_subresponses (self , stoq_response : StoqResponse ) -> Iterable [StoqResponse ]:
858
+ def reconstruct_all_subresponses (
859
+ self , stoq_response : StoqResponse
860
+ ) -> Iterable [StoqResponse ]:
841
861
for i , new_root_result in enumerate (stoq_response .results ):
842
862
parent_payload_ids = {stoq_response .results [i ].payload_id }
843
863
relevant_results : List [PayloadResults ] = [new_root_result ]
@@ -850,7 +870,7 @@ def reconstruct_all_subresponses(self, stoq_response: StoqResponse) -> Iterable[
850
870
request_meta = stoq_response .request_meta ,
851
871
errors = stoq_response .errors ,
852
872
time = stoq_response .time ,
853
- scan_id = stoq_response .scan_id
873
+ scan_id = stoq_response .scan_id ,
854
874
)
855
875
self ._apply_decorators (new_response )
856
876
yield new_response
0 commit comments