Last active
September 23, 2022 19:14
-
-
Save Jacajack/9a091978f545aa4d7a323acdaf2062c7 to your computer and use it in GitHub Desktop.
Example of overriding BIOS interrupts in i386 assembly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[org 0x7c00] | |
[bits 16] | |
[map all thief.map] | |
;Stack init | |
mov bp, 0xffff | |
mov sp, bp | |
;Display initial interrupt address | |
mov bx, [intnum*4+2] | |
mov cx, [intnum*4] | |
mov si, mesg_origs | |
call puts | |
mov ax, bx | |
call puthexw | |
mov si, mesg_nl | |
call puts | |
mov si, mesg_origo | |
call puts | |
mov ax, cx | |
call puthexw | |
mov si, mesg_nl | |
call puts | |
mov cx, [intnum*4+2] | |
mov bx, [intnum*4] | |
mov es, cx | |
mov ax, 0 | |
loop: | |
inc bx | |
inc ax | |
cmp [es:bx], byte 0xcf | |
je loop_end | |
jmp loop | |
loop_end: | |
mov si, mesg_intlen | |
call puts | |
call putdec | |
mov al, 'b' | |
call putc | |
mov si, mesg_nl | |
call puts | |
intnum equ 0x13 | |
mov ax, 0x07c0 | |
mov word [intnum*4+2], ax | |
mov word [intnum*4], ( myint - $$ ) | |
int 0x13 | |
mov si, mesg_hello | |
call puts | |
jmp $ | |
myint: | |
mov si, mesg_nl | |
push ax | |
mov al, 'a' | |
call putc | |
pop ax | |
call puthexw | |
call puts | |
mov al, 'b' | |
call putc | |
mov ax, bx | |
call puthexw | |
call puts | |
mov al, 'c' | |
call putc | |
mov ax, cx | |
call puthexw | |
call puts | |
mov al, 'd' | |
call putc | |
mov ax, dx | |
call puthexw | |
call puts | |
iret | |
%include "stdio.asm" | |
mesg_origs: db "org int cs: ", 0 | |
mesg_origo: db "org int ip: ", 0 | |
mesg_intlen: db "org int len: ", 0 | |
mesg_hello: db "hello!", 10, 13, 0 | |
mesg_nl: db 10, 13, 0 | |
times 510 - ( $ - $$ ) db 0 | |
dw 0xaa55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment