【问题标题】:Runtime error while obtaining PE headers from an application at runtime在运行时从应用程序获取 PE 标头时出现运行时错误
【发布时间】:2012-07-11 18:17:53
【问题描述】:

我一直在尝试为 WINDOWS 进程制作一个可执行注入器,程序编译时没有任何错误,但是当我运行程序时(通过 Microsoft Visual Studio 的调试模式),我得到一个运行时错误。 Visual Studio 高亮一行(我已经用 cmets 标记了)

#include <windows.h>
#include "resource.h"

int main()
{
 PIMAGE_DOS_HEADER IDH;
 PIMAGE_NT_HEADERS INTH;
 PIMAGE_SECTION_HEADER ISH;

 //Lets load the resource
 HRSRC hResource=FindResourceA(NULL,(LPCSTR)MAKEINTRESOURCE(IDR_EXE1),"EXE");
 DWORD ResourceSize=SizeofResource(NULL,hResource);
 HGLOBAL hGlob=LoadResource(NULL,hResource);
 LPSTR lpFileMaped=(LPSTR)LockResource(hGlob);

 //obtain the DOS and PE headers
 IDH=(PIMAGE_DOS_HEADER)&lpFileMaped[0];
 INTH=(PIMAGE_NT_HEADERS)&lpFileMaped[IDH->e_lfanew]; //this is the highlighted line
                                       // which supposedly causes an error at runtime

 ....

为什么会这样,谁能详细说明?

【问题讨论】:

  • 当您遵守 0xcccccccc 时,完全没有任何错误检查最终会导致 AccessViolation 上的代码炸弹
  • +1 到上面的评论——你确定最初的FindResource 调用成功了吗?检查可能失败的函数的返回值总是更好。

标签: c++ process executable portable-executable inject


【解决方案1】:

看看standard work of Matt Pietrek

e_lfanew字段包含PE头的文件偏移量

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 2015-04-18
    • 2014-05-14
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多