Skip to content

Commit 93afd1c

Browse files
martonillesqkaiser
authored andcommitted
fix(yaffs): simplified storing collected data chunks and entries
1 parent 9cd1c8a commit 93afd1c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

unblob/handlers/filesystem/yaffs.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io
22
import itertools
33
import os
4+
from collections import defaultdict
45
from enum import IntEnum
56
from pathlib import Path
67
from typing import Iterable, List, Optional, Tuple
@@ -274,7 +275,7 @@ class YAFFSParser:
274275

275276
def __init__(self, file: File, config: Optional[YAFFSConfig] = None):
276277
self.file_entries = Tree()
277-
self.data_chunks = {}
278+
self.data_chunks = defaultdict(list)
278279
self.file = file
279280
self._struct_parser = StructParser(C_DEFINITIONS)
280281
self.end_offset = -1
@@ -322,14 +323,9 @@ def parse(self, store: bool = False): # noqa: C901,FBT001,FBT002
322323
if not is_valid_header(header):
323324
break
324325

325-
if not store:
326-
continue
327-
self.insert_entry(self.build_entry(header, data_chunk))
328-
else:
329-
if not store:
330-
continue
331-
if data_chunk.object_id not in self.data_chunks:
332-
self.data_chunks[data_chunk.object_id] = []
326+
if store:
327+
self.insert_entry(self.build_entry(header, data_chunk))
328+
elif store:
333329
self.data_chunks[data_chunk.object_id].append(data_chunk)
334330
self.end_offset = self.file.tell()
335331

0 commit comments

Comments
 (0)