首页
社区
课程
招聘
学习PE输出表
2005-7-4 16:35 12374

学习PE输出表

2005-7-4 16:35
12374
; searchapi.asm

.386
.model flat, stdcall
option casemap:none

include         windows.inc
include         kernel32.inc
includelib      kernel32.lib

.data

szOk                    db ":)  Ok !",0
szCap                   db "[sapi] -icytear- ",0
szUser32Dll             db "user32.dll",0
szLoadLibraryA          db "LoadLibraryA",0
szMsgBox                db "MessageBoxA",0
szGetProcAddress        db "GetProcAddress",0

Kernel32Base    dd 0
User32Base      dd 0

fGetProcAddress dd 0
fLoadLibraryA   dd 0
fMessageBoxA    dd 0
fExitProcess    dd 0

.code

start:  
        mov    ecx, [esp]
        xor    edx, edx
        assume  fs:nothing
        push   offset _exception_handle
        push   fs:[0]
        mov    fs:[0],esp

        ;----------------------------
        ; get kernel32 module handle
        ;----------------------------

getK32Base:
        dec    ecx
        cmp    word ptr [ecx],IMAGE_DOS_SIGNATURE       ;0x5A4D
        jnz    getK32Base
        mov    dx,word ptr [ecx+IMAGE_DOS_HEADER.e_lfanew]
        cmp    dword ptr [ecx+edx],IMAGE_NT_SIGNATURE   ;0x00004550
        jnz    getK32Base
        cmp    ecx,dword ptr [ecx+edx+IMAGE_NT_HEADERS.OptionalHeader.ImageBase]
        jnz    getK32Base
        mov    Kernel32Base,ecx
        
        ;-----------------------
        ; search GetProcAddress
        ;-----------------------
        mov    esi,Kernel32Base
        mov    edx,[esi+IMAGE_DOS_HEADER.e_lfanew]
        add    esi,edx
        add    esi,78h ;IMAGE_DATA_DIRECTORY [IMAGE_DIRECTORY_ENTRY_EXPORT]
        assume  esi: ptr IMAGE_DATA_DIRECTORY
        mov    edi,[esi].VirtualAddress
        add    edi,Kernel32Base
        assume edi: ptr IMAGE_EXPORT_DIRECTORY
        mov    edx,[edi].AddressOfNames
        add    edx,Kernel32Base
        mov    ebx,[edi].NumberOfNames
        push    ebx
        push    edx
        push    offset szGetProcAddress
        push    Kernel32Base
        call    SearchFunName
        mov    ebx,[edi].AddressOfNameOrdinals
        add    ebx,Kernel32Base
        lea    ebx,[ebx+eax*2]
        movzx    ebx,word ptr [ebx]
        mov    esi,[edi].AddressOfFunctions
        add    esi,Kernel32Base
        lea    esi,[esi+ebx*4]
        mov    ebx,dword ptr [esi]
        add    ebx,Kernel32Base
        mov    fGetProcAddress,ebx ;save address of GetProcAddress
        
        ;---------------------
        ;search LoadLibraryA
        ;---------------------
        mov    ebx,[edi].NumberOfNames
        push   ebx
        push   edx
        push   offset szLoadLibraryA
        push    Kernel32Base
        call    SearchFunName
        mov    ebx,[edi].AddressOfNameOrdinals
        add    ebx,Kernel32Base
        lea    ebx,[ebx+eax*2]
        movzx  ebx,word ptr [ebx]
        mov    esi,[edi].AddressOfFunctions
        add    esi,Kernel32Base
        lea    esi,[esi+ebx*4]
        mov    ebx,dword ptr [esi]
        add    ebx,Kernel32Base
        mov    fLoadLibraryA,ebx
        
        push    offset szUser32Dll
        call    fLoadLibraryA
        mov     User32Base,eax
        push    offset szMsgBox
        push    User32Base
        call    fGetProcAddress
        push    MB_OK
        push    offset szCap
        push    offset szOk
        push    NULL
        call    eax
        
        invoke   ExitProcess, NULL
        

SearchFunName   proc uses ebx ecx esi edi edx \
        base:DWORD, pFunName:DWORD, pArray:DWORD, num:DWORD
        
        mov    ecx,-1
        mov    edi,pFunName
        xor    eax,eax
        repnz  scasb
        not    ecx
        dec    ecx
        mov    edx,ecx
        xor    ebx,ebx

        .while(ebx<num)
                mov    ecx,edx
                mov    esi,pFunName
                mov    edi,pArray
                lea    edi,[edi+ebx*4]
                mov    edi,dword ptr [edi]
                add    edi,base
                repz   cmpsb
                jz     @F
                inc    ebx
        .endw
        
        mov    eax,-1 ;not found
        jmp    @exit
        
        @@:
        mov    eax,ebx ;return index of AddressOfNameOrdinals.
        @exit:
        ret
        
SearchFunName   endp

_exception_handle   proc   uses ebx esi \
        pExcept:DWORD, pFrame:DWORD, pContext:DWORD, pDispatch:DWORD

        mov    esi,pContext
        assume esi:ptr CONTEXT
        lea    ebx,getK32Base
        mov    [esi].regEip,ebx ;change eip, execute continue
        mov    eax,0
        ret

_exception_handle  endp

end start

[培训]《安卓高级研修班(网课)》月薪三万计划

收藏
点赞7
打赏
分享
最新回复 (11)
雪    币: 325
活跃值: (1510)
能力值: ( LV13,RANK:970 )
在线值:
发帖
回帖
粉丝
nbw 24 2005-7-4 17:11
2
0
顶!
雪    币: 280
活跃值: (433)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
icytear 11 2005-7-4 17:47
3
0
最初由 nbw 发布
顶!


兄弟..总是你第一个顶上来!
雪    币: 598
活跃值: (617)
能力值: ( LV12,RANK:660 )
在线值:
发帖
回帖
粉丝
prince 16 2005-7-4 20:42
4
0
我做第2个~  
雪    币: 1221
活跃值: (464)
能力值: (RANK:460 )
在线值:
发帖
回帖
粉丝
monkeycz 11 2005-7-4 22:01
5
0
不错
雪    币: 1852
活跃值: (504)
能力值: (RANK:1010 )
在线值:
发帖
回帖
粉丝
北极星2003 25 2005-7-4 23:46
6
0
学习,收藏
雪    币: 200
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
haduke 2005-7-5 11:04
7
0
学习中,谢谢
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
skyhits 2005-7-6 17:01
8
0
这个精华给的不太合适,,,icytear有rpwt

这段代码完全是出自武汉大学出版的病毒分析与预防(具体书名记不清了),不过这段代码记得很牢,是病毒api重定位用的
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
skyhits 2005-7-6 17:02
9
0
作弊行为,,,鄙视中。。。。。
雪    币: 325
活跃值: (1510)
能力值: ( LV13,RANK:970 )
在线值:
发帖
回帖
粉丝
nbw 24 2005-7-6 17:43
10
0
最初由 skyhits 发布
这个精华给的不太合适,,,icytear有rpwt

这段代码完全是出自武汉大学出版的病毒分析与预防(具体书名记不清了),不过这段代码记得很牢,是病毒api重定位用的


没看过武汉大学那本书。查找api这段代码很经典,可以说80%以上的代码都是这样,除非这段代码80%以上都跟书上的一样,否则说这段代码是抄袭是不合适的。
雪    币: 280
活跃值: (433)
能力值: ( LV12,RANK:450 )
在线值:
发帖
回帖
粉丝
icytear 11 2005-7-6 19:59
11
0
最初由 skyhits 发布
icytear有rpwt


http://www.pediy.com/bbshtml/BBS4/kanxue468.htm
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
rookier 2005-7-13 16:55
12
0
hehe,赶紧学习一下
游客
登录 | 注册 方可回帖
返回