Skip to content

Commit 8298cdc

Browse files
committed
delete the payload after finish associated task, and need change the DETOUR_EXE_RESTORE_GUID's value for compatible with these dlls that compiled by old version Detours
1 parent a3e8ba1 commit 8298cdc

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/creatwth.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define DETOURS_INTERNAL
1212
#include "detours.h"
1313
#include <stddef.h>
14+
#include <assert.h>
1415

1516
#if DETOURS_VERSION != 0x4c0c1 // 0xMAJORcMINORcPATCH
1617
#error detours.h version mismatch
@@ -1050,6 +1051,18 @@ VOID CALLBACK DetourFinishHelperProcess(_In_ HWND,
10501051
rlpDlls = NULL;
10511052
}
10521053

1054+
//Delete the payload after execution to release the memory occupied by it
1055+
if (s_pHelper != NULL)
1056+
{
1057+
HMODULE hModule = DetourGetContainingModule(s_pHelper);
1058+
assert(hModule != NULL);
1059+
if (hModule != NULL)
1060+
{
1061+
VirtualFree(hModule, 0, MEM_RELEASE);
1062+
hModule = NULL;
1063+
}
1064+
}
1065+
10531066
ExitProcess(Result);
10541067
}
10551068

src/modules.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// #define DETOUR_DEBUG 1
1313
#define DETOURS_INTERNAL
1414
#include "detours.h"
15+
#include <assert.h>
1516

1617
#if DETOURS_VERSION != 0x4c0c1 // 0xMAJORcMINORcPATCH
1718
#error detours.h version mismatch
@@ -23,8 +24,8 @@
2324
//////////////////////////////////////////////////////////////////////////////
2425
//
2526
const GUID DETOUR_EXE_RESTORE_GUID = {
26-
0x2ed7a3ff, 0x3339, 0x4a8d,
27-
{ 0x80, 0x5c, 0xd4, 0x98, 0x15, 0x3f, 0xc2, 0x8f }};
27+
0xbda26f34, 0xbc82, 0x4829,
28+
{ 0x9e, 0x64, 0x74, 0x2c, 0x4, 0xc8, 0x4f, 0xa0 } };
2829

2930
//////////////////////////////////////////////////////////////////////////////
3031
//
@@ -886,6 +887,17 @@ BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData,
886887
}
887888
VirtualProtect(pder->pidh, pder->cbidh, dwPermIdh, &dwIgnore);
888889
}
890+
//Delete the payload after successful recovery to prevent repeated recovery
891+
if (fSucceeded)
892+
{
893+
HMODULE hModule = DetourGetContainingModule(pder);
894+
assert(hModule != NULL);
895+
if (hModule != NULL)
896+
{
897+
VirtualFree(hModule, 0, MEM_RELEASE);
898+
hModule = NULL;
899+
}
900+
}
889901
return fSucceeded;
890902
}
891903

0 commit comments

Comments
 (0)