⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joincode.asm

📁 一个朋友写的操作系统源码
💻 ASM
字号:

dseg segment para public 'global'

     exehdr db 20h dup (0)

     ; we only concern about cs:ip
     ; also magic # in exe

     exefile   db 'start386.exe',0     ; source file

     patchfile db 'stuixldr.exe',0     ; resident file

     exebuf    db 4096 dup (0)

     sucmes    db 'stuixldr.exe patched successful!','$'

     ; small program, 4k is big enough
     ; no need to check boundary

dseg ends

cseg segment para public 'code'

     assume cs:cseg,ds:dseg

     extrn panic:near
     extrn printf:near

start:
     mov ax,dseg
     mov ds,ax
     mov bp,sp
     sub sp,10

     ; stack arranges like this

     ; [bp-2]  : file handler for patch file only
     ; [bp-4]  : cs image
     ; [bp-6]  : ip image
     ; [bp-8]  : patch offset in stuixldr.exe
     ; [bp-10] : # of bytes in start386.exe

     ; read stuixldr.exe header in

     mov dx,offset patchfile
     mov al,2          ; read/write
     mov ah,3dh
     int 21h
     jnc ptnext1
     push ax
     call panic
ptnext1:
     mov bx,ax
     mov [bp-2],ax
     mov dx,offset exehdr
     mov cx,20h
     mov ah,3fh
     int 21h
     jnc ptnext2
     push ax
     call panic
ptnext2:

     ; fetch the information we need

     mov si,offset exehdr
     lodsw
     cmp ax,5a4dh
     jz ptnext3
     mov ax,11
     push ax
     call panic
ptnext3:
     mov si,offset exehdr
     add si,14h      ; address ip
     cld
     lodsw
     mov [bp-6],ax
     lodsw
     mov [bp-4],ax

     ; calculate the address we shall
     ; patch to, assume it is not bigger
     ; than 64k

     mov ax,[bp-4]
     inc ax          ; next para
     mov cl,4
     shl ax,cl
     add ax,[bp-6]

     ; now we got the offset we want to patch

     mov [bp-8],ax

     ; get start386.exe

     mov dx,offset exefile
     mov al,0        ; read only
     mov ah,3dh
     int 21h
     jnc ptnext4
     push ax
     call panic
ptnext4:
     mov bx,ax
     mov dx,offset exehdr
     mov cx,20h
     mov ah,3fh
     int 21h
     jnc ptnext5
     push ax
     call panic
ptnext5:
     mov si,offset exehdr
     lodsw
     cmp ax,5a4dh
     jz ptnext6
     mov ax,11
     push ax
     call panic
ptnext6:

     ; move file pointer to skip exehdr

     xor cx,cx
     mov dx,200h
     mov al,0
     mov ah,42h
     int 21h
     jnc ptnext7
     push ax
     call panic
ptnext7:
     mov cx,4096
     mov dx,offset exebuf
     mov ah,3fh
     int 21h
     jnc ptnext8
     push ax
     call panic
ptnext8:
     mov [bp-10],ax

     ; close start386.exe

     mov ah,3eh
     int 21h

     ; start patching

     mov bx,[bp-2]
     mov dx,200h
     add dx,[bp-8]      ; the code start address + 16
     xor cx,cx
     mov al,0
     mov ah,42h
     int 21h
     jnc ptnext9
     push ax
     call panic
ptnext9:
     mov dx,offset exebuf
     mov cx,[bp-10]
     mov ah,40h
     int 21h
     jnc ptnext10
     push ax
     call panic
ptnext10:
     mov ah,3eh
     int 21h

     mov ax,offset sucmes
     push ax
     call printf
     pop cx

     mov ah,4ch
     int 21h
     
cseg ends

end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -