函数-获取模块地址

/// <summary>
/// 获取模块地址
/// </summary>
/// <param name="pid">进程PID</param>
/// <param name="ModuleName">模块名称</param>
/// <param name="StartAddress">开始地址</param>
/// <param name="EndAddress">结束地址</param>
/// <returns></returns>
BOOL ModuleAddress(DWORD pid, wchar_t* ModuleName, QWORD& StartAddress, QWORD& EndAddress)
{
    MODULEENTRY32 me32;//模块结构信息//#include <tlhelp32.h>
    me32.dwSize = sizeof(MODULEENTRY32);
    HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
    if (INVALID_HANDLE_VALUE == handle)
    {
        return FALSE;
    }
    BOOL ret = ::Module32First(handle, &me32);
    while (ret)
    {
        if (wcscmp(me32.szModule, ModuleName) == 0)
        {
            StartAddress = (QWORD)me32.modBaseAddr;
            EndAddress = StartAddress + me32.modBaseSize;
            CloseHandle(handle);
            return TRUE;
        }
        ret = ::Module32Next(handle, &me32);
    }
    CloseHandle(handle);
    return FALSE;
}

 

posted @ 2021-12-27 16:22  梦之心  阅读(314)  评论(0编辑  收藏  举报