Ignore:
Timestamp:
Dec 16, 2009, 5:15:40 PM (11 years ago)
Author:
Sam Hocevar
Message:

Synchronise VS 2010 solution with [4112].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/myfork.c

    r4122 r4137  
    266266
    267267    /* Get the child process's entry point address */
    268     epaddr = (void *)(get_base_address(pinfo.dwProcessId)
    269                        + get_entry_point_offset(opts->newargv[0]));
     268    epaddr = (void *)get_entry_point(opts->newargv[0],
     269                                     pinfo.dwProcessId);
    270270    if(!epaddr)
    271271        return -1;
     
    414414}
    415415
    416 /* Find the process's base address once it is loaded in memory (the header
    417  * information is unreliable because of Vista's ASLR). */
    418 static intptr_t get_base_address(DWORD pid)
    419 {
    420     MODULEENTRY32 entry;
    421     intptr_t ret = 0;
    422     void *list;
    423     int k;
    424 
    425     list = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
    426     entry.dwSize = sizeof(entry);
    427     for(k = Module32First(list, &entry); k; k = Module32Next(list, &entry))
    428     {
    429         /* FIXME: how do we select the correct module? */
    430         ret = (intptr_t)entry.modBaseAddr;
    431     }
    432     CloseHandle(list);
    433 
    434     return ret;
    435 }
    436 
    437416/* Find the process's entry point address offset. The information is in
    438417 * the file's PE header. */
    439 static intptr_t get_entry_point_offset(char const *name)
     418static intptr_t get_entry_point(char const *name, DWORD pid)
    440419{
    441420    PIMAGE_DOS_HEADER dos;
     
    472451      && nt->OptionalHeader.Magic == 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */)
    473452    {
    474         ret = (intptr_t)nt->OptionalHeader.AddressOfEntryPoint;
     453        ret = get_base_address(pid);
     454        /* Base address not found in the running process. Falling back
     455         * to the header's information, which is unreliable because of
     456         * Vista's address space randomisation. */
     457        if (!ret)
     458            ret = (intptr_t)nt->OptionalHeader.BaseOfCode;
     459
     460        ret += (intptr_t)nt->OptionalHeader.AddressOfEntryPoint;
    475461    }
    476462
     
    481467    return ret;
    482468}
    483 #endif
    484 
     469
     470/* Find the process's base address once it is loaded in memory (the header
     471 * information is unreliable because of Vista's ASLR). */
     472static intptr_t get_base_address(DWORD pid)
     473{
     474    MODULEENTRY32 entry;
     475    intptr_t ret = 0;
     476    void *list;
     477    int k;
     478
     479    list = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
     480    entry.dwSize = sizeof(entry);
     481    for(k = Module32First(list, &entry); k; k = Module32Next(list, &entry))
     482    {
     483        /* FIXME: how do we select the correct module? */
     484        ret = (intptr_t)entry.modBaseAddr;
     485    }
     486    CloseHandle(list);
     487
     488    return ret;
     489}
     490
     491#endif
Note: See TracChangeset for help on using the changeset viewer.