如何获取特定地址处符号的名称/导出索引(GetProcAddress 逆)

发布于 2024-11-27 17:45:48 字数 1543 浏览 1 评论 0原文

假设我有一个导出一些函数的 DLL,并且我知道该 DLL 中的地址。 如果该地址引用此类函数内的位置,那么,假设导出表按函数条目排序,以下内容将在导出中找到该函数的索引table:

IMAGE_DOS_HEADER* dosHeader;
dosHeader = (IMAGE_DOS_HEADER*)m_handle;
unsigned int count;

if(dosHeader->e_magic != IMAGE_DOS_SIGNATURE)
{return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_NT_HEADERS* ntHeaders = (IMAGE_NT_HEADERS*)(((BYTE*)dosHeader) + dosHeader->e_lfanew);

if(ntHeaders->Signature != 0x00004550)
    {return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_OPTIONAL_HEADER* optionalHeader = &ntHeaders->OptionalHeader;
if(optionalHeader->NumberOfRvaAndSizes<IMAGE_DIRECTORY_ENTRY_EXPORT)
    {return __MODULE_ADDRESS_NOT_FOUND;}

if(optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size==0)
    {return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_DATA_DIRECTORY* dataDirectory = &optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
IMAGE_EXPORT_DIRECTORY* Exp;
Exp = (IMAGE_EXPORT_DIRECTORY*)((DWORD)dosHeader + dataDirectory->VirtualAddress);

ULONG* addressoffunctions=(ULONG*)((BYTE*) m_handle + Exp->AddressOfFunctions);

if(Exp->NumberOfNames==1)
{
    if(addressoffunctions[0] + (BYTE*)m_handle < address)
        {return 0;}
    return __MODULE_ADDRESS_NOT_FOUND;
    }

for(count = 1; count < Exp->NumberOfNames; count++)
    {
    if(addressoffunctions[count-1] + (BYTE*)m_handle >= address
    && addressoffunctions[count] + (BYTE*)m_handle < address)
        {return count-1;}
    }

,但是如何断言该地址确实引用导出函数中的位置。

Suppose I have a DLL that exports some functions and I know an address within that DLL. If that address refers to an location within such a function, then, assuming the export table is sorted by function entry, the following would find the index of this function in the export table:

IMAGE_DOS_HEADER* dosHeader;
dosHeader = (IMAGE_DOS_HEADER*)m_handle;
unsigned int count;

if(dosHeader->e_magic != IMAGE_DOS_SIGNATURE)
{return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_NT_HEADERS* ntHeaders = (IMAGE_NT_HEADERS*)(((BYTE*)dosHeader) + dosHeader->e_lfanew);

if(ntHeaders->Signature != 0x00004550)
    {return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_OPTIONAL_HEADER* optionalHeader = &ntHeaders->OptionalHeader;
if(optionalHeader->NumberOfRvaAndSizes<IMAGE_DIRECTORY_ENTRY_EXPORT)
    {return __MODULE_ADDRESS_NOT_FOUND;}

if(optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size==0)
    {return __MODULE_ADDRESS_NOT_FOUND;}

IMAGE_DATA_DIRECTORY* dataDirectory = &optionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
IMAGE_EXPORT_DIRECTORY* Exp;
Exp = (IMAGE_EXPORT_DIRECTORY*)((DWORD)dosHeader + dataDirectory->VirtualAddress);

ULONG* addressoffunctions=(ULONG*)((BYTE*) m_handle + Exp->AddressOfFunctions);

if(Exp->NumberOfNames==1)
{
    if(addressoffunctions[0] + (BYTE*)m_handle < address)
        {return 0;}
    return __MODULE_ADDRESS_NOT_FOUND;
    }

for(count = 1; count < Exp->NumberOfNames; count++)
    {
    if(addressoffunctions[count-1] + (BYTE*)m_handle >= address
    && addressoffunctions[count] + (BYTE*)m_handle < address)
        {return count-1;}
    }

, but how do I assert that the address really refers to an location within an exported function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞳孔里扚悲伤 2024-12-04 17:45:49

在一般情况下,你不能。您应该反汇编整个函数指令图以获取其所有指令的地址。

在一些小情况下,您可以搜索ret指令,但它并不可靠。

如果可以进行静态分析,就可以使用IDA来获取函数边界。

In common case, you can't. You should disassemble whole function instructions graph to get addresses of all its instructions.

In some trivial cases, you can search for ret instruction, but it's not reliable.

If you can perform static analysis, you can use IDA to get function boundaries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文