// EnumDll.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
//#include <Dbghelp.h>
#include <ImageHlp.h>
#pragma comment(lib,"ImageHlp")
//#pragma comment(lib,"Dbghelp")
void EnumDllfunk()
{
DWORD dwNum = 0;
//获取当前file的句柄
HMODULE hMdoule = GetModuleHandle(NULL);
//定位PE结构
PIMAGE_DOS_HEADER pDosHdr = (PIMAGE_DOS_HEADER)hMdoule;
PIMAGE_NT_HEADERS pNtHdr = (PIMAGE_NT_HEADERS)(DWORD(hMdoule)+pDosHdr->e_lfanew);
//保存映像的基地址和导入表的RVA
DWORD lpBase = pNtHdr->OptionalHeader.ImageBase;
PIMAGE_IMPORT_DESCRIPTOR pImpDes = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToData(lpBase,TRUE,IMAGE_DIRECTORY_ENTRY_EXPORT,&dwNum);
这个函数返回pImpDes ==NULL
if(!pImpDes)
{
DWORD dwNum = GetLastError();
printf("%d\r\n",dwNum);
return;
}
我看下错误返回127描述错误信息找不到指定的程序。
msdn描述lpBase为the base of Image
while ( pImpDes->Name)
{
printf("DllName = %s \r\n",(DWORD)lpBase+(DWORD)pImpDes->Name);
PIMAGE_THUNK_DATA thunk = (PIMAGE_THUNK_DATA)(pImpDes->FirstThunk+(DWORD)lpBase);
int n = 0;
while(thunk->u1.Function)
{
if (thunk->u1.Ordinal & IMAGE_ORDINAL_FLAG )
{
printf("ordinal =%08X \r\n",thunk->u1.Ordinal & 0xFFFF);
}else
{
PIMAGE_IMPORT_BY_NAME pImName = (PIMAGE_IMPORT_BY_NAME)thunk->u1.Function;
printf("FuncName = %s \t \t",(DWORD)lpBase+pImName->Name);
printf("addr = %08X \r\n",(DWORD)((DWORD*)((DWORD)lpBase+pImpDes->FirstThunk)+n));
}
thunk++;
n++;
}
}
pImpDes++;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)