Open AndrewFasano opened 5 months ago
We'll have a look at it this week. Thanks for bringing this up, it's a good opportunity to improve our documentation.
- Am I missing a much easier way to do this with the API ?
Issue is on us, not you. part0
has chunk id 14692:1
but it does not show up in the JSON report structure because it's made of two different chunks with chunk ids 14693:1
and 14693:2
. The report is therefore missing a TaskResult
holding a task with path /tmp/out/FW_RT_N66U_C1_300438510000.zip_extract/Firmware_Release/RT-N66U_C1_3.0.0.4_385_10000-gd8ccd3c.trx_extract/part0_extract
. Since it's not there, it's not in known_tasks
and your package()
function is blind.
This issue is documented at https://github.com/onekey-sec/unblob/issues/554, I'll see if we can prioritize it.
On another note, one improvement you can make is to use the HashReport
returned by unblob to get the file SHA1 instead of recomputing it. unblob computes MD5, SHA1, and SHA256 of processed files.
Something along those lines. I leave the hash_report usage to you.
--- extractor.py 2024-06-17 09:10:51.035069581 +0200
+++ extractor.py 2024-06-17 08:57:03.218147812 +0200
@@ -8,6 +8,7 @@
from pathlib import Path
from typing import Dict, List
from unblob.processing import ExtractionConfig, process_file
+from unblob.report import HashReport
from unblob.logging import configure_logger
from unblob import report
@@ -40,7 +41,7 @@
for task_result in unblob_results.results:
task_file = task_result.task.path
task_id = task_result.task.blob_id
-
+ hash_report = [report for report in task_result.reports if isinstance(report, HashReport)]
for subtask in task_result.subtasks:
if subtask.blob_id not in known_tasks:
# XXX: We'll see the same subtask.blob_id for each time we extract more data from a blob. E.g., we could have
- Are blob_id values supposed to be unique per blob? It seems like the same blob_id will show up with distinct paths for example if a blob is carved into 2 files, both the base blob and the 2 generated files will have the same blob_id. Am I just misunderstanding this interface ?
You can think of blob_id
as a kind of parent_id
, indicating to which blob a chunk belongs to. You can use the id
field from ChunkReport
to have a unique identifier for files that are extracted. With the file you're extracting, you get a ZIP file with chunk id 14688:1
that contains a trx file with id 14691:1
and blob_id 14688:1
. The trx file contains part0 holding two chunks with id 14693:1
and 14693:2
.
- Are there examples of API usage somewhere ?
Not at the moment. We have some auto-generated documentation at https://unblob.org/api/ but it's clearly insufficient.
Thanks so much! Really appreciate the guidance.
I'm trying to use the unblob API for what I think should be a fairly straightforward task but I'm having some difficulties and hoping to get some help. I haven't found many examples of API usage so I'm hoping this issue might also help other users get started with the API from the code I have and learn from my mistakes.
My goal here is to use unblob to do a recursive extraction of a blob but to produce a clean copy of each extraction without any sub-extractions (i.e., have no
_extract
files within any of my output directories). Instead I want each of the extractions to be stored one directory deep within an output directory (e.g., output/extraction1, output/extraction2). I've previously implemented something like this by just running unblob then parsing the generated outputs looking for files named*_extract
but I think it should be much cleaner to do this with the API.I've written the code below which successfully logs a lot of information about the extraction process and almost gets me what I want, but I find that extraction files sometimes still end up in my output so I suspect I'm doing something wrong or missing something obvious here.
I have 3 specific questions, but any advice or guidance would be much appreciated! Thanks
blob_id
values supposed to be unique per blob? It seems like the same blob_id will show up with distinct paths for example if a blob is carved into 2 files, both the base blob and the 2 generated files will have the same blob_id. Am I just misunderstanding this interface?Example usage after installing unblob dependencies, unblob itself, and saving the below script as extracator.py
In the generated output directory I see one of the extracted directories contains two
_extract
directoriesIt's almost right, but the
part0_extract
andpart1_extract
directories withinoutput/extracted/31c56af333e9f4652626f6e0e10418e27dd1af33.unblob
shouldn't be there!