当我将这个dll注入程序时,程序在遇到函数memcpy时崩溃。
我想用弯道钩住函数memcpy。 请帮助。
#include <windows.h>
#include<iostream>
#include "detours\detours.h"
#pragma comment( lib, "msvcrt.lib" )
#pragma comment( lib, "detours.lib" )
void * (__cdecl *memcpy_o)(void *dest, const void *src, size_t count);
void* __cdecl Mine_Memcpy(void *dest, const void *src, size_t count) {
char cislo[24]; // just big enough
void* asd = &memcpy;
sprintf(cislo,"0x%08x", &asd);
MessageBoxA(0, cislo, cislo, 0);
return memcpy_o(dest, src, count);
}
BOOL WINAPI DllMain(HINSTANCE, DWORD dwReason, LPVOID) {
HANDLE memcpy_get = GetProcAddress(GetModuleHandleA("msvcrt"), "memcpy");
switch (dwReason) {
case DLL_PROCESS_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
memcpy_o = (void * (__cdecl *)(void *dest, const void *src, size_t count))DetourAttach(&(PVOID&)memcpy_get, Mine_Memcpy);
DetourTransactionCommit();
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID &)memcpy_o, Mine_Memcpy);
DetourTransactionCommit();
break;
}
return TRUE;
}
我将这个dll注入程序。什么时候使用mecpy程序停止工作请帮忙,哪里出错?