Many many thanks for reply, BiggBoss from official l2j board send me a code:
Code:
- #include <windows.h>
- #include <winsock2.h>
- #include <stdlib.h>
- #pragma comment(lib,"ws2_32.lib");
- typedef int (__stdcall* new_connect)(SOCKET socket, sockaddr *name, int namelen);
- new_connect hook;
- int __stdcall InjectedConnect(SOCKET socket, sockaddr *name, int namelen) {
- sockaddr_in * name_in = (sockaddr_in*)name;
- name_in->sin_addr->S_un.S_addr = inet_addr("your.hostname.goes.here");
- return hook(socket,name,namelen);
- }
- void inject() {
- char * alloc_mem = (char*)VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- HMODULE ws2_32 = GetModuleHandle(L"ws2_32.dll");
- if(ws2_32 == 0) {
- ws2_32 = LoadLibrary(L"ws2_32.dll");
- }
- char * old_connect_addr = (char*)GetProcAddress(ws2_32, "connect");
- if(*old_connect_addr == 0xe9) {
- int old_relative = *(int*)(old_connect_addr + 1);
- DWORD32 absolute = (DWORD32)(old_connect_addr + old_relative + 5);
- *alloc_mem = 0xe9;
- *(int*)(alloc_mem + 1) = (int)(absolute - (alloc_mem + 5));
- } else {
- memcpy(alloc_mem,old_connect_addr,5);
- *(alloc_mem + 5)= 0xe9;
- *(int*)(alloc_mem + 6) = (int)(old_connect_addr + 5 - (alloc_mem + 10));
- }
- DWORD prot;
- VirtualProtect(old_connect_addr,5,PAGE_EXECUTE_READWRITE, &prot);
- *old_connect_addr = 0xe9;
- *(int*)(old_connect_addr + 1) = (int)( &InjectedConnect - (old_connect_addr + 5));
- VirtualProtect(old_connect_addr,5,prot,&prot);
- hook = (new_connect)alloc_mem;
- }
- _declspec(dllexport) BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
- if(ul_reason_for_call == DLL_PROCESS_ATTACH || ul_reason_for_call == DLL_THREAD_ATTACH)
- inject();
- return TRUE;
- }
Maybe this is better solution for this?
He recomend me to compile it to dll and add into l2.exe header.
Maybe anyone could write how to do it? What do You think about it?