gpt4 book ai didi

c++ - C/C++分配DWORD数组的指针地址

转载 作者:行者123 更新时间:2023-11-28 07:56:31 26 4
gpt4 key购买 nike

我正在编写一个 C/C++ PE 解析库,我在其中使用 DLL 或 exe 来提取有关目录和 header 的信息。我的问题是当我提取导出地址并获取函数地址时,我不知道如何使用该地址将其指向具有导出的导出函数数量的数组

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;

改变指针地址?

最佳答案

address_of_functionsaddress_of_names 字段分别是 RVA 到实际函数入口点和名称的 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了解更多详情。

关于c++ - C/C++分配DWORD数组的指针地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12592821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com