/util/drmingw: 005749a4d596: Use the full path to IMAGEHLP.DLL i...

Daniel Atallah datallah at pidgin.im
Mon Sep 10 12:11:13 EDT 2012


Changeset: 005749a4d5967b1c109896b478ded78ffe182184
Author:	 Daniel Atallah <datallah at pidgin.im>
Date:	 2012-09-08 12:49 -0400
Branch:	 default
URL: http://hg.pidgin.im/util/drmingw/rev/005749a4d596

Description:

Use the full path to IMAGEHLP.DLL in the Windows System directory for LoadLibrary.

This is probably not necessary because IMAGEHLP.DLL is a "known DLL", but this
is less questionable.

diffstat:

 exchndl.c |  32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

diffs (105 lines):

diff --git a/exchndl.c b/exchndl.c
--- a/exchndl.c
+++ b/exchndl.c
@@ -206,6 +206,20 @@ BOOL BfdGetLineFromAddr(bfd *abfd, asymb
 static BOOL bSymInitialized = FALSE;
 
 static HMODULE hModule_Imagehlp = NULL;
+static HMODULE get_imagehlp_module() {
+	if (!hModule_Imagehlp) {
+		/* It's probably not necessary to load this using a full path
+		 * because IMAGEHLP.DLL should be a "known DLL", but this looks
+		 * less questionable */
+		const TCHAR *dllname = _T("\\IMAGEHLP.DLL");
+		TCHAR dll_full_path[MAX_PATH];
+		if (GetSystemDirectory(dll_full_path, MAX_PATH - _tcslen(dllname))) {
+			_tcscat(dll_full_path, dllname);
+			hModule_Imagehlp = LoadLibrary(dll_full_path);
+		}
+	}
+	return hModule_Imagehlp;
+}
 
 typedef BOOL (WINAPI *PFNSYMINITIALIZE)(HANDLE, LPSTR, BOOL);
 static PFNSYMINITIALIZE pfnSymInitialize = NULL;
@@ -214,7 +228,7 @@ static
 BOOL WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) GetProcAddress(hModule_Imagehlp, "SymInitialize")))
 	)
 		return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess);
@@ -229,7 +243,7 @@ static
 BOOL WINAPI j_SymCleanup(HANDLE hProcess)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymCleanup || (pfnSymCleanup = (PFNSYMCLEANUP) GetProcAddress(hModule_Imagehlp, "SymCleanup")))
 	)
 		return pfnSymCleanup(hProcess);
@@ -244,7 +258,7 @@ static
 DWORD WINAPI j_SymSetOptions(DWORD SymOptions)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) GetProcAddress(hModule_Imagehlp, "SymSetOptions")))
 	)
 		return pfnSymSetOptions(SymOptions);
@@ -259,7 +273,7 @@ static
 BOOL WINAPI j_SymUnDName(PIMAGEHLP_SYMBOL Symbol, PSTR UnDecName, DWORD UnDecNameLength)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymUnDName || (pfnSymUnDName = (PFNSYMUNDNAME) GetProcAddress(hModule_Imagehlp, "SymUnDName")))
 	)
 		return pfnSymUnDName(Symbol, UnDecName, UnDecNameLength);
@@ -274,7 +288,7 @@ static
 PVOID WINAPI j_SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymFunctionTableAccess || (pfnSymFunctionTableAccess = (PFNSYMFUNCTIONTABLEACCESS) GetProcAddress(hModule_Imagehlp, "SymFunctionTableAccess")))
 	)
 		return pfnSymFunctionTableAccess(hProcess, AddrBase);
@@ -289,7 +303,7 @@ static
 DWORD WINAPI j_SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymGetModuleBase || (pfnSymGetModuleBase = (PFNSYMGETMODULEBASE) GetProcAddress(hModule_Imagehlp, "SymGetModuleBase")))
 	)
 		return pfnSymGetModuleBase(hProcess, dwAddr);
@@ -314,7 +328,7 @@ BOOL WINAPI j_StackWalk(
 )
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnStackWalk || (pfnStackWalk = (PFNSTACKWALK) GetProcAddress(hModule_Imagehlp, "StackWalk")))
 	)
 		return pfnStackWalk(
@@ -339,7 +353,7 @@ static
 BOOL WINAPI j_SymGetSymFromAddr(HANDLE hProcess, DWORD Address, PDWORD Displacement, PIMAGEHLP_SYMBOL Symbol)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymGetSymFromAddr || (pfnSymGetSymFromAddr = (PFNSYMGETSYMFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetSymFromAddr")))
 	)
 		return pfnSymGetSymFromAddr(hProcess, Address, Displacement, Symbol);
@@ -354,7 +368,7 @@ static
 BOOL WINAPI j_SymGetLineFromAddr(HANDLE hProcess, DWORD dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE Line)
 {
 	if(
-		(hModule_Imagehlp || (hModule_Imagehlp = LoadLibrary(_T("IMAGEHLP.DLL")))) &&
+		get_imagehlp_module() &&
 		(pfnSymGetLineFromAddr || (pfnSymGetLineFromAddr = (PFNSYMGETLINEFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetLineFromAddr")))
 	)
 		return pfnSymGetLineFromAddr(hProcess, dwAddr, pdwDisplacement, Line);



More information about the Commits mailing list