2013-06-07 3 views
1

나는 우회로를 사용하여 첫 걸쇠를 잡는 데 어려움을 겪고 있습니다. Detour 3.0을 사용하고 있습니다.알려진 메모리 주소를 가진 함수의 단순한 후크를 위해 C++에서 우회 라이브러리를 올바르게 사용하는 방법?

내 코드가 잘 컴파일되고 Winject을 사용하여 DLL을 주입 할 수 있습니다. 그러나 내가 후크하지 않는 기능은 연결되지 않은 것 같습니다. 나는 메모장에 함수 InsertDateTime을 연결하려고합니다.
http://www.9injector.com/winject-injector/

나는 무료 프로 IDA를 사용하여 진수 표기법으로 InsertDateTime의 ADRESS을 발견했다.

아래 코드에서 어떤 펀드얼얼 실수가 있었습니까? 아니면 모든 통화에서 동시에 프로세스가 아닌 메모리가 있습니까? 주입 된 DLL에 대한

내 코드는 아래에 볼 수 있습니다 :

// dllmain.cpp : Defines the entry point for the DLL application. 
#include "stdafx.h" 

#include <windows.h> 
#include "detours.h" 
#pragma comment(lib, "detours.lib") 
// 

int(__stdcall* InsertDateTime)(int) = (int(__stdcall*)(int))(0x0100978A); 
int MyInsertDateTime(int x) //Our function 
{ 
//Messagebox 
MessageBox(NULL, TEXT("InsertDateTime Just Got Called"), TEXT("InsertDateTime"), MB_OK); 
return InsertDateTime(x); //Return the origional function 
} 

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 
{ 
switch (ul_reason_for_call) //Decide what to do 
{ 
case DLL_PROCESS_ATTACH: //On dll attach 
    //InsertDateTime = (int (__stdcall*)(int))DetourAttach((PVOID*)0x0100978A, MyInsertDateTime); 
    //MessageBox(NULL, TEXT("InsertDateTime Just Got Called"), TEXT("InsertDateTime"), MB_OK); 
    DetourAttach((PVOID*)(&InsertDateTime), (PVOID)MyInsertDateTime); 
    //if(!errorCode) { 
    //Detour successful 

break; 
case DLL_THREAD_ATTACH: //On thread attach 
     DetourAttach((PVOID*)(&InsertDateTime), (PVOID)MyInsertDateTime); 
break; 
case DLL_THREAD_DETACH: //On thread detach 
break; 
case DLL_PROCESS_DETACH: //on process detach 
    DetourDetach((PVOID*)0x0100978A, InsertDateTime); 
break; 
} 
return TRUE; 
} 

또한 코드는 대부분 우회 1.5을 사용하여 이전 튜토리얼에서 가져옵니다. 참조 : http://www.moddb.com/groups/ibepex/tutorials/function-hooking

답변

3

Detours는 데이터베이스와 유사한 트랜잭션 시스템을 사용하고 있습니다. Attach 또는 Detach를 호출하기 전에 트랜잭션을 시작해야하며 변경 내용은 트랜잭션을 커밋 할 때만 적용됩니다.

DetourTransactionBegin(); 
DetourAttach(...); 
DetourAttach(...); 
DetourTransactionCommit(); 

이것이 2.0에서 소개 된 것으로 생각합니다. 1.5 용 자습서 코드에이 코드가 포함되어 있지 않은 이유를 설명합니다.