Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 14.03.2006, 17:55   #1
aralyon
Архивный участник
 
Join Date: Sep 2005
Posts: 72
Default Gameserver packet encryption

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.
aralyon is offline  
Old 14.03.2006, 18:01   #2
testdude
Архивный участник
 
Join Date: Nov 2005
Posts: 504
Default

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
hope it helps... if you search you will find the whole source posted by digital...

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;
		}
thats also from l2pf
testdude is offline  
Old 14.03.2006, 18:12   #3
aralyon
Архивный участник
 
Join Date: Sep 2005
Posts: 72
Default

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;
	}
It looks same as that C++ code :?
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
aralyon is offline  
Old 14.03.2006, 18:14   #4
aralyon
Архивный участник
 
Join Date: Sep 2005
Posts: 72
Default

And where is the source of l2packet framework? If I search PP or google for "l2packet" I got only rubbish
aralyon is offline  
Old 14.03.2006, 18:23   #5
testdude
Архивный участник
 
Join Date: Nov 2005
Posts: 504
Default

check pm
testdude is offline  
Old 14.03.2006, 18:25   #6
Shawnmb
Архивный участник
 
Join Date: Feb 2005
Posts: 307
Default

Or maybe where to find the program itself
Shawnmb is offline  
Old 14.03.2006, 21:11   #7
vex
Архивный участник
 
Join Date: Dec 2005
Posts: 83
Default

please pm me too
vex is offline  
Old 15.03.2006, 00:09   #8
Shawnmb
Архивный участник
 
Join Date: Feb 2005
Posts: 307
Default

And me >.>
Shawnmb is offline  
Old 15.03.2006, 10:04   #9
testdude
Архивный участник
 
Join Date: Nov 2005
Posts: 504
Default

-.- just search for "packet" posted by digital -.-
testdude is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 18:10.