Skip to content

Commit e52edf4

Browse files
committed
fix(handlers): improve squashfs extraction by providing endianness explicitly.
Sasquatch does not switch to the other endianness when the current endianness is not valid on some specific sample from Netgear such as https://www.downloads.netgear.com/files/GDC/WNR3500Lv2/WNR3500Lv2-V1.2.0.40_40.0.80.zip Improved by creating a custom Extractor that is just a wrapper around Command that detects the file endianness and provides either '-le' or '-be' endianness options to sasquatch.
1 parent e7e8ff4 commit e52edf4

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

unblob/handlers/filesystem/squashfs.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,43 @@
1414
PAD_SIZES = [4_096, 1_024]
1515

1616

17+
class SquashFSExtractor(Extractor):
18+
EXECUTABLE = "sasquatch"
19+
20+
def __init__(self, big_endian_magic: int):
21+
self.big_endian_magic = big_endian_magic
22+
23+
def extract(self, inpath: Path, outdir: Path):
24+
with File.from_path(inpath) as file:
25+
endian = get_endian(file, self.big_endian_magic)
26+
27+
commands_args = []
28+
29+
if endian == Endian.BIG:
30+
commands_args.append("-be")
31+
else:
32+
commands_args.append("-le")
33+
34+
commands_args.extend(
35+
[
36+
"-no-exit-code",
37+
"-f",
38+
"-d",
39+
"{outdir}",
40+
"{inpath}",
41+
]
42+
)
43+
extractor = Command(self.EXECUTABLE, *commands_args)
44+
extractor.extract(inpath, outdir)
45+
46+
def get_dependencies(self) -> List[str]:
47+
return [self.EXECUTABLE]
48+
49+
1750
class _SquashFSBase(StructHandler):
1851
BIG_ENDIAN_MAGIC = 0x73_71_73_68
1952

20-
EXTRACTOR = Command(
21-
"sasquatch", "-no-exit-code", "-f", "-d", "{outdir}", "{inpath}"
22-
)
53+
EXTRACTOR = SquashFSExtractor(0x73_71_73_68)
2354

2455
def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]:
2556
file.seek(start_offset)
@@ -145,6 +176,8 @@ class SquashFSv3DDWRTHandler(SquashFSv3Handler):
145176

146177
BIG_ENDIAN_MAGIC = 0x74_71_73_68
147178

179+
EXTRACTOR = SquashFSExtractor(0x74_71_73_68)
180+
148181
PATTERNS = [
149182
HexString(
150183
"""
@@ -170,6 +203,8 @@ class SquashFSv3BroadcomHandler(SquashFSv3Handler):
170203

171204
BIG_ENDIAN_MAGIC = 0x71_73_68_73
172205

206+
EXTRACTOR = SquashFSExtractor(0x71_73_68_73)
207+
173208
PATTERNS = [
174209
HexString(
175210
"""
@@ -196,6 +231,8 @@ class SquashFSv3NSHandler(SquashFSv3Handler):
196231

197232
BIG_ENDIAN_MAGIC = 0x73_71_6C_7A
198233

234+
EXTRACTOR = SquashFSExtractor(0x73_71_6C_7A)
235+
199236
PATTERNS = [
200237
HexString(
201238
"""

0 commit comments

Comments
 (0)