View Single Post
Old 21.09.2006, 13:54   #1
x64
Архивный участник
 
Join Date: Sep 2006
Posts: 4
Default [SHARE]Source code of l2auth.dll(For C5 client),All language!

// l2auth.cpp : DLL Entry
//

#include "stdafx.h"
#include "tchar.h"

HMODULE g_hEngine;

bool __stdcall GetServerInfo(void);
void __stdcall MemPatch(void);

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox(NULL,_T("Loading Extender...\n\nWrite by x64(99nets)"),
_T("Notice"),MB_OK);

g_hEngine = GetModuleHandle(_T("Engine.dll"));

//DebugBreak();
if(GetServerInfo() == FALSE) return FALSE;

MemPatch();
break;
default:
break;
}

return TRUE;
}


//===============================================
//patch.cpp
//===============================================

#include "stdafx.h"
#include "tchar.h"

#define SYSTEM_LANG_CN 0x01
#define SYSTEM_LANG_TW 0x02
#define SYSTEM_LANG_EN 0x03
#define SYSTEM_LANG_KR 0x04

int ppOffset[4][3] = {{0x0FA1AD,0x101EF8,0x550440+0x0B}, //cn
{0x0FA1AD,0x101EF8,0x550440+0x0B}, //tw
{0x0FA25D,0x101FE8,0x550480+0x0B}, //en 0x00508926
{0x0FA25D,0x101FE8,0x550480+0x0B}}; //kr

extern HMODULE g_hEngine;
char g_szServerAddr[MAX_PATH] = "127.0.0.1";
char g_szRevison[MAX_PATH];
int g_nServerPort = 2106;
char szRequestAuthLogin[] = "cxxdh";
int g_nSystemLang;
char szRevison693[] = "693";

void __stdcall ReplaceMem(BYTE *pbMemAddr,const BYTE *pbMemData,int nLen)
{
DWORD dwProtectFlag;

VirtualProtect(pbMemAddr,nLen,PAGE_EXECUTE_READWRI TE,&dwProtectFlag);
memcpy(pbMemAddr,pbMemData,nLen);
VirtualProtect(pbMemAddr,nLen,dwProtectFlag,NULL);

return;
}

bool __stdcall GetServerInfo(void)
{
HANDLE hIniFile;
char szFilePath[MAX_PATH];

GetCurrentDirectory(MAX_PATH,szFilePath);
lstrcat(szFilePath,_T("\\l2.ini"));
hIniFile = CreateFile(szFilePath,GENERIC_READ,FILE_SHARE_READ ,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hIniFile != INVALID_HANDLE_VALUE)
{
CloseHandle(hIniFile);
}
else
{
MessageBox(NULL,_T("Can't open config file!"),"WARNNING",MB_OK | MB_ICONSTOP);
return FALSE;
}

GetPrivateProfileStringA("URL","ServerAddr","auth. lineage2.com.cn",
g_szServerAddr,MAX_PATH,".\\l2.ini");
GetPrivateProfileStringA("URL","SvrRevison",szRevi son693,
g_szRevison,MAX_PATH,".\\l2.ini");
g_nServerPort = GetPrivateProfileInt(_T("URL"),_T("ServerPort"),21 06,_T(".\\l2.ini"));
g_nSystemLang = GetPrivateProfileInt(_T("URL"),_T("SystemLang"),0, _T(".\\l2.ini"));
if((g_nSystemLang <= 0) || (g_nSystemLang >= 5)) return FALSE;

return TRUE;
}


__declspec(naked) void SetServerInfo(void)
{
__asm push ecx //save object pointer

lstrlenA(g_szServerAddr);
__asm
{
mov ecx,dword ptr [esp]
push eax
lea eax,g_szServerAddr
lea ecx,dword ptr [ecx+4858h]
push eax
push ecx
call ReplaceMem
}

__asm pop ecx

__asm
{
pop eax //the return address
push g_nServerPort

jmp eax
}
}

__declspec(naked) void RequestAuthLogin(void)
{
__asm
{
push 0
push 8h

lea edx,[esp+44h]
push edx
push 10h
lea edx,[esp+3Eh]
push edx
push 0Eh

push 0 ;OPCode
lea eax,szRequestAuthLogin
push eax
mov ecx,dword ptr [esp+41FCh]
mov ecx,dword ptr [ecx+4Ch]
mov eax,[ecx]
push ecx
call dword ptr [eax+64h]
add esp,24h

pop ecx //the return address

//code that we have replaced
pop edi
pop ebp

xor eax,eax
test eax,eax
jmp ecx
}
}

void __stdcall MemPatch(void)
{
BYTE pbJmpCode[] = {0x90,0xE9,0xEB,0x90,0x90};
BYTE *lpMemAddr;

//jmp over file checking
ReplaceMem((BYTE *)0x109095EF, pbJmpCode, 2); //l2.ini
ReplaceMem((BYTE *)0x109096D0, pbJmpCode, 2); //user.ini
ReplaceMem((BYTE *)0x1090979E, pbJmpCode+2, 1); //option.ini

//revison
lpMemAddr = (BYTE *)((int)g_hEngine + ppOffset[g_nSystemLang-1][2]);
ReplaceMem(lpMemAddr, (BYTE *)g_szRevison, 3);

//call
pbJmpCode[0] = 0xE8;
lpMemAddr = (BYTE *)((int)g_hEngine + ppOffset[g_nSystemLang-1][0]);
*(int *)(pbJmpCode+1) = (int)SetServerInfo - (int)lpMemAddr - 5;
ReplaceMem(lpMemAddr, pbJmpCode, 5);

pbJmpCode[0] = 0xE8;
lpMemAddr = (BYTE *)((int)g_hEngine + ppOffset[g_nSystemLang-1][1]);
*(int *)(pbJmpCode+1) = (int)RequestAuthLogin - (int)lpMemAddr - 5;
ReplaceMem(lpMemAddr, pbJmpCode, 5);

return;
}
x64 is offline