能力值:
( LV7,RANK:100 )
|
-
-
2 楼
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
楼主写的不错好文章
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
发现自己变懒了,习惯了微软的VC,从来都不去考虑底层的问题,哎!
|
能力值:
( LV6,RANK:90 )
|
-
-
5 楼
very good, study
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
谢谢楼主共享
|
能力值:
( LV4,RANK:50 )
|
-
-
7 楼
强人啊 啊啊啊
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
收藏了慢慢学
|
能力值:
( LV2,RANK:10 )
|
-
-
9 楼
附个代码。
.586P
LOADER_SIZE EQU 1024
PADDING_100h EQU 100h
code_seg segment use16
org PADDING_100h
startup:
jmp main
include int21.inc
Error_Str db 'Error!'
Error_Str_Len Equ $-Error_Str
PrintStr Proc near C USES AX BX CX ES BP,\
Color:BYTE,Position:WORD,\
StrAddrOffset:WORD,StrLen:WORD
mov cx,StrLen
mov bl,Color
mov dx,Position
push bp
push StrAddrOffset
pop bp
mov bh,0
mov al,0
mov ah,13h
int 10h
pop bp
ret
PrintStr endp
WaitKey Proc near C USES AX,KeyCode:BYTE
.repeat
mov ah,0
int 16h
.until al == KeyCode
ret
WaitKey endp
Relocate_And_Exec Proc near C
Local Reloc_Table_Addr:WORD
Local Reloc_Item_Num:WORD
Local Exe_Header_Size:WORD
Local Exe_Entry_Point:WORD
Local Reloc_CS:WORD
Local Init_SS:WORD
Local Init_SP:WORD
call Current_Ip
Current_Ip:
pop bx
add bx,Exe_Start-Current_Ip
.if word ptr[bx] !='ZM' ;find the exe file's magic number
stc
ret
.endif
mov word ptr[Reloc_CS],bx
shr word ptr[Reloc_CS],4 ;add reloc_cs with loader_size and psp size
mov ax,cs
add ax,word ptr[bx+8]
add word ptr[Reloc_CS],ax
mov ax,word ptr[bx+18h] ;get the reloc_table address
mov word ptr[Reloc_Table_Addr],ax
mov ax,word ptr[bx+6] ;get the reloc_item number
mov word ptr[Reloc_Item_Num],ax
mov ax,word ptr[bx+8] ;get the exe header_size/16
shl ax,4 ;X16
mov word ptr[Exe_Header_Size],ax
mov ax,word ptr[bx+0eh]
add ax,word ptr[Reloc_CS]
mov word ptr[Init_SS],ax
mov ax,word ptr[bx+10h]
mov word ptr[Init_SP],ax
mov ax,word ptr[bx+14h]
mov word ptr[Exe_Entry_Point],ax
xor cx,cx
.while cx < word ptr[Reloc_Item_Num]
mov si,cx
shl si,2 ;reloc_item size is 4 bytes
add si,Reloc_Table_Addr
mov di,word ptr[bx+si+2] ;cs
shl di,4
add di,word ptr[bx+si] ;ip
add di,bx
add di,word ptr[Exe_Header_Size]
mov ax,word ptr[Reloc_CS]
add word ptr[di],ax
inc cx
.endw
;mov si,0
;mov di,LOADER_SIZE
;add di,word ptr[Exe_Header_Size]
;sub di,100h
;mov cx,100h
;cld
;rep movsb [di],[si]
mov ax,word ptr[Reloc_CS]
mov bx,word ptr[Exe_Entry_Point]
mov cx,word ptr[Init_SS]
mov dx,word ptr[Init_SP]
mov ds,ax
mov es,ax
mov ss,cx
mov sp,dx
push ax ;cs
push bx ;ip
retf
Relocate_And_Exec endp
main:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0fffeh
push ds
push 0
pop ds
mov word ptr ds:[21h*4],Int21_Handler
mov word ptr ds:[21h*4+2],cs
pop ds
invoke Relocate_And_Exec
.if Carry?
invoke PrintStr,57h,0,offset Error_Str,Error_Str_Len
int 21h
.endif
invoke WaitKey,'n'
ret
;---------------------------
padding_size equ $-startup
padding db LOADER_SIZE-padding_size dup(0)
Exe_Start:
code_seg ends
end startup
详细请看
http://hi.baidu.com/quick1/blog/item/9eb0f9ea6aaad8d4d539c916.html
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
楼主厉害呀!
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
谢谢楼主分享这么好的资料。。。
|
能力值:
( LV2,RANK:10 )
|
-
-
12 楼
很有收获,多谢楼主
|