Changeset 4137 for zzuf/trunk/src
- Timestamp:
- Dec 16, 2009, 5:15:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/myfork.c
r4122 r4137 266 266 267 267 /* 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); 270 270 if(!epaddr) 271 271 return -1; … … 414 414 } 415 415 416 /* Find the process's base address once it is loaded in memory (the header417 * 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 437 416 /* Find the process's entry point address offset. The information is in 438 417 * the file's PE header. */ 439 static intptr_t get_entry_point _offset(char const *name)418 static intptr_t get_entry_point(char const *name, DWORD pid) 440 419 { 441 420 PIMAGE_DOS_HEADER dos; … … 472 451 && nt->OptionalHeader.Magic == 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */) 473 452 { 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; 475 461 } 476 462 … … 481 467 return ret; 482 468 } 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). */ 472 static 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.