MCPcopy Create free account
hub / github.com/ConEmu/ConEmu / PrepareHookModule

Function PrepareHookModule

src/ConEmuCD/InjectRemote.cpp:221–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221CINFILTRATE_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))

Callers 1

InjectRemoteFunction · 0.85

Calls 8

wcscat_cFunction · 0.85
DirectoryExistsFunction · 0.85
FileExistsFunction · 0.85
FileCompareFunction · 0.85
wcscpy_cFunction · 0.85
PointToExtFunction · 0.85
msprintfFunction · 0.85
swprintf_cFunction · 0.50

Tested by

no test coverage detected