Repository navigation
Expand file tree
/
Copy pathextractor.py
More file actions
73 lines (56 loc) · 1.79 KB
/
Copy pathextractor.py
File metadata and controls
73 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
NODE_SEA_BLOB extractor for Binary Ninja.
Supports Mach-O (__NODE_SEA_BLOB section) and PE (NODE_SEA_BLOB section).
"""
SEA_MAGIC = bytes([0x20, 0xDA, 0x43, 0x01])
JS_OFFSET = 0x31
FILENAME_OFFSET = 0x10
class SEAExtractionError(Exception):
pass
class SEABlob:
def __init__(self, magic, version, filename, js_code, raw_blob):
self.magic = magic
self.version = version
self.filename = filename
self.js_code = js_code
self.raw_blob = raw_blob
self.size = len(raw_blob)
def find_sea_section(bv):
"""
Looks for NODE_SEA_BLOB in Mach-O or PE.
Returns the section object or None.
"""
section = bv.get_section_by_name("__NODE_SEA_BLOB")
if section:
return section
section = bv.get_section_by_name("NODE_SEA_BLOB")
if section:
return section
return None
def extract(bv):
"""
Main extraction function.
Returns a SEABlob object or raises SEAExtractionError.
"""
section = find_sea_section(bv)
if section is None:
raise SEAExtractionError("No NODE_SEA_BLOB section found in this binary.")
blob = bv.read(section.start, section.length)
if not blob:
raise SEAExtractionError("Failed to read NODE_SEA_BLOB section.")
if blob[:4] != SEA_MAGIC:
raise SEAExtractionError(
f"Invalid magic number: {blob[:4].hex()} (expected {SEA_MAGIC.hex()})"
)
version = blob[4]
filename_raw = blob[FILENAME_OFFSET:JS_OFFSET]
filename = filename_raw.split(b"\x00")[0].decode("utf-8", errors="replace")
js_bytes = blob[JS_OFFSET:]
js_code = js_bytes.decode("utf-8", errors="replace")
return SEABlob(
magic=blob[:4].hex(),
version=version,
filename=filename,
js_code=js_code,
raw_blob=blob,
)