| 219 | } |
| 220 | |
| 221 | CINFILTRATE_EXIT_CODES PrepareHookModule(wchar_t (&szModule)[MAX_PATH+16]) |
| 222 | { |
| 223 | CINFILTRATE_EXIT_CODES iRc = CIR_GeneralError/*-1*/; |
| 224 | wchar_t szNewPath[MAX_PATH + 16] = L""; |
| 225 | wchar_t szAddName[40] = L""; |
| 226 | wchar_t szMinor[8] = L""; |
| 227 | lstrcpyn(szMinor, WSTRING(MVV_4a), countof(szMinor)); |
| 228 | size_t nLen = 0; |
| 229 | bool bAlreadyExists = false; |
| 230 | |
| 231 | // Copy szModule to CSIDL_LOCAL_APPDATA and return new path |
| 232 | const HRESULT hr = SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0/*SHGFP_TYPE_CURRENT*/, szNewPath); |
| 233 | if ((hr != S_OK) || (szNewPath[0] == L'\0')) |
| 234 | { |
| 235 | iRc = CIR_SHGetFolderPath/*-251*/; |
| 236 | goto wrap; |
| 237 | } |
| 238 | |
| 239 | swprintf_c(szAddName, |
| 240 | L"\\" CEDEFTERMDLLFORMAT /*L"ConEmuHk%s.%02u%02u%02u%s.dll"*/, |
| 241 | WIN3264TEST(L"",L"64"), MVV_1, MVV_2, MVV_3, szMinor); |
| 242 | |
| 243 | nLen = wcslen(szNewPath); |
| 244 | if (szNewPath[nLen-1] != L'\\') |
| 245 | { |
| 246 | szNewPath[nLen++] = L'\\'; szNewPath[nLen] = 0; |
| 247 | } |
| 248 | |
| 249 | if ((nLen + wcslen(szAddName) + 8) >= countof(szNewPath)) |
| 250 | { |
| 251 | iRc = CIR_TooLongTempPath/*-252*/; |
| 252 | goto wrap; |
| 253 | } |
| 254 | |
| 255 | wcscat_c(szNewPath, L"ConEmu"); |
| 256 | if (!DirectoryExists(szNewPath)) |
| 257 | { |
| 258 | if (!CreateDirectory(szNewPath, nullptr)) |
| 259 | { |
| 260 | iRc = CIR_CreateTempDirectory/*-253*/; |
| 261 | goto wrap; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | wcscat_c(szNewPath, szAddName); |
| 266 | |
| 267 | if (((bAlreadyExists = FileExists(szNewPath))) && FileCompare(szNewPath, szModule)) |
| 268 | { |
| 269 | // OK, file exists and match the required |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | if (bAlreadyExists) |
| 274 | { |
| 275 | _ASSERTE(FALSE && "Continue to overwrite existing ConEmuHk in AppLocal"); |
| 276 | |
| 277 | // Try to delete or rename old version |
| 278 | if (!DeleteFile(szNewPath)) |
no test coverage detected