Dropped packet crypt listeners and related cleanup.

This commit is contained in:
MobiusDevelopment
2021-10-21 23:15:04 +00:00
parent c52d596d79
commit 47786d53d4
104 changed files with 778 additions and 4042 deletions

View File

@@ -17,28 +17,35 @@
*/
package org.l2jmobius.gameserver.network;
/**
* @author KenM
*/
public class Crypt
{
byte[] _key;
private byte[] _inKey;
private byte[] _outKey;
public void setKey(byte[] key)
{
_key = new byte[key.length];
System.arraycopy(key, 0, _key, 0, key.length);
_inKey = new byte[key.length];
_outKey = new byte[key.length];
System.arraycopy(key, 0, _inKey, 0, key.length);
System.arraycopy(key, 0, _outKey, 0, key.length);
}
public long decrypt(byte[] raw)
public void decrypt(byte[] raw)
{
if (_key == null)
if (_inKey == null)
{
return 0L;
return;
}
int temp = 0;
int j = 0;
for (int i = 0; i < raw.length; ++i)
{
final int temp2 = raw[i] & 0xFF;
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
final int temp2 = raw[i] & 0xff;
raw[i] = (byte) (temp2 ^ (_inKey[j++] & 0xff) ^ temp);
temp = temp2;
if (j <= 7)
{
@@ -46,29 +53,32 @@ public class Crypt
}
j = 0;
}
long old = _key[0] & 0xFF;
old |= (_key[1] << 8) & 0xFF00;
old |= (_key[2] << 16) & 0xFF0000;
old |= (_key[3] << 24) & 0xFF000000;
_key[0] = (byte) ((old += raw.length) & 0xFFL);
_key[1] = (byte) ((old >> 8) & 0xFFL);
_key[2] = (byte) ((old >> 16) & 0xFFL);
_key[3] = (byte) ((old >> 24) & 0xFFL);
return old;
// Shift key.
int old = _inKey[0] & 0xff;
old |= (_inKey[1] << 8) & 0xff00;
old |= (_inKey[2] << 16) & 0xff0000;
old |= (_inKey[3] << 24) & 0xff000000;
old += raw.length;
_inKey[0] = (byte) (old & 0xff);
_inKey[1] = (byte) ((old >> 8) & 0xff);
_inKey[2] = (byte) ((old >> 16) & 0xff);
_inKey[3] = (byte) ((old >> 24) & 0xff);
}
public long encrypt(byte[] raw)
public void encrypt(byte[] raw)
{
if (_key == null)
if (_outKey == null)
{
return 0L;
return;
}
int temp = 0;
int j = 0;
for (int i = 0; i < raw.length; ++i)
{
final int temp2 = raw[i] & 0xFF;
raw[i] = (byte) (temp2 ^ (_key[j++] & 0xFF) ^ temp);
final int temp2 = raw[i] & 0xff;
raw[i] = (byte) (temp2 ^ (_outKey[j++] & 0xff) ^ temp);
temp = raw[i];
if (j <= 7)
{
@@ -76,14 +86,16 @@ public class Crypt
}
j = 0;
}
long old = _key[0] & 0xFF;
old |= (_key[1] << 8) & 0xFF00;
old |= (_key[2] << 16) & 0xFF0000;
old |= (_key[3] << 24) & 0xFF000000;
_key[0] = (byte) ((old += raw.length) & 0xFFL);
_key[1] = (byte) ((old >> 8) & 0xFFL);
_key[2] = (byte) ((old >> 16) & 0xFFL);
_key[3] = (byte) ((old >> 24) & 0xFFL);
return old;
// Shift key.
int old = _outKey[0] & 0xff;
old |= (_outKey[1] << 8) & 0xff00;
old |= (_outKey[2] << 16) & 0xff0000;
old |= (_outKey[3] << 24) & 0xff000000;
old += raw.length;
_outKey[0] = (byte) (old & 0xff);
_outKey[1] = (byte) ((old >> 8) & 0xff);
_outKey[2] = (byte) ((old >> 16) & 0xff);
_outKey[3] = (byte) ((old >> 24) & 0xff);
}
}