|
23 | 23 | This script analyzes MZ-PE (MS-DOS) executable file. |
24 | 24 | """ |
25 | 25 |
|
26 | | -__version__ = "1.0.0" |
| 26 | +__version__ = "1.0.1" |
27 | 27 | __author__ = "Maurice Lambert" |
28 | 28 | __author_email__ = "mauricelambert434@gmail.com" |
29 | 29 | __maintainer__ = "Maurice Lambert" |
|
47 | 47 |
|
48 | 48 | from sys import argv, stderr, stdin, exit, executable |
49 | 49 | from string import printable as printable_ |
| 50 | +from os.path import basename, isfile |
50 | 51 | from urllib.request import urlopen |
| 52 | +from dataclasses import dataclass |
51 | 53 | from shutil import copyfileobj |
52 | | -from os.path import basename |
53 | 54 | from binascii import hexlify |
54 | 55 | from os.path import getsize |
55 | 56 | from random import randint |
|
58 | 59 | from time import ctime |
59 | 60 | from os import name |
60 | 61 |
|
| 62 | +@dataclass |
| 63 | +class Section: |
| 64 | + label: str |
| 65 | + start_position: int |
| 66 | + size: int |
| 67 | + |
61 | 68 | try: |
62 | 69 | from EntropyAnalysis import charts_chunks_file_entropy, Section |
63 | 70 | from matplotlib import pyplot |
@@ -1173,13 +1180,14 @@ class SYSTEMTIME(Structure): |
1173 | 1180 | if calcul_checksum == checksum_value |
1174 | 1181 | else "Invalid checksum", |
1175 | 1182 | ) |
1176 | | - with open("rich_ids.txt", "wb") as rich_headers: |
1177 | | - copyfileobj( |
1178 | | - urlopen( |
1179 | | - "https://raw.githubusercontent.com/dishather/richprint/master/comp_id.txt" |
1180 | | - ), |
1181 | | - rich_headers, |
1182 | | - ) |
| 1183 | + if not isfile("rich_ids.txt"): |
| 1184 | + with open("rich_ids.txt", "wb") as rich_headers: |
| 1185 | + copyfileobj( |
| 1186 | + urlopen( |
| 1187 | + "https://raw.githubusercontent.com/dishather/richprint/master/comp_id.txt" |
| 1188 | + ), |
| 1189 | + rich_headers, |
| 1190 | + ) |
1183 | 1191 | with open("rich_ids.txt") as rich_headers: |
1184 | 1192 | for id_, value in sorted(ids.items(), key=lambda x: x[1]): |
1185 | 1193 | for line in rich_headers: |
@@ -3831,14 +3839,17 @@ def read_StringFileInfo(): |
3831 | 3839 | def read_resources_headers(main=False): |
3832 | 3840 | global position, last_object |
3833 | 3841 | data = file.read(4) |
3834 | | - vprint( |
| 3842 | + time_ = file.read(4) |
| 3843 | + if any(time_): |
| 3844 | + return |
| 3845 | + print( |
3835 | 3846 | "Characteristics".ljust(25), |
3836 | 3847 | f"{position:0>8x}-{position+4:0>8x}".ljust(20), |
3837 | 3848 | hexlify(data).decode().ljust(40), |
3838 | 3849 | "".join(chr(x) if x in printable else "." for x in data).ljust(20), |
3839 | 3850 | int.from_bytes(data, "little"), |
3840 | 3851 | ) |
3841 | | - data = file.read(4) |
| 3852 | + data = time_ |
3842 | 3853 | print( |
3843 | 3854 | "Timestamp".ljust(25), |
3844 | 3855 | f"{position+4:0>8x}-{position+8:0>8x}".ljust(20), |
@@ -4265,11 +4276,13 @@ def read_resources_headers(main=False): |
4265 | 4276 |
|
4266 | 4277 | overlay_position = max([x.start_position + x.size for x in sections]) |
4267 | 4278 | file.seek(overlay_position) |
4268 | | - try: |
4269 | | - with open("overlay_" + basename(argv[1]), "wb") as overlay: |
4270 | | - copyfileobj(file, overlay) |
4271 | | - except PermissionError: |
4272 | | - print("Permission Denied to extract overlay.", file=stderr) |
| 4279 | + if file.read(1): |
| 4280 | + file.seek(overlay_position) |
| 4281 | + try: |
| 4282 | + with open("overlay_" + basename(argv[1]), "wb") as overlay: |
| 4283 | + copyfileobj(file, overlay) |
| 4284 | + except PermissionError: |
| 4285 | + print("Permission Denied to extract overlay.", file=stderr) |
4273 | 4286 | if entropy_charts_import: |
4274 | 4287 | axes = pyplot.gca() |
4275 | 4288 | axes.invert_yaxis() |
|
0 commit comments