![]() |
|
|
#1 |
|
Архивный участник
Join Date: Sep 2005
Posts: 72
|
Can anyone explain me, or rather post code to encryption/decryption gameserver packets?
I looked at l2j, but it works fine only when I'm connecting to emulator. When I connect to normal server, some bytes are ok, some unfortunately not. |
|
|
|
|
#2 |
|
Архивный участник
Join Date: Nov 2005
Posts: 504
|
this is from l2packet framework source...
C++ Code:
Decoder.cpp
#include "Decoder.h"
#include <stdio.h>
#include <malloc.h>
#include <string.h>
Decoder::Decoder()
{
}
Decoder::~Decoder()
{
}
void Decoder::setKey(char *newkey, int size)
{
key = (char*)malloc(size);
memcpy(key, newkey, size);
printf("key was issued by the server\n");
}
long Decoder::decode(char *input, int size)
{
if(key == NULL)
return 0L;
int i = 0;
int j = 0;
for(int k=0; k < size; k++)
{
int i1 = input[k] & 0xFF;
input[k] = (char)(i1 ^ key[j++] & 0xFF ^i);
i = i1;
if(j>7)
j=0;
}
long l = key[0] & 0xFF;
l |= key[1] << 8 & 0xFF00;
l |= key[2] << 16 & 0xFF0000;
l |= key[3] << 24 & 0xFF000000;
l += size;
key[0] = (char)(l & 255L);
key[1] = (char)(l >> 8 & 255L);
key[2] = (char)(l >> 16 & 255L);
key[3] = (char)(l >> 24 & 255L);
return l;
}
Decoder.h
#ifndef __Decoder_h__
#define __Decoder_h__
class Decoder
{
private:
public:
char *key;
Decoder();
~Decoder();
void setKey(char *newkey, int size);
long decode(char *input, int size);
};
#endif
EDIT: also, the 0x00 packet aparently also contains the key of which is used for the decryption of the server packets... Code:
PacketProcessor.cpp
if(sizeGamePacket == 0x0c && newbuffer[2] == 0x00 && decode == 0)
{
char key[8];
key[0] = newbuffer[4];
key[1] = newbuffer[5];
key[2] = newbuffer[6];
key[3] = newbuffer[7];
key[4] = (char)0xA1;
key[5] = (char)0x6C;
key[6] = (char)0x54;
key[7] = (char)0x87;
decoder->setKey(key, sizeof(key));
size = 0;
decode = 1;
continue;
}
|
|
|
|
|
#3 |
|
Архивный участник
Join Date: Sep 2005
Posts: 72
|
I'm using this java code (extracted from l2j and compiled under .net as J#)
Code:
public long decrypt(ubyte[] raw)
{
if (_key == null)
{
return 0;
}
int temp = 0;
int j = 0;
for (int i = 0; i < raw.length; i++)
{
int temp2 = raw[i] & 0xff;
raw[i] = (ubyte)(temp2 ^ (_key[j++] & 0xff) ^ temp);
temp = temp2;
if (j > 7)
{
j = 0;
}
}
long old = _key[0] & 0xff;
old |= _key[1] << 8 & 0xff00;
old |= _key[2] << 0x10 & 0xff0000;
old |= _key[3] << 0x18 & 0xff000000;
old += raw.length;
_key[0] = (ubyte)(old & 0xff);
_key[1] = (ubyte)(old >> 0x08 & 0xff);
_key[2] = (ubyte)(old >> 0x10 & 0xff);
_key[3] = (ubyte)(old >> 0x18 & 0xff);
return 1;
}
As I wrote, it's ok with l2j, but there are some bad bytes (just some, most are ok) if I use it with normal server |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Sep 2005
Posts: 72
|
And where is the source of l2packet framework? If I search PP or google for "l2packet" I got only rubbish
|
|
|
|
|
#5 |
|
Архивный участник
Join Date: Nov 2005
Posts: 504
|
check pm
|
|
|
|
|
#6 |
|
Архивный участник
Join Date: Feb 2005
Posts: 307
|
Or maybe where to find the program itself
|
|
|
|
|
#7 |
|
Архивный участник
Join Date: Dec 2005
Posts: 83
|
please pm me too
|
|
|
|
|
#8 |
|
Архивный участник
Join Date: Feb 2005
Posts: 307
|
And me >.>
|
|
|
|
|
#9 |
|
Архивный участник
Join Date: Nov 2005
Posts: 504
|
-.- just search for "packet" posted by digital -.-
|
|
|
|
|