-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbytecode_dumper.py
More file actions
54 lines (43 loc) · 1.66 KB
/
bytecode_dumper.py
File metadata and controls
54 lines (43 loc) · 1.66 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
import re
import os
import magic
source_file = "fonts.h"
try:
with open(source_file, "r") as f:
content = f.read()
matches = re.findall(r"unsigned char (\w+)\[[^\]]+\] = \{([^\}]+)\};", content, re.DOTALL)
if not matches:
print("Aucun tableau 'unsigned char' trouvé.")
exit()
for name, data in matches:
byte_values = re.findall(r"0x[0-9A-Fa-f]{2}", data)
byte_values = [int(b, 16) for b in byte_values]
temp_file = f"{name}.bin"
with open(temp_file, "wb") as f:
f.write(bytearray(byte_values))
file_type = magic.Magic(mime=True).from_file(temp_file)
if "image/png" in file_type:
extension = ".png"
elif "image/jpeg" in file_type:
extension = ".jpg"
elif "image/vnd.microsoft.icon" in file_type:
extension = ".ico"
elif "application/x-dosexec" in file_type:
extension = ".exe"
elif "application/octet-stream" in file_type and name.lower().endswith(".sys"):
extension = ".sys"
elif "font" in file_type:
extension = ".ttf"
elif "application/pdf" in file_type:
extension = ".pdf"
elif "text/plain" in file_type:
extension = ".txt"
elif "application/zip" in file_type:
extension = ".zip"
else:
extension = ".bin"
output_file = f"{name}{extension}"
os.rename(temp_file, output_file)
print(f"Fichier créé : {output_file} ({len(byte_values)} octets, type : {file_type})")
except Exception as e:
print(f"Erreur : {e}")