2015-09-25 18:52:25 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2016-06-21 21:13:01 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-06-21 18:58:33 -04:00
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Targets;
|
2016-08-24 15:41:54 -04:00
|
|
|
|
using Ionic.Zlib;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-08-22 10:43:04 -04:00
|
|
|
|
namespace FFXIVClassic.Common
|
2016-06-08 22:29:04 +01:00
|
|
|
|
{
|
2015-09-25 18:52:25 -04:00
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
public struct BasePacketHeader
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public byte isAuthenticated;
|
|
|
|
|
public byte isCompressed;
|
|
|
|
|
public ushort connectionType;
|
|
|
|
|
public ushort packetSize;
|
|
|
|
|
public ushort numSubpackets;
|
|
|
|
|
public ulong timestamp; //Miliseconds
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public class BasePacket
|
2016-06-17 05:05:31 +01:00
|
|
|
|
{
|
2016-01-19 21:47:59 -05:00
|
|
|
|
public const int TYPE_ZONE = 1;
|
|
|
|
|
public const int TYPE_CHAT = 2;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
public const int BASEPACKET_SIZE = 0x10;
|
2016-06-21 18:52:20 -04:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
public byte[] data;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
public BasePacketHeader header;
|
|
|
|
|
|
2015-10-04 22:43:22 -04:00
|
|
|
|
//Loads a sniffed packet from a file
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public unsafe BasePacket(string path)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var bytes = File.ReadAllBytes(path);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
if (bytes.Length < BASEPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet was too small");
|
|
|
|
|
|
|
|
|
|
fixed (byte* pdata = &bytes[0])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (BasePacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bytes.Length < header.packetSize)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet size didn't equal given size");
|
|
|
|
|
|
|
|
|
|
int packetSize = header.packetSize;
|
|
|
|
|
|
2015-12-29 01:20:46 -05:00
|
|
|
|
if (packetSize - BASEPACKET_SIZE != 0)
|
|
|
|
|
{
|
|
|
|
|
data = new byte[packetSize - BASEPACKET_SIZE];
|
|
|
|
|
Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
data = new byte[0];
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 22:43:22 -04:00
|
|
|
|
//Loads a sniffed packet from a byte array
|
2015-09-25 18:52:25 -04:00
|
|
|
|
public unsafe BasePacket(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
if (bytes.Length < BASEPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet was too small");
|
|
|
|
|
|
|
|
|
|
fixed (byte* pdata = &bytes[0])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (BasePacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bytes.Length < header.packetSize)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet size didn't equal given size");
|
|
|
|
|
|
|
|
|
|
int packetSize = header.packetSize;
|
|
|
|
|
|
|
|
|
|
data = new byte[packetSize - BASEPACKET_SIZE];
|
2016-06-21 18:52:20 -04:00
|
|
|
|
Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public unsafe BasePacket(byte[] bytes, ref int offset)
|
|
|
|
|
{
|
|
|
|
|
if (bytes.Length < offset + BASEPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet was too small");
|
|
|
|
|
|
|
|
|
|
fixed (byte* pdata = &bytes[offset])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (BasePacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int packetSize = header.packetSize;
|
|
|
|
|
|
|
|
|
|
if (bytes.Length < offset + header.packetSize)
|
2016-06-21 18:52:20 -04:00
|
|
|
|
throw new OverflowException("Packet Error: Packet size didn't equal given size");
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
data = new byte[packetSize - BASEPACKET_SIZE];
|
|
|
|
|
Array.Copy(bytes, offset + BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
|
|
|
|
|
|
|
|
|
|
offset += packetSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BasePacket(BasePacketHeader header, byte[] data)
|
2016-06-21 18:52:20 -04:00
|
|
|
|
{
|
2015-09-25 18:52:25 -04:00
|
|
|
|
this.header = header;
|
|
|
|
|
this.data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public List<SubPacket> GetSubpackets()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var subpackets = new List<SubPacket>(header.numSubpackets);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var offset = 0;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
while (offset < data.Length)
|
2016-06-21 18:52:20 -04:00
|
|
|
|
subpackets.Add(new SubPacket(data, ref offset));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
return subpackets;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public static unsafe BasePacketHeader GetHeader(byte[] bytes)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
BasePacketHeader header;
|
|
|
|
|
if (bytes.Length < BASEPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Packet was too small");
|
|
|
|
|
|
|
|
|
|
fixed (byte* pdata = &bytes[0])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (BasePacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public byte[] GetHeaderBytes()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var size = Marshal.SizeOf(header);
|
|
|
|
|
var arr = new byte[size];
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var ptr = Marshal.AllocHGlobal(size);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
Marshal.StructureToPtr(header, ptr, true);
|
|
|
|
|
Marshal.Copy(ptr, arr, 0, size);
|
|
|
|
|
Marshal.FreeHGlobal(ptr);
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public byte[] GetPacketBytes()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var outBytes = new byte[header.packetSize];
|
2016-06-14 21:29:10 +01:00
|
|
|
|
Array.Copy(GetHeaderBytes(), 0, outBytes, 0, BASEPACKET_SIZE);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
Array.Copy(data, 0, outBytes, BASEPACKET_SIZE, data.Length);
|
|
|
|
|
return outBytes;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 22:43:22 -04:00
|
|
|
|
//Replaces all instances of the sniffed actorID with the given one
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void ReplaceActorID(uint actorID)
|
2015-10-04 22:43:22 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var mem = new MemoryStream(data))
|
2015-10-04 22:43:22 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var binWriter = new BinaryWriter(mem))
|
2015-10-04 22:43:22 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var binreader = new BinaryReader(mem))
|
2015-10-04 22:43:22 -04:00
|
|
|
|
{
|
|
|
|
|
while (binreader.BaseStream.Position + 4 < data.Length)
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var read = binreader.ReadUInt32();
|
|
|
|
|
if (read == 0x029B2941 || read == 0x02977DC7 || read == 0x0297D2C8 || read == 0x0230d573 ||
|
|
|
|
|
read == 0x23317df || read == 0x23344a3 || read == 0x1730bdb || read == 0x6c)
|
|
|
|
|
//Original ID
|
2015-10-04 22:43:22 -04:00
|
|
|
|
{
|
|
|
|
|
binWriter.BaseStream.Seek(binreader.BaseStream.Position - 0x4, SeekOrigin.Begin);
|
|
|
|
|
binWriter.Write(actorID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-13 22:57:16 -04:00
|
|
|
|
//Replaces all instances of the sniffed actorID with the given one
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void ReplaceActorID(uint fromActorID, uint actorID)
|
2015-10-13 22:57:16 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var mem = new MemoryStream(data))
|
2015-10-13 22:57:16 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var binWriter = new BinaryWriter(mem))
|
2015-10-13 22:57:16 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
using (var binreader = new BinaryReader(mem))
|
2015-10-13 22:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
while (binreader.BaseStream.Position + 4 < data.Length)
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var read = binreader.ReadUInt32();
|
2015-10-13 22:57:16 -04:00
|
|
|
|
if (read == fromActorID) //Original ID
|
|
|
|
|
{
|
|
|
|
|
binWriter.BaseStream.Seek(binreader.BaseStream.Position - 0x4, SeekOrigin.Begin);
|
|
|
|
|
binWriter.Write(actorID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public void DebugPrintPacket()
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
logger.ColorDebug(
|
|
|
|
|
string.Format("IsAuth:{0} IsEncrypted:{1}, Size:0x{2:X}, NumSubpackets:{3}{4}{5}",
|
|
|
|
|
header.isAuthenticated, header.isCompressed, header.packetSize, header.numSubpackets,
|
|
|
|
|
Environment.NewLine, Utils.ByteArrayToHex(GetHeaderBytes())), ConsoleOutputColor.DarkYellow);
|
|
|
|
|
|
|
|
|
|
foreach (var sub in GetSubpackets())
|
|
|
|
|
{
|
|
|
|
|
sub.DebugPrintSubPacket();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
#region Utility Functions
|
2016-06-21 18:52:20 -04:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static BasePacket CreatePacket(List<SubPacket> subpackets, bool isAuthed, bool isCompressed)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
//Create Header
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var header = new BasePacketHeader();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
byte[] data = null;
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header.isAuthenticated = isAuthed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.isCompressed = isCompressed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.numSubpackets = (ushort) subpackets.Count;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
header.packetSize = BASEPACKET_SIZE;
|
2015-12-29 01:20:46 -05:00
|
|
|
|
header.timestamp = Utils.MilisUnixTimeStampUTC();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
//Get packet size
|
2016-06-21 18:52:20 -04:00
|
|
|
|
foreach (var subpacket in subpackets)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
header.packetSize += subpacket.header.subpacketSize;
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
data = new byte[header.packetSize - 0x10];
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
//Add Subpackets
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var offset = 0;
|
|
|
|
|
foreach (var subpacket in subpackets)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var subpacketData = subpacket.GetBytes();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
Array.Copy(subpacketData, 0, data, offset, subpacketData.Length);
|
2016-06-21 18:52:20 -04:00
|
|
|
|
offset += (ushort) subpacketData.Length;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.Assert(data != null && offset == data.Length && header.packetSize == 0x10 + offset);
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var packet = new BasePacket(header, data);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static BasePacket CreatePacket(SubPacket subpacket, bool isAuthed, bool isCompressed)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
//Create Header
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var header = new BasePacketHeader();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
byte[] data = null;
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header.isAuthenticated = isAuthed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.isCompressed = isCompressed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.numSubpackets = 1;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
header.packetSize = BASEPACKET_SIZE;
|
2015-12-29 01:20:46 -05:00
|
|
|
|
header.timestamp = Utils.MilisUnixTimeStampUTC();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
//Get packet size
|
|
|
|
|
header.packetSize += subpacket.header.subpacketSize;
|
|
|
|
|
|
|
|
|
|
data = new byte[header.packetSize - 0x10];
|
|
|
|
|
|
|
|
|
|
//Add Subpackets
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var subpacketData = subpacket.GetBytes();
|
|
|
|
|
Array.Copy(subpacketData, 0, data, 0, subpacketData.Length);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
Debug.Assert(data != null);
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var packet = new BasePacket(header, data);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static BasePacket CreatePacket(byte[] data, bool isAuthed, bool isCompressed)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
Debug.Assert(data != null);
|
|
|
|
|
|
|
|
|
|
//Create Header
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var header = new BasePacketHeader();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header.isAuthenticated = isAuthed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.isCompressed = isCompressed ? (byte) 1 : (byte) 0;
|
|
|
|
|
header.numSubpackets = 1;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
header.packetSize = BASEPACKET_SIZE;
|
2015-12-29 01:20:46 -05:00
|
|
|
|
header.timestamp = Utils.MilisUnixTimeStampUTC();
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
//Get packet size
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header.packetSize += (ushort) data.Length;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var packet = new BasePacket(header, data);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static unsafe void EncryptPacket(Blowfish blowfish, BasePacket packet)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var data = packet.data;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
int size = packet.header.packetSize;
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var offset = 0;
|
|
|
|
|
while (offset < data.Length)
|
|
|
|
|
{
|
2015-09-25 18:52:25 -04:00
|
|
|
|
if (data.Length < offset + SubPacket.SUBPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Subpacket was too small");
|
|
|
|
|
|
|
|
|
|
SubPacketHeader header;
|
|
|
|
|
fixed (byte* pdata = &data[offset])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (SubPacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(SubPacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.Length < offset + header.subpacketSize)
|
|
|
|
|
throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
blowfish.Encipher(data, offset + 0x10, header.subpacketSize - 0x10);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
offset += header.subpacketSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static unsafe void DecryptPacket(Blowfish blowfish, ref BasePacket packet)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var data = packet.data;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
int size = packet.header.packetSize;
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var offset = 0;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
while (offset < data.Length)
|
|
|
|
|
{
|
|
|
|
|
if (data.Length < offset + SubPacket.SUBPACKET_SIZE)
|
|
|
|
|
throw new OverflowException("Packet Error: Subpacket was too small");
|
|
|
|
|
|
|
|
|
|
SubPacketHeader header;
|
|
|
|
|
fixed (byte* pdata = &data[offset])
|
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
header = (SubPacketHeader) Marshal.PtrToStructure(new IntPtr(pdata), typeof(SubPacketHeader));
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.Length < offset + header.subpacketSize)
|
|
|
|
|
throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
|
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
blowfish.Decipher(data, offset + 0x10, header.subpacketSize - 0x10);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
offset += header.subpacketSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-21 18:52:20 -04:00
|
|
|
|
|
2016-08-24 15:41:54 -04:00
|
|
|
|
public static unsafe void DecompressPacket(ref BasePacket packet)
|
|
|
|
|
{
|
|
|
|
|
using (var compressedStream = new MemoryStream(packet.data))
|
|
|
|
|
using (var zipStream = new ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Decompress))
|
|
|
|
|
using (var resultStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
zipStream.CopyTo(resultStream);
|
|
|
|
|
packet.data = resultStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static unsafe void CompressPacket(ref BasePacket packet)
|
|
|
|
|
{
|
|
|
|
|
using (var compressedStream = new MemoryStream(packet.data))
|
|
|
|
|
using (var zipStream = new ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Compress))
|
|
|
|
|
using (var resultStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
zipStream.CopyTo(resultStream);
|
|
|
|
|
packet.data = resultStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
#endregion
|
2016-06-21 18:52:20 -04:00
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-21 18:52:20 -04:00
|
|
|
|
public static class LoggerExtensions
|
|
|
|
|
{
|
|
|
|
|
public static void ColorDebug(this Logger logger, string message, ConsoleOutputColor color)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-21 18:52:20 -04:00
|
|
|
|
var logEvent = new LogEventInfo(LogLevel.Debug, logger.Name, message);
|
|
|
|
|
logEvent.Properties["color"] = (int) color;
|
|
|
|
|
logger.Log(logEvent);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-21 18:52:20 -04:00
|
|
|
|
}
|