2015-02-06 59 views
0

좋은 아침 :(DetourAttach의 성공은 있지만 기능은 내가 최근에 함수를 후킹에 대한 매우 흥미로운 기사를 읽었습니다!

을 구부려하지, 난 하나 또는 두 개의 튜토리얼을 따랐지만, 나는 우회를 사용하고 작동하는 것 같다없고, 여기에 결코 함수에, 메모리 주소 나에게 완벽하게 정상 :(기능 후크 RemoteDLL 더미와 같은 간단한 콘솔 응용 프로그램을 사용하는 경우

#include <stdio.h> 
#include <windows.h> 

#include "stdafx.h" 
#include "detours.h" 

#pragma comment(lib, "detours.lib") 

int(__stdcall* realFunc)(int) = (int(__stdcall*)(int))(0x004157B0); 

void hookedFunc(int num) 
{ 
    printf("Test : %d\n", num + 100); 
} 

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 
{ 
    switch (ul_reason_for_call) 
    { 
    case DLL_PROCESS_ATTACH: 
     DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc); 
     break; 
    case DLL_THREAD_ATTACH: 
     DetourTransactionBegin(); 
     DetourUpdateThread(GetCurrentThread()); 
     DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc); 
     DetourTransactionCommit(); 
     hookedFunc(100); 
     break; 
    case DLL_THREAD_DETACH: 
     break; 
    case DLL_PROCESS_DETACH: 
     DetourDetach((PVOID*)0x004157B0, hookedFunc); 
     break; 
    } 
    return TRUE; 
} 

이 모든 단계 (관리자로 실행) 성공적으로 완료 보인다 전체 코드 내가 매치되고 싶지만 코드 라인 "printf ("Test : % d \ n ", num + 100);"이 실행되지 않으면 res 궁극적으로 화면에 나타나지 않습니다 ...

아무도 무슨 일이 일어나고 있는지에 대한 아이디어가 있다면 나는 정말로 그것을 듣고 기뻐할 것입니다!

미리 감사드립니다.

답변

0

먼저 hookedFunc에는 동일한 시그니처가 있어야합니다. int __stdcall hookedFunc (int x).

코드의 효과는 다음과 같습니다. hookedFunc는 누군가 0x004157B0 주소에서 함수를 호출 할 때마다 호출됩니다. 그것은 당신이 기대하는 것입니까?

테스트를 위해이 주소로 전화하십시오. 조금 명확하게 코드를 변경하겠습니다.

extern int __stdcall FunctionIWantToHook(int); 
int(__stdcall* realFunc)(int) = FunctionIWantToHook; 

... 
DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc); 
FunctionIWantToHook(100); // hookedFunc will be called here 
+0

답장을 보내 주셔서 감사합니다. 내가 원했던 것은 0x004157B0 주소의 함수에 연결하는 것입니다.이 함수는 메시지 만 표시합니다. 새 메시지를 표시하여 변경하려고했지만 개념을 잘못 이해했거나 잊어 버렸을 수 있습니다. 논문을 분리 할 다음 줄 : \t \t DetourTransactionBegin(); \t \t DetourUpdateThread (GetCurrentThread()); \t \t DetourDetach (& (PVOID &) realFunc, hookedFunc); \t \t DetourTransactionCommit(); 주사가 더 이상 작동하지 않고 RemoteDLL의 4 단계에서 실패합니다. – coldZou