Quote:
Originally Posted by Synsia
The way you're overwriting the buffer does not look right at all. Only incrementing position by 1?
|
The original buffer is almost certainly wrong anyways. Hawtness said that SendPacket() takes two parameters, size and address so I figure this part has to be right:
Code:
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(ms))
{[INDENT]// push packet size
writer.Write((byte)0x68);
writer.Write(packet.Length);
// push packet address
writer.Write((byte)0x68);
writer.Write(packetAddress);
// store SendPacket() address in EAX
writer.Write((byte)0xB8);
writer.Write(SendPacketAddress);
// call function stored in EAX
writer.Write(new byte[] {0xFF, 0xD0});
// return
writer.Write((byte)0xC3);[/INDENT]
}
Simple and I understand that. What I don't understand is why in the sample he does:
Code:
mov edx, packetType - [COLOR="Red"]why the hell would I need to do this?[/COLOR]
push packetSize
push packetAddress
mov esi, networkClass - [COLOR="Red"]why the hell would I need to do this?[/COLOR]
mov ecx, [esi+14] - [COLOR="Red"]and subsequently, this?[/COLOR]
mov eax, sendpacketfunction
call eax
ret
Then Ian posts his own function which seemed a lot easier to read and is almost what I expected:
Code:
unsafe public void SendPacket(byte[] packet)
{[INDENT]int packetAdr = AllocMem(packet.Length);
Write(packetAdr, packet);
byte[] buffer = new byte[]
{[INDENT]0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0 ; Size
0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0 ; Packet
0xB9, 0x60, 0x12, 0x80, 0x00, // MOV ECX, SendPacketEcx - [COLOR="Red"]why?[/COLOR]
0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, SendPacketFn
0xFF, 0xD0, // CALL EAX
0xC3, // RET[/INDENT]};
fixed (byte* ptr = buffer)
{[INDENT]
*((int*)(ptr + 1)) = packet.Length;
*((int*)(ptr + 6)) = packetAdr;
*((int*)(ptr + 11)) = SendPacketEcx;
*((int*)(ptr + 16)) = SendPacketFn;
[/INDENT]}
Execute(buffer);
FreeMem(packetAdr);[/INDENT]}
AND either way executing both of these in memory crashes the client so I'm assuming some part of both is outdated though I can't imagine what.