From 36d0ed7e5747d8c88e66a2854370096dd4941fed Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 16 Dec 2009 16:15:40 +0000 Subject: [PATCH] Synchronise VS 2010 solution with [4112]. --- msvc/config.h | 2 +- msvc/libzzuf.vcxproj | 49 ++++++++++++++++++------------------ msvc/zzuf.vcxproj | 42 +++++++++++++++---------------- src/myfork.c | 59 +++++++++++++++++++++++++------------------- 4 files changed, 80 insertions(+), 72 deletions(-) diff --git a/msvc/config.h b/msvc/config.h index e7192ec..b5d82cd 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -131,7 +131,7 @@ /* Fucking Visual Studio should just shut the fuck up with this fucking * warning about fucking ISO C++ when we fucking compile fucking C. */ -#pragma warning(disable: 4996) +#pragma warning(disable: 4996) /* Win32-specific, of course. */ typedef signed long long int int64_t; diff --git a/msvc/libzzuf.vcxproj b/msvc/libzzuf.vcxproj index 2ffa6f2..e28f720 100644 --- a/msvc/libzzuf.vcxproj +++ b/msvc/libzzuf.vcxproj @@ -51,7 +51,7 @@ Disabled - ..\msvc;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) true EnableFastChecks @@ -78,7 +78,7 @@ - ..\msvc;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDLL $(IntDir).libs/ @@ -104,30 +104,31 @@ - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + diff --git a/msvc/zzuf.vcxproj b/msvc/zzuf.vcxproj index b65b37c..595bb3b 100644 --- a/msvc/zzuf.vcxproj +++ b/msvc/zzuf.vcxproj @@ -51,7 +51,7 @@ Disabled - ..\msvc;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true EnableFastChecks @@ -73,7 +73,7 @@ - ..\msvc;%(AdditionalIncludeDirectories) + ..\msvc;..\src\common;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -93,29 +93,29 @@ - - - - - - - - - - $(IntDir)%(FileName)1.obj - $(IntDir)%(FileName)1.obj - - - - - - + + + + + + - - + + + + + + + + + + + + + diff --git a/src/myfork.c b/src/myfork.c index a84da42..3d351b4 100644 --- a/src/myfork.c +++ b/src/myfork.c @@ -265,8 +265,8 @@ static int run_process(struct opts *opts, int pipes[][2]) return -1; /* Get the child process's entry point address */ - epaddr = (void *)(get_base_address(pinfo.dwProcessId) - + get_entry_point_offset(opts->newargv[0])); + epaddr = (void *)get_entry_point(opts->newargv[0], + pinfo.dwProcessId); if(!epaddr) return -1; @@ -413,30 +413,9 @@ static int dll_inject(void *process, void *epaddr, char const *lib) return 0; } -/* Find the process's base address once it is loaded in memory (the header - * information is unreliable because of Vista's ASLR). */ -static intptr_t get_base_address(DWORD pid) -{ - MODULEENTRY32 entry; - intptr_t ret = 0; - void *list; - int k; - - list = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); - entry.dwSize = sizeof(entry); - for(k = Module32First(list, &entry); k; k = Module32Next(list, &entry)) - { - /* FIXME: how do we select the correct module? */ - ret = (intptr_t)entry.modBaseAddr; - } - CloseHandle(list); - - return ret; -} - /* Find the process's entry point address offset. The information is in * the file's PE header. */ -static intptr_t get_entry_point_offset(char const *name) +static intptr_t get_entry_point(char const *name, DWORD pid) { PIMAGE_DOS_HEADER dos; PIMAGE_NT_HEADERS nt; @@ -471,7 +450,14 @@ static intptr_t get_entry_point_offset(char const *name) && nt->FileHeader.Machine == IMAGE_FILE_MACHINE_I386 && nt->OptionalHeader.Magic == 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */) { - ret = (intptr_t)nt->OptionalHeader.AddressOfEntryPoint; + ret = get_base_address(pid); + /* Base address not found in the running process. Falling back + * to the header's information, which is unreliable because of + * Vista's address space randomisation. */ + if (!ret) + ret = (intptr_t)nt->OptionalHeader.BaseOfCode; + + ret += (intptr_t)nt->OptionalHeader.AddressOfEntryPoint; } UnmapViewOfFile(base); @@ -480,5 +466,26 @@ static intptr_t get_entry_point_offset(char const *name) return ret; } -#endif +/* Find the process's base address once it is loaded in memory (the header + * information is unreliable because of Vista's ASLR). */ +static intptr_t get_base_address(DWORD pid) +{ + MODULEENTRY32 entry; + intptr_t ret = 0; + void *list; + int k; + + list = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); + entry.dwSize = sizeof(entry); + for(k = Module32First(list, &entry); k; k = Module32Next(list, &entry)) + { + /* FIXME: how do we select the correct module? */ + ret = (intptr_t)entry.modBaseAddr; + } + CloseHandle(list); + + return ret; +} + +#endif