PDA

View Full Version : [SHARE]Source code of l2auth.dll(For C5 client),All language!


x64
21.09.2006, 13:54
// 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",szRevison693,
g_szRevison,MAX_PATH,".\\l2.ini");
g_nServerPort = GetPrivateProfileInt(_T("URL"),_T("ServerPort"),2106,_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;
}

kgptzac
21.09.2006, 14:07
hohoho the iceburg starts to show itself :)

Stazis
21.09.2006, 14:34
woooh - welcome here x64

HongK
21.09.2006, 19:49
mmm source code is a good thing ..

Nevyn
21.09.2006, 21:05
Nice work ezme =>
Was kind of easy to edit even without the source-code anyways.
But this helps alot to make people learn :>

sparcode
22.09.2006, 07:40
thanx ezasme for your code

hel
22.09.2006, 08:40
x64:
Thank you very much for this source code.
It's very interesting. :)

khelben
21.07.2007, 13:47
//resurrect post

Anyone interested in helping me update this for c5 retail engine?

If i'm not mistaken this was written for the PTS engine.

So I'd like to make this an adventure in learning.

I believe this is a good start?

I have the RequestAuthLogin of the C5 Retail Engine at +0xFA140:

103FA140 loc_103FA140: ; CODE XREF: UNetworkHandler::RequestAuthLogin(ushort *,ushort *)j
.text:103FA140 xor eax, eax
.text:103FA142 push esi
.text:103FA143 mov WideCharStr, eax
.text:103FA148 mov dword_10ACE8B8, eax
.text:103FA14D mov dword_10ACE8BC, eax
.text:103FA152 mov word_10ACE8C0, ax
.text:103FA158 mov byte_10ACE8C2, al
.text:103FA15D mov dword_10ACE8D2, eax
.text:103FA162 mov dword_10ACE8D6, eax
.text:103FA167 mov dword_10ACE8DA, eax
.text:103FA16C mov dword_10ACE8DE, eax
.text:103FA171 mov byte_10ACE8E2, al
.text:103FA176 mov eax, [esp+4+arg_0]
.text:103FA17A push 0Eh ; size_t
.text:103FA17C push eax ; wchar_t *
.text:103FA17D push offset WideCharStr ; wchar_t *
.text:103FA182 mov esi, ecx
.text:103FA184 call _wcsncpy
.text:103FA189 mov ecx, [esp+10h+arg_4]
.text:103FA18D push 10h ; size_t
.text:103FA18F push ecx ; wchar_t *
.text:103FA190 push offset dword_10ACE8D2 ; wchar_t *
.text:103FA195 call _wcsncpy
.text:103FA19A mov edx, [esi+4Ch]
.text:103FA19D add esp, 18h
.text:103FA1A0 mov dword ptr [edx+5054h], 0
.text:103FA1AA mov ecx, [esi+4Ch]
.text:103FA1AD push 83Ah
.text:103FA1B2 lea eax, [ecx+4858h]
.text:103FA1B8 push eax
.text:103FA1B9 call sub_10311D97
.text:103FA1BE mov dword ptr [esi+50h], 1
.text:103FA1C5 mov ecx, ds:?GNetworkLog@@3PAVFOutputDevice@@A ; FOutputDevice * GNetworkLog
.text:103FA1CB mov edx, [ecx]
.text:103FA1CD push offset aSendRequestaut ; "(Send)RequestAuthLogin"
.text:103FA1D2 push edx
.text:103FA1D3 call ds:?Logf@FOutputDevice@@QAAXPBGZZ ; FOutputDevice::Logf(ushort const *,...)
.text:103FA1D9 add esp, 8
.text:103FA1DC mov eax, 1
.text:103FA1E1 pop esi
.text:103FA1E2 retn 8