| 2350 | } |
| 2351 | |
| 2352 | LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer, |
| 2353 | _In_ PVOID pDetour) |
| 2354 | { |
| 2355 | LONG error = NO_ERROR; |
| 2356 | |
| 2357 | if (s_nPendingThreadId != (LONG)GetCurrentThreadId()) { |
| 2358 | return ERROR_INVALID_OPERATION; |
| 2359 | } |
| 2360 | |
| 2361 | // If any of the pending operations failed, then we don't need to do this. |
| 2362 | if (s_nPendingError != NO_ERROR) { |
| 2363 | return s_nPendingError; |
| 2364 | } |
| 2365 | |
| 2366 | if (pDetour == NULL) { |
| 2367 | return ERROR_INVALID_PARAMETER; |
| 2368 | } |
| 2369 | if (ppPointer == NULL) { |
| 2370 | return ERROR_INVALID_HANDLE; |
| 2371 | } |
| 2372 | if (*ppPointer == NULL) { |
| 2373 | error = ERROR_INVALID_HANDLE; |
| 2374 | s_nPendingError = error; |
| 2375 | s_ppPendingError = ppPointer; |
| 2376 | DETOUR_BREAK(); |
| 2377 | return error; |
| 2378 | } |
| 2379 | |
| 2380 | DetourOperation *o = new NOTHROW DetourOperation; |
| 2381 | if (o == NULL) { |
| 2382 | error = ERROR_NOT_ENOUGH_MEMORY; |
| 2383 | fail: |
| 2384 | s_nPendingError = error; |
| 2385 | DETOUR_BREAK(); |
| 2386 | stop: |
| 2387 | if (o != NULL) { |
| 2388 | delete o; |
| 2389 | o = NULL; |
| 2390 | } |
| 2391 | s_ppPendingError = ppPointer; |
| 2392 | return error; |
| 2393 | } |
| 2394 | |
| 2395 | |
| 2396 | #ifdef DETOURS_IA64 |
| 2397 | PPLABEL_DESCRIPTOR ppldTrampo = (PPLABEL_DESCRIPTOR)*ppPointer; |
| 2398 | PPLABEL_DESCRIPTOR ppldDetour = (PPLABEL_DESCRIPTOR)pDetour; |
| 2399 | PVOID pDetourGlobals = NULL; |
| 2400 | PVOID pTrampoGlobals = NULL; |
| 2401 | |
| 2402 | pDetour = (PBYTE)DetourCodeFromPointer(ppldDetour, &pDetourGlobals); |
| 2403 | PDETOUR_TRAMPOLINE pTrampoline = (PDETOUR_TRAMPOLINE) |
| 2404 | DetourCodeFromPointer(ppldTrampo, &pTrampoGlobals); |
| 2405 | DETOUR_TRACE((" ppldDetour=%p, code=%p [gp=%p]\n", |
| 2406 | ppldDetour, pDetour, pDetourGlobals)); |
| 2407 | DETOUR_TRACE((" ppldTrampo=%p, code=%p [gp=%p]\n", |
| 2408 | ppldTrampo, pTrampoline, pTrampoGlobals)); |
| 2409 |
nothing calls this directly
no test coverage detected
searching dependent graphs…