我正在编写一个C / C ++ PE解析库,我使用DLL或exe来提取有关目录和头文件的信息。我的问题是当我提取导出地址并获取函数的地址时,我不知道如何使用该地址将其指向具有导出导出函数数量的数组
DWORD ExportRVA = PEHeader->optional.data_directory[0].virtual_address;
image_export_directory* Exports = (image_export_directory*)(RVAToOffset(ExportRVA)+BaseAddress);
ExportTable.nNames = Exports->number_of_names;
ExportTable.nFunctions = Exports->number_of_functions;
ExportTable.pFunctions = Exports->address_of_functions;
ExportTable.nNames = Exports->address_of_names;
ExportTable.pNamesOrdinals = Exports->address_of_name_ordinals;
我是否必须指定一个指向数组的指针,如
DWORD * AddrFunctions;
更改指针地址?
答案 0 :(得分:1)
address_of_functions
和address_of_names
字段分别是实际功能入口点和名称的RVAs数组的RVA,而address_of_name_ordinals
字段是WORD值数组的RVA ,例如:
#define RVAToPtr(RVA) ( ((LPBYTE)BaseAddress) + ((DWORD)(RVA)) )
image_export_directory* Exports = (image_export_directory*) RVAToPtr(PEHeader->optional.data_directory[0].virtual_address);
ExportTable.nFunctions = Exports->number_of_functions;
ExportTable.nNames = Exports->number_of_names;
ExportTable.pFunctions = (PDWORD) RVAToPtr(Exports->address_of_functions);
ExportTable.pNames = (PDWORD) RVAToPtr(Exports->address_of_names);
ExportTable.pNamesOrdinals = (PWORD) RVAToPtr(Exports->address_of_name_ordinals);
for (DWORD i = 0; i < ExportTable.nFunctions; ++i)
{
void *FuncPtr = (void*) RVAToPtr(ExportTable.pFunctions[i]);
char* FuncName = (char*) RVAToPtr(ExportTable.pNames[i]);
WORD FuncOrdinal = ExportTable.Base + ExportTable.pNamesOrdinals[i];
...
}
有关详细信息,请参阅MSDN。