Skip to content

Instantly share code, notes, and snippets.

@indutny indutny/ExeLDR.asm
Created Dec 31, 2010

Embed
What would you like to do?
Loader for MSDOS EXE files, without MSDOS
;Made by FeDOS (FeDOS SubSystems)
;All Rights Reserved
;FeDOS (ICQ 313-997-813)
[BITS 16]
[ORG 0x0000]
__start:
; mov cx, 0xB800
; mov es, cx
; mov bx, 0h
; mov cx, cs
; sub cx, 100h
; mov ds, cx
; mov ax, 00002h
; int 10h
; mov cx, 0xFA0
__loop:
; mov al, [ds:bx]
; mov [es:bx], al
; inc bx
; loop __loop
; xor ah, ah
; int 16h
mov ax, cs
mov bx, __start
shr bx, 4
add bx, 20h
add ax, bx
mov ds, ax
mov ax, [ds:0]
mov ebx, 0
__MZ:
;Length of file (last page)
add ebx, 4
;Count of relocations
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __RELOCNT
mov [cs:edx], ax
;HDR Length
inc ebx
inc ebx
mov eax, 0
mov ax, [ds:ebx]
shl eax, 4
mov edx, __HDRSIZE
mov [cs:edx], eax
;MinMem, MaxMem
add ebx, 4
;Get SS Segment address
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __SS
mov [cs:edx], ax
;Get SP Start Value
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __SP
mov [cs:edx], ax
;ChkSum
inc ebx
inc ebx
;Get IP Start Value
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __IP
mov [cs:edx], ax
;Get CS Segment address
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __CS
mov [cs:edx], ax
;Get First Offset
inc ebx
inc ebx
mov ax, [ds:ebx]
mov edx, __OFF
mov [cs:edx], ax
;Get Overlay Number
inc ebx
inc ebx
;Looking for relocations
;Getting a start address
mov edx, __RELOCNT
mov ax, [cs:edx]
cmp ax, 0
je __RUN_
mov ebx, __OFF
mov bx, [cs:ebx]
;Cicle
__RELO:
;EAX <- Address of relocation
mov eax, 0
mov ax, [ds:ebx]
add ebx, 2
mov edx, 0
mov dx, [ds:ebx]
add ebx, 2
shl edx, 4
add eax, edx ;EAX = Address of relocation
xchg ebx, esi
;Changing Segment Relocation Address to real address
;Now - getting real address in memory -> ds:ebx
mov ebx, 0
mov edx, __HDRSIZE
mov bx, [cs:edx]
add ebx, eax
mov dx, [ds:bx]
xchg bx , di
mov ecx, __CS
mov cx, [cs:ecx]
add dx, cx
mov ecx, __HDRSIZE
mov cx, [cs:ecx]
shr cx, 4
add dx, cx
mov cx, ds
add dx, cx
xchg bx, di
mov [ds:ebx], dx
xchg ebx, esi
jmp __CHECK
__RUN_:
jmp __RUN
__CHECK:
;Checking __RELOCNT>0 -> jump to RUN
mov edx, __RELOCNT
mov ax, [cs:edx]
dec ax
mov [cs:edx], ax
cmp ax, 0
je __RUN
jmp __RELO
__RUN:
;Running program
mov bx, ds
mov edx, __CS
mov ax, [cs:edx]
mov edx, __HDRSIZE
xchg si, bx
mov bx, [cs:edx]
mov dx, bx
xchg si, bx
shr dx, 4
add ax, dx
add ax, bx
mov edx, __IP
mov dx, [cs:edx]
mov ebx, off
mov [cs:ebx], dx
mov ebx, segmnt
mov [cs:ebx], ax
mov ds, ax
mov es, ax
; mov bx, 0f04h
; mov cx, 0460h
; mov dx, 0f04h
; mov si, 0264h
; mov di, 083b0h
; mov bp, 0000h
; mov sp, 03ffeh
db 0EAh ;jmp KernelSegB:[0000h]
off dw 0000h ;‘¬ҐйҐ­ЁҐ
segmnt dw 0000h ;‘ҐЈ¬Ґ­в
__varlist:
__RELOCNT dw 0
__HDRSIZE dw 0, 0
__SS dw 0
__SP dw 0
__IP dw 0
__CS dw 0
__OFF dw 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.