【问题标题】:Trying to call functions directly through the Import Section尝试通过导入部分直接调用函数
【发布时间】:2012-07-22 00:14:35
【问题描述】:

我一直在搞乱汇编语言中的 PE 文件结构。我很确定我已经正确地进入了导入部分。我以此作为参考,其中每个框等于 4 个字节:

+-------------------------+-------------------------+
|     RVA to a list of    |       DATE/TIME         |
| pointer to APIs names   |                         |  IMPORT DATA DIRECTORY
+-------------------------+-------------------------+          #1
| .DLL address (unused)   |     RVA to .DLL name    |
+-------------------------+-------------------------+
|RVA to API address list  | 
+-------------------------+

Ollydbg。注意右边eax的值(00402048),再看高亮调用指令的值是跳转到(00402000)。

我尝试调用(RVA 到 API 地址列表)中的第一个函数,即 ExitProcess,但是当我尝试对该地址发出调用时,它导致我的程序崩溃。当我用 Ollydbg 调试它时,我发现发出 call ExitProcess 时的地址与我在列表中找到的地址不同。在 Ollydbg 中,我发现的地址指向 ,而 call ExitProcess 指向 。我在某处读到过某种 jmp 存根。就是这样吗?我应该如何调用“RVA to API 地址列表”中的函数?

我知道这可能会令人困惑。如果您需要更多说明,请告诉我。

代码如下:

extern printf
extern ExitProcess
global _start
section .code
 _start:
    mov eax, [imagebase]
    mov esi, eax
    add eax, 3ch
    mov eax, DWORD [eax]
    add eax, esi; PE header pointer in eax
    add eax, 128; 24 for PE Optional Header offset and then 104 for import RVA
    mov ebx, DWORD [eax]
    add ebx, DWORD [imagebase]; ebx now has import section offset
    mov eax, DWORD [ebx+16]
    add eax, DWORD [imagebase]; has array offset
    mov ecx, ExitProcess
    push 0
    call ecx
    ;call eax
    ;jmp ecx
    ;call ExitProcess

imagebase: db 0,0,64,0; 0x00400000; This is right

【问题讨论】:

  • 问题的截图会有所帮助。
  • 直接使用导入表条目调用函数应该不会导致问题。我怀疑您调用的函数中的某处必须在没有恢复寄存器、堆栈或异常处理程序的情况下返回。您可以在程序入口点使用CALL DWORD PTR [EAX] 对其进行测试。其中EAXExitProcess 的导入表条目的地址。
  • 其实我现在只是尝试将ExitProcess的地址移动到ecx中,然后调用ecx。用 ollydbg 看,我仍然得到与函数指针列表中相同的地址,但它不起作用。它唯一起作用的时候是当我“调用ExitProcess”时。我也尝试直接跳转到 ecx。那也没用。

标签: windows x86 nasm portable-executable


【解决方案1】:

似乎我找到了数组,但我从未检索到该地址的值。所以我试图在数组的地址而不是数组的第一个元素处调用函数。

extern printf
extern ExitProcess
global _start
section .code
_start:
    mov eax, [imagebase]
    mov esi, eax
    add eax, 3ch
    mov eax, DWORD [eax]
    add eax, esi; PE header pointer in eax
    add eax, 128; 24 for PE Optional Header offset and then 104 for import RVA
    mov ebx, DWORD [eax]
    add ebx, DWORD [imagebase]; ebx now has import section offset
    mov eax, DWORD [ebx+16]
    add eax, DWORD [imagebase]; has array offset
    mov eax, [eax];This is what I needed to do
    push 0
    call eax

imagebase: db 0,0,64,0; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多