.model tiny
.code
org 100h
start: jmp begin
fname db 'btroot.exe', 0
newval db 90h,90h
handle dw ?
errcode db ?
errmsg db 'error 0x','$'
sucmsg db 'File sucessfully patched!','$'
begin: mov ax,3D02h ; open file
lea dx,fname
int 21h
jc errors
mov handle,ax
mov ax,4200h ; move pointer
mov bx,handle
mov cx,0h
mov dx,20DAh
int 21h
jc errors
mov ah, 40h
mov bx,handle
mov cx,02h
lea dx,newval
int 21h
jc errors
mov ah,3Eh ; close file
mov bx,handle
int 21h
jc errors
mov ah,09h
lea dx,sucmsg
int 21h
fine: ret ; 0 to IP from stack ( int 20 )
print_byte_hex proc near
push cx
push dx
mov dh,dl ; copy byte
mov cx,4
shr dl,cl ; first digit
call print_digit
xchg dl,dh
and dl,0Fh ; second one
call print_digit
pop dx
pop cx
ret
print_byte_hex endp
print_digit proc near
cmp dl,0Ah
jae letter
or dl,30h
jmp print
letter: add dl,'A' - 0Ah
print: mov ah,02h
int 21h
ret
print_digit endp
errors: mov errcode,al
mov ah,09h
lea dx,errmsg
int 21h
mov dl,errcode
call print_byte_hex
jmp fine
end start