C++ Winsock Hook

Posts 1–6 of 6 · Page 1 of 1
C++ Winsock Hook
Hello, I'm at the moment stuck with some things because I'm searching for a long time for an .dll Winsock hook and I found one


Code:
#include "windows.h"
#include "winsock.h"

#pragma comment ( lib, "Ws2_32.lib" )
#define JMP(frm, to) (int)(((int)to - (int)frm) - 5);

DWORD SendOriginalAddress = 0;
DWORD SendReturnAddress = 0;
DWORD* SendNewAddress = 0;
DWORD OldProtection = 0;

char* send_buffer;
int send_sizeofdata = 0;
SOCKET send_s;
int send_flags = 0;

void __declspec(naked) __stdcall  SendHookFunc() 	
{
	__asm
	{ 
				mov  edi,edi
				push ebp
				mov ebp, esp
				mov eax, [ebp+0x08] /* Param 1 : Socket */
				mov send_s, eax
				mov eax, [ebp+0x0C] /* Param 2 : buffer */
				mov [send_buffer], eax
				mov eax, [ebp+0x10] /*Param 3 : Size*/
				mov send_sizeofdata, eax
				mov eax, [ebp+0x14] /*Param 4 : flags*/
				mov send_flags, eax
				jmp SendReturnAddress
	}
}

void UnHookSend()
{
	/* To unhook on a WinXP post SP2 box you need to restore the 5 byte preamble */
	*(WORD *)SendOriginalAddress = 0xFF8B;		// mov  edi,edi
	*(BYTE *)(SendOriginalAddress+2) = 0x55;	// push epb
	*(WORD *)(SendOriginalAddress+3) = 0xEC8B;	// mov epb, esp
	VirtualProtect( (void*)SendOriginalAddress, 0x05, OldProtection, &OldProtection );
}

void HookSend()
{
	SendNewAddress = (DWORD*)SendHookFunc;
	HINSTANCE hDll = LoadLibrary((LPCTSTR) "Ws2_32.dll"); 
	SendOriginalAddress = (DWORD)GetProcAddress(hDll, "send"); 
	SendReturnAddress = SendOriginalAddress + 5;
	VirtualProtect( (void*)SendOriginalAddress, 0x05, PAGE_READWRITE , &OldProtection );
	*(BYTE *)(SendOriginalAddress) = 0xe9;
	*(int *)(SendOriginalAddress+1) = JMP(SendOriginalAddress, SendNewAddress);
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
		HookSend();
	if (ul_reason_for_call == DLL_THREAD_DETACH)
		UnHookSend();
    return TRUE;
}
But when I compile the .dll its giving me warnings:
Warning 1 warning C4793: 'SendHookFunc' : function compiled as native

Warning 2 warning C4747: Calling managed '_DllMain@12': Managed code may not be run under loader lock, including the DLL entrypoint and calls reached from the DLL entrypoint

And when I use WinJect to inject it to a process (l2.exe) it said this



And then the game just crash and if I attach my .dll to something else like pinball it crash also...


And another question:
How to send packets through the game by using the dll injection
I'm having already the packets I need to send but I just need to know how

(I just named the injection deleteme.dll because I just wanted to test it fast)
hmm , maybe you should try to rewrite the code for winsock , try MSDN , there are sample codes for winsock 6.0 , and then try parsing the code.

OrX
I'm having now a working Injection .dll and I can inject it now to the process with my program but I seriuosly need to know now how to send packets

example..

L2Dragon Packet Hacker -> Get Function Send -> Injection.dll -> Send Packet -> Lineage2
MSCIL, is what managed .NET projects are compiled into, instead of directly executable code. The .NET framework then executes this code and translated it into something readable by the processor. Why this program is stopping MSCIL from executing, I don't know, but you have to reprogram it into something that doesn't make use of the .NET framework. To avoid this error, or you can find a way to fix it.
I fixed already but error but now I need to manage to send packets using the injected .dll
In the process
try to use some game , which is not using any cheatprotect , just simple localhosted wargame or something , and if you work out the way you can send packets to your own local game , then you should be able to send packets to lineage2 , do u even have the packets you want to send? if not , try WPE ( Winsock packet editor) .

OrX
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?