-
February 24th, 2013, 07:24 AM
#1
Detour Trampoline help
Hello there..
IM having a problem with detours automatically calling "int WINAPI my_send". I need to be able to call this from my GUI, That i call externally from the WINAPI MainThread.
IM new to c++ but have been programming in various languages for years. So far ive got pretty far without the need of help. But all this DLL stuff is blowing my mind hehe.
Can someone please explain how i would stop "int WINAPI my_send". Been automatically called when the dll is loaded. So i can then call from my GUI.
Thank you very much.
Gavin
Code:
void WINAPI MainThread( )
{
//This function will run when we attach the DLL
Main(); //located in Form1.cpp, This will load the form and display it
}
//------------------------------------------------------------------
DETOUR_TRAMPOLINE(int WINAPI real_send(SOCKET Socket, char * buffer, int strlen, int flags),send);
//int WINAPI my_send(SOCKET Socket, char FAR* buffer, int strlen, int flags);
int WINAPI my_send(SOCKET Socket, char FAR* buffer, int strlen, int flags){
send(Socket,packet,10,0);
Sleep(500);
send(Socket,packet2,10,0);
return real_send(Socket, buffer, strlen, flags);
}
//------------------------------------------------------------------
//------------------------------------------------------------------
HINSTANCE hinst;
__declspec( dllexport ) LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(0, nCode, wParam, lParam);
};
//------------------------------------------------------------------
BOOL WINAPI DllMain ( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
{
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
if ( CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MainThread, NULL, 0, NULL) == NULL ) {
return FALSE;
}
//------------------------------------------------------------------
DetourFunctionWithTrampoline((PBYTE)real_send,(PBYTE)my_send);
break;
//------------------------------------------------------------------
break;
case DLL_PROCESS_DETACH:
//------------------------------------------------------------------
DetourRemove((PBYTE)real_send,(PBYTE)my_send);
//------------------------------------------------------------------
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
-
February 24th, 2013, 05:30 PM
#2
Re: Detour Trampoline help
What is "int WINAPI my_send" and what does it have to do with the
Forum: Visual C++ Programming
Ask questions about Windows programming with Visual C++ and help others by answering their questions.
Victor Nijegorodov
-
February 25th, 2013, 01:30 AM
#3
Re: Detour Trampoline help
Originally Posted by Things
Hello there..
IM having a problem with detours automatically calling "int WINAPI my_send". I need to be able to call this from my GUI, That i call externally from the WINAPI MainThread.
IM new to c++ but have been programming in various languages for years. So far ive got pretty far without the need of help. But all this DLL stuff is blowing my mind hehe.
Can someone please explain how i would stop "int WINAPI my_send". Been automatically called when the dll is loaded. So i can then call from my GUI.
Gavin, you definitely have to explain the design in whole prior to be advised anything.
The highlighted stuff indicates that despite all of your years of programming you're not very good at explanations, so you need to do your best once again.
From your code I can see that "This is a dll injection, and all the game is about intercepting winsock send for some time. While send remains intercepted it sends predefined data instead of the stuff provided by application..." This is how I would start explaining.
Besides, there definitely must be some problem you say not a word about. As well, you need to explain for the app you intrude into is it okay to lose the data you substitute with your "packets", what your form main purpose is, etc. You say your form needs send later as well, but in your dll code you remove detour on dll unload only. What's the purpose? You use already intercepted send inside your my_send, so are you aware of the consequences? Is it only DLL stuff blowing your mind, or C++ stuff as well? How good you are at compiler and linker stuff?
And finally, do you really need to intercept, or there may be some other solution? Did you ever think of that?
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|