From 8254c1da586531fe73f3a99ba79921d83c06dacd Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 18 Mar 2017 01:43:51 +0100 Subject: [PATCH] Increased safety of INI path query --- SilentPatchSA/SilentPatchSA.cpp | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 491c746..7c9b7cb 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1985,14 +1985,8 @@ BOOL InjectDelayedPatches_10() // Obtain a path to the ASI wchar_t wcModulePath[MAX_PATH]; - - GetModuleFileNameW(hDLLModule, wcModulePath, MAX_PATH); - - // ASI -> INI - size_t nLen = wcslen(wcModulePath); - wcModulePath[nLen-1] = L'i'; - wcModulePath[nLen-2] = L'n'; - wcModulePath[nLen-3] = L'i'; + GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension + PathRenameExtensionW(wcModulePath, L".ini"); bool bHasImVehFt = GetModuleHandle("ImVehFt.asi") != nullptr; bool bSAMP = GetModuleHandle("samp") != nullptr; @@ -2213,14 +2207,8 @@ BOOL InjectDelayedPatches_11() // Obtain a path to the ASI wchar_t wcModulePath[MAX_PATH]; - - GetModuleFileNameW(hDLLModule, wcModulePath, MAX_PATH); - - // ASI -> INI - size_t nLen = wcslen(wcModulePath); - wcModulePath[nLen-1] = L'i'; - wcModulePath[nLen-2] = L'n'; - wcModulePath[nLen-3] = L'i'; + GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension + PathRenameExtensionW(wcModulePath, L".ini"); bool bHasImVehFt = GetModuleHandle("ImVehFt.asi") != nullptr; bool bSAMP = GetModuleHandle("samp") != nullptr; @@ -2438,14 +2426,8 @@ BOOL InjectDelayedPatches_Steam() // Obtain a path to the ASI wchar_t wcModulePath[MAX_PATH]; - - GetModuleFileNameW(hDLLModule, wcModulePath, MAX_PATH); - - // ASI -> INI - size_t nLen = wcslen(wcModulePath); - wcModulePath[nLen-1] = L'i'; - wcModulePath[nLen-2] = L'n'; - wcModulePath[nLen-3] = L'i'; + GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension + PathRenameExtensionW(wcModulePath, L".ini"); bool bHasImVehFt = GetModuleHandle("ImVehFt.asi") != nullptr; bool bSAMP = GetModuleHandle("samp") != nullptr;