%
GetUnknowVarOffset proc uses esi edi ebx
LOCAL user32base:dword
LOCAL varaddr:dword
LOCAL optable[2048]:byte
LOCAL oplen[256]:byte ;记录每个指令的长度,最多512个
invoke LoadLibrary,offset user32dll
mov user32base,eax
invoke _ProcessPeFile,user32base ;返回user32.dll的.data段的虚拟偏移
invoke GetProcAddress,user32base,offset _UserRegisterWowHandlers
.if eax!=NULL
invoke RtlMoveMemory,offset buffercode,eax,1000
mov esi,offset buffercode
;------------------------ 利用LDE32库函数得到该函数中每个指令的长度:)
lea eax,optable
push eax
call disasm_init ;解压缩’指令长度表’
xor ebx,ebx
lea edi,oplen
@@nextcode:
push esi
lea eax,optable
push eax
call disasm_main
.if eax!=-1 && ebx<256
mov cx,word ptr [esi]
mov dl,byte ptr [esi+2]
.if eax == 3 && cx == 08C2h && dl == 00 ;找到ret 08=C20800
;-------------------然后反过去找MOV EAX,XXXXXXXX =B8 XXXXXXXX
dec ebx
@@nextcode2:
mov AL,byte ptr [edi+ebx]
movzx eax,al
sub esi,eax
mov cl,byte ptr [esi]
.if al == 5 && cl == 0B8H
inc esi
mov eax,dword ptr [esi]
mov varaddr,eax
dec esi
.else
@@nextb8:
dec ebx
.if ebx >1
jmp @@nextcode2
.else
jmp @@errcode
.endif
.endif
.else
mov byte ptr [edi+ebx],al
inc ebx
add esi,eax
jmp @@nextcode
.endif
.else ;找不到RET 08指令
@@errcode:
invoke MessageBox,0,offset errnocode,offset vp,1
xor eax,eax
ret
.endif
;------------------------
.else ;找不到函数
invoke MessageBox,0,offset errnowow,offset vp,1
xor eax,eax
ret
.endif
;正常情况varaddr为USER32.DLL全局变量中记录当前线程GUI TABLE R3层地址的变量的地址
mov ecx,user32base
add ecx,VirtualAddress ;得到内存中user32.dll的全局变量的起始地址
mov eax,varaddr
sub eax,ecx ;变量的地址减全局变量起始地址
.if eax>0 && eax<VirtualSize ;变量的偏移大于0,小于全局变量总大小
add eax,4
mov VarOffset,eax
.else
jmp @@nextb8
.endif
ret
GetUnknowVarOffset endp
GetUser32Base proc uses ebx esi edi remoteproid
LOCAL hSnapshot:dword
LOCAL modinfMODULEENTRY32
LOCAL modname[256]:byte
mov modinfo.dwSize,sizeof MODULEENTRY32
invoke CreateToolhelp32Snapshot,TH32CS_SNAPMODULE,remoteproid
mov hSnapshot,eax
invoke Module32First,hSnapshot,addr modinfo
.while eax
lea ecx,modinfo.szModule
invoke lstrcmpi,offset user32dll,ecx
.if eax == 0
mov eax,modinfo.modBaseAddr
ret
.endif
invoke Module32Next,hSnapshot,addr modinfo
.endw
invoke CloseHandle,hSnapshot
ret
GetUser32Base endp
_ProcessPeFile proc _lpPeHead
local @szBuffer[1024]:byte,@szSectionName[16]:byte
mov esi,_lpPeHead
assume esi:ptr IMAGE_DOS_HEADER
add esi,[esi].e_lfanew
mov edi,esi
assume edi:ptr IMAGE_NT_HEADERS
;movzx ecx,[edi].FileHeader.Machine
;movzx edx,[edi].FileHeader.NumberOfSections
;movzx ebx,[edi].FileHeader.Characteristics
;********************************************************************
上一页 1 2 3 4 5 6 7 8 9 10 下一页 |