View Single Post
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