這篇文章主要為大家展示了“如何獲取PE文件的導(dǎo)出函數(shù)列表”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何獲取PE文件的導(dǎo)出函數(shù)列表”這篇文章吧。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到革吉網(wǎng)站設(shè)計(jì)與革吉網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋革吉地區(qū)。函數(shù)作者為zhangjiawen@cchongda.com.cn,示例代碼由ccrun(老妖)編寫(xiě),應(yīng)函數(shù)作者要求發(fā)表在本站。
一段可以從任何DLL中提取函數(shù)名的代碼,這段代碼的應(yīng)用前提是該DLL文件對(duì)象沒(méi)有經(jīng)過(guò)任何“加殼”處理,否則,可能提取不完整。
#include "Dbghelp.h"
bool GetDLLFileExports(char *szFileName, UINT *nNoOfExports, char **&pszFunctions)
{
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
PIMAGE_DOS_HEADER pImg_DOS_Header;
PIMAGE_NT_HEADERS pImg_NT_Header;
PIMAGE_EXPORT_DIRECTORY pImg_Export_Dir;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile == INVALID_HANDLE_VALUE)
return false;
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(hFileMapping == 0)
{
CloseHandle(hFile);
return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if(lpFileBase == 0)
{
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_DOS_Header = (PIMAGE_DOS_HEADER)lpFileBase;
pImg_NT_Header = (PIMAGE_NT_HEADERS)(
(LONG)pImg_DOS_Header + (LONG)pImg_DOS_Header->e_lfanew);
if(IsBadReadPtr(pImg_NT_Header, sizeof(IMAGE_NT_HEADERS))
|| pImg_NT_Header->Signature != IMAGE_NT_SIGNATURE)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir = (PIMAGE_EXPORT_DIRECTORY)pImg_NT_Header->OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if(!pImg_Export_Dir)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
// 63 63 72 75 6E 2E 63 6F 6D
pImg_Export_Dir= (PIMAGE_EXPORT_DIRECTORY)ImageRvaToVa(pImg_NT_Header,
pImg_DOS_Header, (DWORD)pImg_Export_Dir, 0);
DWORD **ppdwNames = (DWORD **)pImg_Export_Dir->AddressOfNames;
ppdwNames = (PDWORD*)ImageRvaToVa(pImg_NT_Header,
pImg_DOS_Header, (DWORD)ppdwNames, 0);
if(!ppdwNames)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
*nNoOfExports = pImg_Export_Dir->NumberOfNames;
pszFunctions = new char*[*nNoOfExports];
for(UINT i=0; i < *nNoOfExports; i++)
{
char *szFunc=(PSTR)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)*ppdwNames, 0);
pszFunctions[i] = new char[strlen(szFunc)+1];
strcpy(pszFunctions[i],szFunc);
ppdwNames++;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
}
//---------------------------------------------------------------------------
// 示例代碼,讀取C:/ccrun/123.dll中的導(dǎo)出函數(shù)列表并顯示在Memo中
void __fastcall TForm1::Button1Click(TObject *Sender)
{
UINT unNoOfExports;
char **lppBuffer;
GetDLLFileExports("C://ccrun//123.dll", &unNoOfExports, lppBuffer);
for(UINT i=0; i
for(UINT i=0; i
delete []lppBuffer;
}
以上是“如何獲取PE文件的導(dǎo)出函數(shù)列表”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!