.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
.data
szLoadLibrary db 'LoadLibraryA',0
szGetProcAddress db 'GetProcAddress',0
szGetModuleHandle db 'GetModuleHandleA',0
szProcessWndName db 'Program Manager',0
szKernel db 'Kernel32.dll',0
.data?
dwProcessID dd ?
hProcess dd ?
lpLoadLibrary dd ?
lpGetProcAddress dd ?
lpGetModuleHandle dd ?
hModule dd ?
lpRemoteCode dd ?
.code
_GetKernelBase proc _dwKernelRet
LOCAL _dwRet
pushad
;**********************代码重定位***************
call @F
@@:
pop ebx
sub ebx, offset @B
;************************************************
mov edi, _dwKernelRet
and edi, 0ffff0000h
.while TRUE
.if word ptr [edi] == IMAGE_DOS_SIGNATURE
mov eax, edi
add eax, [eax + 003ch]
.if word ptr [eax] == IMAGE_NT_SIGNATURE
mov _dwRet, edi
.break
.endif
.endif
sub edi, 010000h
.break .if edi < 070000000h
.endw
popad
mov eax, _dwRet
ret
_GetKernelBase endp
_GetAPIByName proc _dwKernelBase, _lpszAPI
LOCAL @dwRet, @dwAPILength
pushad
;************************** 获取API长度 ***************************
mov edi, _lpszAPI
mov ecx, -1 ;构建一个无限ecx循环
xor al, al
cld
repnz scasb
sub edi, _lpszAPI ;用edi减去 _lpszAPI原始地址 = 长度
mov @dwAPILength, edi
;************************** 获取导出库 ***************************
mov esi, _dwKernelBase
assume esi: ptr IMAGE_DOS_HEADER ;esi -> DOS头
add esi, [esi].e_lfanew
assume esi: ptr IMAGE_NT_HEADERS ;esi -> NT头
mov esi, [esi].OptionalHeader.DataDirectory.VirtualAddress ;esi -> 导出库
add esi, _dwKernelBase
assume esi: ptr IMAGE_EXPORT_DIRECTORY
;************************** 查找API *********************************
mov ebx, [esi].AddressOfNames
add ebx, _dwKernelBase ;ebx -> AddressOfNames
xor edx, edx ;edx -> 函数的Index
.repeat ;循环查找API
push esi
mov esi, _lpszAPI ;esi -> _lpszAPI
mov edi, [ebx]
add edi, _dwKernelBase ;edi -> 导出函数名的地址
mov ecx, @dwAPILength ;ecx -> 要获取的API的长度
repz cmpsb ;循环比较
.if ZERO? ;找到这个API
pop esi
.break
.endif
pop esi
add ebx, 4
inc edx
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
.data
szLoadLibrary db 'LoadLibraryA',0
szGetProcAddress db 'GetProcAddress',0
szGetModuleHandle db 'GetModuleHandleA',0
szProcessWndName db 'Program Manager',0
szKernel db 'Kernel32.dll',0
.data?
dwProcessID dd ?
hProcess dd ?
lpLoadLibrary dd ?
lpGetProcAddress dd ?
lpGetModuleHandle dd ?
hModule dd ?
lpRemoteCode dd ?
.code
_GetKernelBase proc _dwKernelRet
LOCAL _dwRet
pushad
;**********************代码重定位***************
call @F
@@:
pop ebx
sub ebx, offset @B
;************************************************
mov edi, _dwKernelRet
and edi, 0ffff0000h
.while TRUE
.if word ptr [edi] == IMAGE_DOS_SIGNATURE
mov eax, edi
add eax, [eax + 003ch]
.if word ptr [eax] == IMAGE_NT_SIGNATURE
mov _dwRet, edi
.break
.endif
.endif
sub edi, 010000h
.break .if edi < 070000000h
.endw
popad
mov eax, _dwRet
ret
_GetKernelBase endp
_GetAPIByName proc _dwKernelBase, _lpszAPI
LOCAL @dwRet, @dwAPILength
pushad
;************************** 获取API长度 ***************************
mov edi, _lpszAPI
mov ecx, -1 ;构建一个无限ecx循环
xor al, al
cld
repnz scasb
sub edi, _lpszAPI ;用edi减去 _lpszAPI原始地址 = 长度
mov @dwAPILength, edi
;************************** 获取导出库 ***************************
mov esi, _dwKernelBase
assume esi: ptr IMAGE_DOS_HEADER ;esi -> DOS头
add esi, [esi].e_lfanew
assume esi: ptr IMAGE_NT_HEADERS ;esi -> NT头
mov esi, [esi].OptionalHeader.DataDirectory.VirtualAddress ;esi -> 导出库
add esi, _dwKernelBase
assume esi: ptr IMAGE_EXPORT_DIRECTORY
;************************** 查找API *********************************
mov ebx, [esi].AddressOfNames
add ebx, _dwKernelBase ;ebx -> AddressOfNames
xor edx, edx ;edx -> 函数的Index
.repeat ;循环查找API
push esi
mov esi, _lpszAPI ;esi -> _lpszAPI
mov edi, [ebx]
add edi, _dwKernelBase ;edi -> 导出函数名的地址
mov ecx, @dwAPILength ;ecx -> 要获取的API的长度
repz cmpsb ;循环比较
.if ZERO? ;找到这个API
pop esi
.break
.endif
pop esi
add ebx, 4
inc edx