Add script to extract the byte array of bootloader binary plus instructions

This commit is contained in:
Vega 2024-02-14 20:58:35 +00:00
parent ba8c94f9f2
commit 831333f9ae
Signed by: muteplayer
GPG Key ID: 31FE0B16CB1045E7
5 changed files with 202 additions and 2 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin/
bin/*.exe
res/resource.o
res/*.o
bootloader/*.bin

View File

@ -14,4 +14,4 @@ main: $(BIN)
clean:
@echo "Cleaning up..."
@rm -fr bin/* res/*.o
@rm -fr bin/* res/*.o bootloader/*.bin

7
bootloader/README.org Normal file
View File

@ -0,0 +1,7 @@
#+TITLE: Bootloader
This is the bootloader source code of Y2K. to build run ~nasm bootloader.asm -o bootloader.bin~
You can execute the ~python getHex.py bootloader.bin~ to get the formated bootloader bytes plus
the size of the generated array and put it in the bootloader contant in =src/payloads.h= alongside
with the printed size.

166
bootloader/bootloader.asm Normal file
View File

@ -0,0 +1,166 @@
[BITS 16] ; Bootloader file 16 bits
[ORG 0x7C00] ; Memory region that BIOS load the file
; Setup video segment 320x200 - 256 color
; Setup
cli
push 0x0A000
pop es
xor di, di
mov ax, 0x13
int 0x10
; The code realy starts here
mov cx, 0x15
call sleep
mov si, str1
mov dl, 0x0c
mov dh, 0x0a
call cursor
call print
mov cx, 0x15
call sleep
mov si, str2
mov dl, 0x06
mov dh, 0x0c
call cursor
call print
; Prepare for notepad_rules mode...
mov cx, 0x15
call sleep
xor dl, dl
xor dh, dh
call cursor
mov si, str3
mov bl, 0x7
sigma:
mov ah, 0xe
lodsb
int 0x10
or al, al
jnz sigma
add dl, 0x10
call cursor
notepad_rules:
; Read char from keyboard
xor ah, ah
int 0x16
; Verify if Backspace key was pressed
cmp al, 0x8
je delete_char
; Verify if Enter key was pressed
cmp al, 0x0d
je inc_y
; Verify if the line reached on end
cmp dl, 0x27
jge inc_y
; Check for keys to call egg function
cmp al, 0x1b ; ESC
je e1
cmp al, 0x36 ; 6
je e2
cmp al, 0x39 ; 9
je e3
cmp al, 0x09 ; TAB
je e4
; Print char on screen
mov ah, 0x0a
xor bh, bh
mov bl, 0x0f
mov cx, 0x01
int 0x10
inc dl
call cursor
jmp notepad_rules
inc_y:
xor dl, dl
inc dh
call cursor
jmp notepad_rules
delete_char:
dec dl
call cursor
jmp notepad_rules
e1:
mov si, easter1
jmp eternal
e2:
mov si, easter2
jmp eternal
e3:
mov si, easter3
jmp eternal
e4:
mov si, easter4
; jmp eternal (it down here)
eternal:
xor dl, dl
xor dh, dh
call cursor
call print
hlt
; Set cursor position
; dl - Columns - x
; dh - Rows - y
cursor:
cli
mov ah, 0x2
mov bh, 0x0
int 0x10
ret
; Print some gay string
; si - string
print:
cli
mov bl, 0x21
l:
mov ah, 0xe
lodsb
inc bl
int 0x10
or al, al
jnz l
ret
; Delay
; cx - delay value in microsseconds
sleep:
cli
mov ah, 0x86
mov dx, 0x0
int 0x15
ret
str1 db "Happy new Year!", 0
str2 db "Enjoy this useless payload...", 0
str3 db "Type something: ", 0
easter1 db "You find a EasterEgg, OMG!", 0
easter2 db "This Code is so buggy. >:C", 0
easter3 db "I really hate this mbr payload.", 0
easter4 db "You're very gay. B)", 0
times 510 - ($-$$) db 0 ; Fill the file with 0 510 times'
dw 0xAA55 ; Magic number used by BIOS to identify the file

26
bootloader/getHex.py Normal file
View File

@ -0,0 +1,26 @@
from sys import argv,exit as exitc
if len(argv) != 2:
print('Please inform just one file!')
exitc(1)
try:
file = open(argv[1], 'rb')
except FileNotFoundError:
print('The specified file was not found!')
exitc(2)
content = file.read()
file.close()
for i in range(len(content)):
if i%12 == 0:
print('')
print(format(content[i], '#04x'), end='')
if i != len(content)-1:
print(', ', end='')
print('\nSize:', len(content))