-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet ready.py
More file actions
41 lines (38 loc) · 1.02 KB
/
Get ready.py
File metadata and controls
41 lines (38 loc) · 1.02 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
import os
import sys
import re
out = False
if len(sys.argv) > 1:
out = True
if out:
print("Deleting old binary")
os.unlink("boot.bin")
if out:
print("generating new binary")
os.system("nasm boot.asm -o boot.bin")
with open("boot.bin", "rb") as boot:
bootdata = boot.read()
btf = 510 - len(bootdata)
if btf < 1:
sys.stdout.flush()
os.system("cls")
print("Your code is too big for the MBR, please make it smaller")
sys.stdout.flush()
exit(1)
bootdata += bytes([0x00] * btf)
bootdata += bytes([0x55, 0xAA])
with open("bootpatched.bin", "wb") as patch:
patch.write(bootdata)
bootbytes = []
for data in bootdata:
bootbytes.append(data)
bootstr = f"{bootbytes}".replace("[", "{").replace("]", "}")
c_code = f"""unsigned char bootBytes[512] = {bootstr};"""
with open("main.c") as c_file:
c_contents = c_file.read()
with open("main.c", "w") as write_file:
write_file.write(
re.sub(
r"unsigned char bootBytes\[512] = \{.*?};", c_code, c_contents, 1, re.DOTALL
)
)