#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#include "detours.h"
#pragma comment(lib,"detours.lib")
static
BOOL
(WINAPI *Old_CreateProcessW)(
LPCWSTR
lpApplicationName,
LPWSTR
lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL
bInheritHandles,
DWORD
dwCreationFlags,
LPVOID
lpEnvironment,
LPCWSTR
lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
) = CreateProcessW;
BOOL
New_CreateProcessW(
LPCWSTR
lpApplicationName,
LPWSTR
lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL
bInheritHandles,
DWORD
dwCreationFlags,
LPVOID
lpEnvironment,
LPCWSTR
lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
)
{
MessageBoxA(0,
"success"
,
"success"
, 0);
return
0;
}
void
Hook()
{
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((
void
**)&Old_CreateProcessW, New_CreateProcessW);
DetourTransactionCommit();
}
void
UnHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((
void
**)&Old_CreateProcessW, New_CreateProcessW);
DetourTransactionCommit();
}
_declspec(
dllexport
)
void
go()
{
Hook();
int
i = 0;
while
(1) {
if
(i == 120) {
UnHook();
break
;
}
i++;
Sleep(1000);
}
system
(
"tasklist & pause"
);
}