Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   Client hooking (https://postpacific.loc-online.com/showthread.php?t=6002)

aralyon 12.10.2006 16:33

Client hooking
 
Hi all, does anyone have experience with hooking a c4 client? I need to modify one packet (or attach sending custom packet to sending username and password). Can anyone help me please?

Met45 12.10.2006 17:39

sure u have to modify packets... hmm sure...
why u wanne do that?
u dun need to hook the client!
it's working without sending "cheater" packets

FidoW 12.10.2006 18:32

Maybe he is trying to create an antibot system....

HongK 12.10.2006 19:40

Wouldn't be hard to do .. You need to know which functions you want to hook and then hook them, try and catch the packet header and then when it catches the packet you want, call your own function that modifies the packet .. At least in theory this is what you want, but its hard to tell without knowing more details...

But if you just need to modify one packet, then why not just manually patch it? You can find the functions pretty easily in engine.dll ...

Dmytro 12.10.2006 20:56

HongK, yep, in Engine.dll it's easy!
But we must change it in l2server too.
Damn x64! XD

Can you or some one give small help in searching packets headers in l2server_x64?

HongK 13.10.2006 00:07

they'll be in hex right after the packet format is pushed if I remember correctly ... There was a post floating around here on PP somewhere with a lot of the packet header id's, but im quite sure it was for c1 only

mcrabben7 13.10.2006 05:52

Go to the L2EP 'Elhaym' thread and download the Opcode zip, it has C1 through C4 packet headers. It's in the Server section.

aralyon 13.10.2006 11:39

I know structure of all login packets .... l2j is great documentation :)
I'm trying to make something like gameguard ... but for my server.
I'm not familiar with asm very well, so if anyone can give me some advice, i would be glad for it

HongK 13.10.2006 12:30

Ok here's a small example ...

This is going to be a big post cause I will use lots of asm instructions as well as l2j code to show you what you are looking at.

First, let's look at the structure and makeup of an npcinfo packet in the official l2server. Here it goes:
--------------------------------------------------------------------
00496636 . 8B4D A8 MOV ECX,DWORD PTR SS:[EBP-58]
00496639 . 51 PUSH ECX
0049663A . 8B55 C4 MOV EDX,DWORD PTR SS:[EBP-3C]
0049663D . 52 PUSH EDX
0049663E . 8A55 EF MOV DL,BYTE PTR SS:[EBP-11]
00496641 . 33C9 XOR ECX,ECX
00496643 . 84D2 TEST DL,DL
00496645 . 0F95C1 SETNE CL
00496648 . 8845 0B MOV BYTE PTR SS:[EBP+B],AL
0049664B . 8B83 540F0000 MOV EAX,DWORD PTR DS:[EBX+F54]
00496651 . 8D93 2A100000 LEA EDX,DWORD PTR DS:[EBX+102A]
00496657 . 51 PUSH ECX
00496658 . 8D8B F80F0000 LEA ECX,DWORD PTR DS:[EBX+FF8]
0049665E . 51 PUSH ECX
0049665F . 52 PUSH EDX
00496660 . 8B50 70 MOV EDX,DWORD PTR DS:[EAX+70]
00496663 . 33C9 XOR ECX,ECX
00496665 . 85D2 TEST EDX,EDX
00496667 . 0F94C1 SETE CL
0049666A . 33D2 XOR EDX,EDX
0049666C . 6A 01 PUSH 1
0049666E . 51 PUSH ECX
0049666F . 8A8B 65090000 MOV CL,BYTE PTR DS:[EBX+965]
00496675 . 84C9 TEST CL,CL
00496677 . 0F95C2 SETNE DL
0049667A . 33C9 XOR ECX,ECX
0049667C . 52 PUSH EDX
0049667D . 8B90 6C010000 MOV EDX,DWORD PTR DS:[EAX+16C]
00496683 . 85D2 TEST EDX,EDX
00496685 . 0F95C1 SETNE CL
00496688 . 33D2 XOR EDX,EDX
0049668A . 51 PUSH ECX
0049668B . 8B88 70010000 MOV ECX,DWORD PTR DS:[EAX+170]
00496691 . 85C9 TEST ECX,ECX
00496693 . 0F95C2 SETNE DL
00496696 . 33C0 XOR EAX,EAX
00496698 . 83FE FF CMP ESI,-1
0049669B . 0F94C0 SETE AL
0049669E . 33C9 XOR ECX,ECX
004966A0 . 52 PUSH EDX
004966A1 . 48 DEC EAX
004966A2 . 23C6 AND EAX,ESI
004966A4 . 50 PUSH EAX
004966A5 . 8B45 D8 MOV EAX,DWORD PTR SS:[EBP-28]
004966A8 . 83F8 FF CMP EAX,-1
004966AB . 0F94C1 SETE CL
004966AE . 33D2 XOR EDX,EDX
004966B0 . 49 DEC ECX
004966B1 . 23C8 AND ECX,EAX
004966B3 . 8B45 98 MOV EAX,DWORD PTR SS:[EBP-68]
004966B6 . 83FF FF CMP EDI,-1
004966B9 . 0F94C2 SETE DL
004966BC . 51 PUSH ECX
004966BD . 8B4D 94 MOV ECX,DWORD PTR SS:[EBP-6C]
004966C0 . 4A DEC EDX
004966C1 . 23D7 AND EDX,EDI
004966C3 . 52 PUSH EDX
004966C4 . 8B55 8C MOV EDX,DWORD PTR SS:[EBP-74]
004966C7 . 50 PUSH EAX
004966C8 . 8B45 88 MOV EAX,DWORD PTR SS:[EBP-78]
004966CB . 51 PUSH ECX
004966CC . 8B4D 80 MOV ECX,DWORD PTR SS:[EBP-80]
004966CF . 52 PUSH EDX
004966D0 . 8B95 7CFFFFFF MOV EDX,DWORD PTR SS:[EBP-84]
004966D6 . 50 PUSH EAX
004966D7 . 8B45 E4 MOV EAX,DWORD PTR SS:[EBP-1C]
004966DA . 51 PUSH ECX
004966DB . 8B4D E0 MOV ECX,DWORD PTR SS:[EBP-20]
004966DE . 52 PUSH EDX
004966DF . 8B55 A4 MOV EDX,DWORD PTR SS:[EBP-5C]
004966E2 . 50 PUSH EAX
004966E3 . 51 PUSH ECX
004966E4 . 8B45 BC MOV EAX,DWORD PTR SS:[EBP-44]
004966E7 . DD85 40FFFFFF FLD QWORD PTR SS:[EBP-C0]
004966ED . 8B4D 90 MOV ECX,DWORD PTR SS:[EBP-70]
004966F0 . 52 PUSH EDX
004966F1 . 8B55 B4 MOV EDX,DWORD PTR SS:[EBP-4C]
004966F4 . 50 PUSH EAX
004966F5 . 8B45 9C MOV EAX,DWORD PTR SS:[EBP-64]
004966F8 . 51 PUSH ECX
004966F9 . 8B4D AC MOV ECX,DWORD PTR SS:[EBP-54]
004966FC . 52 PUSH EDX
004966FD . 8B55 CC MOV EDX,DWORD PTR SS:[EBP-34]
00496700 . 50 PUSH EAX
00496701 . 8B45 C8 MOV EAX,DWORD PTR SS:[EBP-38]
00496704 . 51 PUSH ECX
00496705 . 8B4D D0 MOV ECX,DWORD PTR SS:[EBP-30]
00496708 . 52 PUSH EDX
00496709 . 8B55 B8 MOV EDX,DWORD PTR SS:[EBP-48]
0049670C . 50 PUSH EAX
0049670D . 8B45 B0 MOV EAX,DWORD PTR SS:[EBP-50]
00496710 . 51 PUSH ECX
00496711 . 8B4D E8 MOV ECX,DWORD PTR SS:[EBP-18]
00496714 . 52 PUSH EDX
00496715 . 50 PUSH EAX
00496716 . 51 PUSH ECX
00496717 . E8 905C0F00 CALL L2Server.0058C3AC
0049671C . DD85 38FFFFFF FLD QWORD PTR SS:[EBP-C8]
00496722 . 50 PUSH EAX
00496723 . E8 845C0F00 CALL L2Server.0058C3AC
00496728 . DD85 30FFFFFF FLD QWORD PTR SS:[EBP-D0]
0049672E . 50 PUSH EAX
0049672F . E8 785C0F00 CALL L2Server.0058C3AC
00496734 . 8A4D 0B MOV CL,BYTE PTR SS:[EBP+B]
00496737 . 33D2 XOR EDX,EDX
00496739 . 84C9 TEST CL,CL
0049673B . 8B4B 18 MOV ECX,DWORD PTR DS:[EBX+18]
0049673E . 0F95C2 SETNE DL
00496741 . 50 PUSH EAX
00496742 . 8B43 1C MOV EAX,DWORD PTR DS:[EBX+1C]
00496745 . 52 PUSH EDX
00496746 . 8B95 6CFFFFFF MOV EDX,DWORD PTR SS:[EBP-94]
0049674C . 50 PUSH EAX
0049674D . 51 PUSH ECX
0049674E . 6A 22 PUSH 22
00496750 . 68 C80C5E00 PUSH L2Server.005E0CC8 ; ASCII "cddddddddddddddddddffffdddcccccSSddd"
00496755 . 52 PUSH EDX
00496756 . E8 15950400 CALL L2Server.004DFC70

---------------------------------------------------------------------
If you take a look at the ASCII value you see the packet format for NPCINFO. In assembly, a push instruction "pushes" a value onto the stack. What happens is that SP (stack pointer) is decremented by one word (two bytes) so that it points to an empty area of the stack segment that is two bytes long. Then whatever value is to be pushed onto the stack is written to memory in the stack segment at the offset address in SP. So that's the asm part of it. Just about every push you see here will be a push of a value for one of those c's or d's or f's or S's in NPCINFO. So, for example:

MOV EAX,DWORD PTR SS:[EBP-38] ---> This is mov'ing the "contents" of whats at EBP-38 into the EAX register. This will no doubt be something about the NPC we are looking at, such as an abnormal effect. But just moving the value into a register doesn't do anything. You will see later on that there is a PUSH EAX instruction. That pushes the value onto the stack and in an order to fit into the full NPCINFO packet.

After all the values have been pushed in the order to form a NPCINFO packet (cddddddddddddddddddffffdddcccccSSddd), you can see at address 0x00496756 that a call instruction is encountered. This calls the function that sends the packet to the client and the process is complete.

So lets look at the corresponding NPCINFO packet in Java, courtesy of L2J:
-----------------------------------------------------------------------
final void writeImpl()
{
if (_cha instanceof L2Summon)
if (((L2Summon)_cha).getOwner() != null
&& ((L2Summon)_cha).getOwner().getInvisible() == 1)
return;
writeC(0x16);
writeD(_cha.getObjectId());
writeD(_idTemplate+1000000); // npctype id
writeD(_isAttackable ? 1 : 0);
writeD(_x);
writeD(_y);
writeD(_z);
writeD(_heading);
writeD(0x00);
writeD(_mAtkSpd);
writeD(_pAtkSpd);
writeD(_runSpd);
writeD(_walkSpd);
writeD(_swimRunSpd/*0x32*/); // swimspeed
writeD(_swimWalkSpd/*0x32*/); // swimspeed
writeD(_flRunSpd);
writeD(_flWalkSpd);
writeD(_flyRunSpd);
writeD(_flyWalkSpd);
writeF(1.1/*_cha.getProperMultiplier()*/);
//writeF(1/*_cha.getAttackSpeedMultiplier()*/);
writeF(_pAtkSpd/2xx.xx8340719);
writeF(collisionRadius);
writeF(collisionHeight);
writeD(_rhand); // right hand weapon
writeD(0);
writeD(_lhand); // left hand weapon
writeC(1); // name above char 1=true ... ??
writeC(_cha.isRunning() ? 1 : 0);
writeC(_cha.isInCombat() ? 1 : 0);
writeC(_cha.isAlikeDead() ? 1 : 0);
writeC(_isSummoned ? 2 : 0); // invisible ?? 0=false 1=true 2=summoned (only works if model has a summon animation)
writeS(_name);
writeS(_title);
writeD(0);
writeD(0);
writeD(0000); // hmm karma ??

writeD(_cha.getAbnormalEffect()); // C2
writeD(0000); // C2
writeD(0000); // C2
writeD(0000); // C2
writeD(0000); // C2
writeC(0000); // C2

writeC(0x00); // C3 team circle 1-blue, 2-red
writeF(0x00); // C4 i think it is collisionRadius a second time
writeF(0x00); // C4 " collisionHeight "
writeD(0x00); // C4
}
----------------------------------------------------------------------
This is essentially EXACTLY what you see going on in the assembly in l2server, except now we see it in a higher lvl language. The packets are slightly different cause this is a C4 l2j packet and the original one I used was from C1 l2server. So hopefully you now have a little bit better understanding of what goes on.


All times are GMT. The time now is 15:24.