windows - C ++ BaseAddress og indtastningsadresse

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg ved, at i c # kan jeg gøre:


Process currentProcess  = System.Diagnostics.Process.GetCurrentProcess();

currentProcess.Modules[0].BaseAddress
currentProcess.Modules[0].EntryPointAddress


Hvordan vil jeg få disse oplysninger i C ++?


Tager et kig jeg har:


void
get\_module\_name\_for\_address(LPVOID address,
                            TCHAR *buf, int buf\_size)
{
    HANDLE process;
    HMODULE modules[256];
    DWORD bytes\_needed, num\_modules;
    unsigned int i;

    buf[0] = '';

    process = GetCurrentProcess();

    if (EnumProcessModules(process, (HMODULE *) &modules,
                           sizeof(modules), &bytes\_needed) == 0)
    {
        return;
    }

    if (bytes\_needed > sizeof(modules))
        bytes\_needed = sizeof(modules);

    num\_modules = bytes\_needed / sizeof(HMODULE);

    for (i = 0; i < num\_modules; i++)
    {
        MODULEINFO mi;

        if (GetModuleInformation(process, modules[i], &mi, sizeof(mi)) != 0)
        {
            LPVOID start, end;

            start = mi.lpBaseOfDll;
            end = (char *) start + mi.SizeOfImage;

            if (address >= start && address <= end)
            {
                GetModuleBaseName(process, modules[i], buf, buf\_size);
                return;
            }
        }
    }
}

Bedste reference


GetModuleInformation () i ustyret kode: http://msdn.microsoft.com/en-us/library/ms683201\%28v=VS.85\%29.aspx[3]