Programming 版 (精华区)

发信人: pzc (不过如此), 信区: Programming
标  题: 查找法获得GetProcAddress地址
发信站: 哈工大紫丁香 (2002年03月03日21:14:31 星期天), 站内信件

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.data
hKernel32 dd 0
nKernel32 db "Kernel32.dll",0
nGetProcAddress db "GetProcAddress",0
PEGame segment
    push offset nKernel32
    call GetModuleHandle
    mov hKernel32,eax               ;保存kernel32.dll的base addr
    mov ebx,eax
    assume ebx :ptr IMAGE_DOS_HEADER
    add ebx,[ebx].e_lfanew
    assume ebx:ptr IMAGE_NT_HEADERS
    mov ebx,[ebx].OptionalHeader.DataDirectory.VirtualAddress ;first I use a
dd ebx,... make a error
    add ebx,hKernel32
    assume ebx:ptr IMAGE_EXPORT_DIRECTORY
    mov ebp,[ebx].AddressOfNames
    add ebp,hKernel32                ;now ebp=Addr of RVAofName[]
    mov     eax,0                    ; eax AddressOfNames Index
    mov     ecx,14                   ;length of GetProcAddress
    .repeat
            mov     edi,[ebp]
            add     edi,hKernel32
            mov     esi,offset nGetProcAddress
            repz    cmpsb
            .if zero?
                 .break
            .endif
            mov     ecx,14
            add     ebp, 4        ;下一个RVA
            inc     eax
    .until eax == [ebx].NumberOfNames
    mov     ebp, [ebx].AddressOfNameOrdinals
    add     ebp, hKernel32
    movzx   ecx,word ptr [ebp+eax*2]
    mov     ebp, [ebx].AddressOfFunctions   ; get the address of the api
    add     ebp, hKernel32
    mov     eax, [ebp+ecx*4]
    add     eax,hKernel32                   ;now we get it
    ;Get Other Funtion Addr
    ret 

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.236.144]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.736毫秒