Skip to content

Commit ebe084b

Browse files
jcrussellqkaiser
authored andcommitted
feat(handler): fix size of NSIS installers
Compute the size of NSIS installers properly so that the padding gets removed from nsis-3.11-setup.exe.padded.
1 parent 4373107 commit ebe084b

File tree

1 file changed

+20
-0
lines changed
  • python/unblob/handlers/executable

1 file changed

+20
-0
lines changed

python/unblob/handlers/executable/pe.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import struct
23
from pathlib import Path
34
from typing import Optional
45

@@ -98,6 +99,25 @@ def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]
9899
if not binary:
99100
return None
100101

102+
# Check to see if we can extract the size of the full NSIS Installer by
103+
# including the archive size from the NSIS header.
104+
if binary.overlay:
105+
overlay = bytes(binary.overlay)
106+
107+
magic_offset = overlay.find(b'NullsoftInst')
108+
if magic_offset != -1:
109+
header_start = magic_offset - 8
110+
if header_start < 0:
111+
# Malformed NSIS header?
112+
return None
113+
114+
_, _, _, _, archive_size = struct.unpack('II12sII', overlay[header_start:header_start + 28])
115+
116+
return ValidChunk(
117+
start_offset=start_offset,
118+
end_offset=start_offset + binary.overlay_offset + archive_size,
119+
)
120+
101121
return ValidChunk(
102122
start_offset=start_offset,
103123
end_offset=start_offset + binary.original_size,

0 commit comments

Comments
 (0)