Welcome
Ladies and Gents:

These forums are now closed and registration disabled.

Please join us at our new forum on Proboards. Our hope is that these new forums are more stable, provide more and better features, and allow continuation of the project forums in a safer, more secure, long term environment.

me3explorer.proboards.com

--The ME3Explorer Team

Current Research: Network

Technical research related to the structure of Mass Effect game files.

Re: Current Research: Network

Postby WarrantyVoider » 10 Jun 2014, 21:19

Im working on a tool for editing the packets, also trying to write it so, that I can have some clean code at end, well classes and inhertiances helps alot here :D

Image

Spoiler:
public static class Blaze
{
public class Packet
{
public ushort Length;
public ushort Component;
public ushort Command;
public ushort Error;
public ushort QType;
public ushort ID;
public ushort extLength;
public byte[] Content;
}
public static Packet ReadBlazePacket(Stream s)
{
Packet res = new Packet();
res.Length = ReadUShort(s);
res.Component = ReadUShort(s);
res.Command = ReadUShort(s);
res.Error = ReadUShort(s);
res.QType = ReadUShort(s);
res.ID = ReadUShort(s);
if ((res.QType & 0x10) != 0)
res.extLength = ReadUShort(s);
else
res.extLength = 0;
int len = res.Length + (res.extLength << 16);
res.Content = new byte[len];
s.Read(res.Content, 0, len);
return res;
}
public static List<Packet> FetchAllBlazePackets(Stream s)
{
List<Packet> res = new List<Packet>();
s.Seek(0, 0);
while (s.Position < s.Length)
{
res.Add(ReadBlazePacket(s));
}
return res;
}
public static ushort ReadUShort(Stream s)
{
byte[] buff = new byte[2];
s.Read(buff, 0, 2);
return (ushort)((buff[0] << 8) + buff[1]);
}
public static uint ReadUInt(Stream s)
{
byte[] buff = new byte[4];
s.Read(buff, 0, 4);
return (uint)((buff[0] << 24) + (buff[1] << 16) + (buff[2] << 8) + buff[3]);
}
public static string TagToLabel(uint Tag)//very ugly code, has to be speed up
{
byte[] buff = BitConverter.GetBytes(Tag);
List<byte> tmp = new List<byte>(buff);
tmp.Reverse();
buff = tmp.ToArray();
string s = "";
foreach (byte b in buff)
{
string t = "";
for (int i = 0; i < 8; i++)
if ((b & (1 << i)) != 0)
t = "1" + t;
else
t = "0" + t;
s += t;
}
string binary = s.Substring(0, 24);
binary = binary.Insert(0, "0");
binary = binary.Insert(2, "0");
binary = binary.Insert(8, "0");
binary = binary.Insert(10, "0");
binary = binary.Insert(16, "0");
binary = binary.Insert(18, "0");
binary = binary.Insert(24, "0");
binary = binary.Insert(26, "0");
s = "";
for (int i = 0; i < binary.Length / 8; i++)
{
byte b = 0;
for (int j = 0; j < 8; j++)
if (binary[i * 8 + 7 - j] == '1')
b += (byte)(1 << j);
s += (char)b;
}
return s.Replace('\0', ' ');
}
public static long DecompressInteger(Stream s)
{
List<byte> tmp = new List<byte>();
byte b;
while ((b = (byte)s.ReadByte()) >= 0x80)
tmp.Add(b);
tmp.Add(b);
byte[] buff = tmp.ToArray();
int currshift = 6;
long result = buff[0] & 0x3F;
for (int i = 1; i < buff.Length; i++)
{
byte curbyte = buff[i];
long l = (curbyte & 0x7F) << currshift;
result |= l;
currshift += 7;
}
return result;
}
public static List<Tdf> ReadPacketContent(Packet p)
{
List<Tdf> res = new List<Tdf>();
MemoryStream m = new MemoryStream(p.Content);
m.Seek(0, 0);
while (m.Position < m.Length)
res.Add(ReadTdf(m));
return res;
}

public static Tdf ReadTdf(Stream s)
{
Tdf res = new Tdf();
uint Head = ReadUInt(s);
res.Tag = (Head & 0xFFFFFF00);
res.Label = TagToLabel(res.Tag);
res.Type = (byte)(Head & 0xFF);
switch (res.Type)
{
case 0:
return ReadTdfInteger(res, s);
case 1:
return ReadTdfString(res, s);
case 3:
return ReadTdfStruct(res, s);
default:
throw new Exception("Unknown Tdf Type: " + res.Type);
}
}

public static TdfInteger ReadTdfInteger(Tdf head, Stream s)
{
TdfInteger res = new TdfInteger();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = (int)DecompressInteger(s);
return res;
}

public static TdfString ReadTdfString(Tdf head, Stream s)
{
TdfString res = new TdfString();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
int len = (int)DecompressInteger(s);
res.Value = "";
for (int i = 0; i < len - 1; i++)
res.Value += (char)s.ReadByte();
s.ReadByte();
return res;
}

public static TdfStruct ReadTdfStruct(Tdf head, Stream s)
{
TdfStruct res = new TdfStruct();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Values = new List<Tdf>();
byte b = 0;
while ((b = (byte)s.ReadByte()) != 0)
{
s.Seek(-1, SeekOrigin.Current);
res.Values.Add(ReadTdf(s));
}
return res;
}

public class Tdf
{
public string Label;
public uint Tag;
public byte Type;
public TreeNode ToTree()
{
return new TreeNode(Label + " : " + Type);
}
}

public class TdfInteger : Tdf
{
public int Value;
}

public class TdfString : Tdf
{
public string Value;
}

public class TdfStruct : Tdf
{
public List<Tdf> Values;
}

}


greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 11 Jun 2014, 17:21

ok, looks like im done, im releasing only the class here that I wrote for this, Ill release tools as soon as I get rid of using my login credentials (which id like NOT to share :P)
Image

Spoiler:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ME3Server_WV
{
public static class Blaze
{
public class Packet
{
public ushort Length;
public ushort Component;
public ushort Command;
public ushort Error;
public ushort QType;
public ushort ID;
public ushort extLength;
public byte[] Content;
}
public static Packet ReadBlazePacket(Stream s)
{
Packet res = new Packet();
res.Length = ReadUShort(s);
res.Component = ReadUShort(s);
res.Command = ReadUShort(s);
res.Error = ReadUShort(s);
res.QType = ReadUShort(s);
res.ID = ReadUShort(s);
if ((res.QType & 0x10) != 0)
res.extLength = ReadUShort(s);
else
res.extLength = 0;
int len = res.Length + (res.extLength << 16);
res.Content = new byte[len];
s.Read(res.Content, 0, len);
return res;
}
public static List<Packet> FetchAllBlazePackets(Stream s)
{
List<Packet> res = new List<Packet>();
s.Seek(0, 0);
while (s.Position < s.Length)
{
res.Add(ReadBlazePacket(s));
}
return res;
}
public static ushort ReadUShort(Stream s)
{
byte[] buff = new byte[2];
s.Read(buff, 0, 2);
return (ushort)((buff[0] << 8) + buff[1]);
}
public static uint ReadUInt(Stream s)
{
byte[] buff = new byte[4];
s.Read(buff, 0, 4);
return (uint)((buff[0] << 24) + (buff[1] << 16) + (buff[2] << 8) + buff[3]);
}
public static string TagToLabel(uint Tag)
{
byte[] buff = BitConverter.GetBytes(Tag);
List<byte> tmp = new List<byte>(buff);
tmp.Reverse();
buff = tmp.ToArray();
string s = "";
foreach (byte b in buff)
{
string t = "";
for (int i = 0; i < 8; i++)
if ((b & (1 << i)) != 0)
t = "1" + t;
else
t = "0" + t;
s += t;
}
string binary = s.Substring(0, 24);
binary = binary.Insert(0, "0");
binary = binary.Insert(2, "0");
binary = binary.Insert(8, "0");
binary = binary.Insert(10, "0");
binary = binary.Insert(16, "0");
binary = binary.Insert(18, "0");
binary = binary.Insert(24, "0");
binary = binary.Insert(26, "0");
s = "";
for (int i = 0; i < binary.Length / 8; i++)
{
byte b = 0;
for (int j = 0; j < 8; j++)
if (binary[i * 8 + 7 - j] == '1')
b += (byte)(1 << j);
s += (char)b;
}
return s.Replace('\0', ' ');
}
public static long DecompressInteger(Stream s)
{
List<byte> tmp = new List<byte>();
byte b;
while ((b = (byte)s.ReadByte()) >= 0x80)
tmp.Add(b);
tmp.Add(b);
byte[] buff = tmp.ToArray();
int currshift = 6;
long result = buff[0] & 0x3F;
for (int i = 1; i < buff.Length; i++)
{
byte curbyte = buff[i];
long l = (curbyte & 0x7F) << currshift;
result |= l;
currshift += 7;
}
return result;
}
public static string ReadString(Stream s)
{
int len = (int)DecompressInteger(s);
string res = "";
for (int i = 0; i < len - 1; i++)
res += (char)s.ReadByte();
s.ReadByte();
return res;
}

public static List<Tdf> ReadStruct(Stream s)
{
List<Tdf> res = new List<Tdf>();
byte b = 0;
while ((b = (byte)s.ReadByte()) != 0)
{
s.Seek(-1, SeekOrigin.Current);
res.Add(ReadTdf(s));
}
return res;
}
public static List<Tdf> ReadPacketContent(Packet p)
{
List<Tdf> res = new List<Tdf>();
MemoryStream m = new MemoryStream(p.Content);
m.Seek(0, 0);
while (m.Position < m.Length)
res.Add(ReadTdf(m));
return res;
}

public static Tdf ReadTdf(Stream s)
{
Tdf res = new Tdf();
uint Head = ReadUInt(s);
res.Tag = (Head & 0xFFFFFF00);
res.Label = TagToLabel(res.Tag);
res.Type = (byte)(Head & 0xFF);
switch (res.Type)
{
case 0:
case 2:
case 6:
case 7:
return ReadTdfInteger(res, s);
case 1:
return ReadTdfString(res, s);
case 3:
return ReadTdfStruct(res, s);
case 4:
return ReadTdfList(res, s);
case 5:
return ReadTdfDoubleList(res, s);
case 9:
return ReadTdfTrippleVal(res, s);
case 8:
return ReadTdfDoubleVal(res, s);
default:
throw new Exception("Unknown Tdf Type: " + res.Type);
}
}
public static TdfInteger ReadTdfInteger(Tdf head, Stream s)
{
TdfInteger res = new TdfInteger();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = (int)DecompressInteger(s);
return res;
}
public static TdfString ReadTdfString(Tdf head, Stream s)
{
TdfString res = new TdfString();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadString(s);
return res;
}
public static TdfStruct ReadTdfStruct(Tdf head, Stream s)
{
TdfStruct res = new TdfStruct();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Values = ReadStruct(s);
return res;
}
public static TdfTrippleVal ReadTdfTrippleVal(Tdf head, Stream s)
{
TdfTrippleVal res = new TdfTrippleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.v1 = (int)DecompressInteger(s);
res.v2 = (int)DecompressInteger(s);
res.v3 = (int)DecompressInteger(s);
return res;
}
public static TdfDoubleVal ReadTdfDoubleVal(Tdf head, Stream s)
{
TdfDoubleVal res = new TdfDoubleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.v1 = (int)DecompressInteger(s);
res.v2 = (int)DecompressInteger(s);
return res;
}
public static TdfList ReadTdfList(Tdf head, Stream s)
{
TdfList res = new TdfList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType)
{
case 0:
if (res.List == null)
res.List = new List<long>();
List<long> l1 = (List<long>)res.List;
l1.Add(DecompressInteger(s));
res.List = l1;
break;
case 1:
if (res.List == null)
res.List = new List<string>();
List<string> l2 = (List<string>)res.List;
l2.Add(ReadString(s));
res.List = l2;
break;
case 3:
if (res.List == null)
res.List = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List;
l3.Add(ReadStruct(s));
res.List = l3;
break;
default:
throw new Exception("Unknown Tdf Type in List: " + res.Type);
}
}
return res;
}
public static TdfDoubleList ReadTdfDoubleList(Tdf head, Stream s)
{
TdfDoubleList res = new TdfDoubleList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType1 = (byte)s.ReadByte();
res.SubType2 = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType1)
{
case 0:
if (res.List1 == null)
res.List1 = new List<long>();
List<long> l1 = (List<long>)res.List1;
l1.Add(DecompressInteger(s));
res.List1 = l1;
break;
case 1:
if (res.List1 == null)
res.List1 = new List<string>();
List<string> l2 = (List<string>)res.List1;
l2.Add(ReadString(s));
res.List1 = l2;
break;
case 3:
if (res.List1 == null)
res.List1 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List1;
l3.Add(ReadStruct(s));
res.List1 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType1);
}
switch (res.SubType2)
{
case 0:
if (res.List2 == null)
res.List2 = new List<long>();
List<long> l1 = (List<long>)res.List2;
l1.Add(DecompressInteger(s));
res.List2 = l1;
break;
case 1:
if (res.List2 == null)
res.List2 = new List<string>();
List<string> l2 = (List<string>)res.List2;
l2.Add(ReadString(s));
res.List2 = l2;
break;
case 3:
if (res.List2 == null)
res.List2 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List2;
l3.Add(ReadStruct(s));
res.List2 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType2);
}
}
return res;
}

public class Tdf
{
public string Label;
public uint Tag;
public byte Type;
public TreeNode ToTree()
{
return new TreeNode(Label + " : " + Type);
}
}
public class TdfInteger : Tdf
{
public int Value;
}
public class TdfString : Tdf
{
public string Value;
}
public class TdfStruct : Tdf
{
public List<Tdf> Values;
}
public class TdfList : Tdf
{
public byte SubType;
public int Count;
public object List;
}
public class TdfDoubleList : Tdf
{
public byte SubType1;
public byte SubType2;
public int Count;
public object List1;
public object List2;
}
public class TdfDoubleVal : Tdf
{
public long v1;
public long v2;
}
public class TdfTrippleVal : Tdf
{
public long v1;
public long v2;
public long v3;
}

}
}


greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby bournejason » 14 Jun 2014, 12:28

COOL!!!
bournejason
User
 
Posts: 12
Joined: 02 Apr 2014, 08:50
Has thanked: 12 time
Have thanks: 0 time

Re: Current Research: Network

Postby WarrantyVoider » 14 Jun 2014, 22:39

found some bugs, here the changes to above code...

Spoiler:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ME3Server_WV
{
public static class Blaze
{
public class Packet
{
public ushort Length;
public ushort Component;
public ushort Command;
public ushort Error;
public ushort QType;
public ushort ID;
public ushort extLength;
public byte[] Content;
}
public static Packet ReadBlazePacket(Stream s)
{
Packet res = new Packet();
res.Length = ReadUShort(s);
res.Component = ReadUShort(s);
res.Command = ReadUShort(s);
res.Error = ReadUShort(s);
res.QType = ReadUShort(s);
res.ID = ReadUShort(s);
if ((res.QType & 0x10) != 0)
res.extLength = ReadUShort(s);
else
res.extLength = 0;
int len = res.Length + (res.extLength << 16);
res.Content = new byte[len];
s.Read(res.Content, 0, len);
return res;
}
public static List<Packet> FetchAllBlazePackets(Stream s)
{
List<Packet> res = new List<Packet>();
s.Seek(0, 0);
while (s.Position < s.Length)
{
res.Add(ReadBlazePacket(s));
}
return res;
}
public static ushort ReadUShort(Stream s)
{
byte[] buff = new byte[2];
s.Read(buff, 0, 2);
return (ushort)((buff[0] << 8) + buff[1]);
}
public static uint ReadUInt(Stream s)
{
byte[] buff = new byte[4];
s.Read(buff, 0, 4);
return (uint)((buff[0] << 24) + (buff[1] << 16) + (buff[2] << 8) + buff[3]);
}
public static string TagToLabel(uint Tag)
{
byte[] buff = BitConverter.GetBytes(Tag);
List<byte> tmp = new List<byte>(buff);
tmp.Reverse();
buff = tmp.ToArray();
string s = "";
foreach (byte b in buff)
{
string t = "";
for (int i = 0; i < 8; i++)
if ((b & (1 << i)) != 0)
t = "1" + t;
else
t = "0" + t;
s += t;
}
string binary = s.Substring(0, 24);
binary = binary.Insert(0, "0");
binary = binary.Insert(2, "0");
binary = binary.Insert(8, "0");
binary = binary.Insert(10, "0");
binary = binary.Insert(16, "0");
binary = binary.Insert(18, "0");
binary = binary.Insert(24, "0");
binary = binary.Insert(26, "0");
s = "";
for (int i = 0; i < binary.Length / 8; i++)
{
byte b = 0;
for (int j = 0; j < 8; j++)
if (binary[i * 8 + 7 - j] == '1')
b += (byte)(1 << j);
s += (char)b;
}
return s.Replace('\0', ' ');
}
public static long DecompressInteger(Stream s)
{
List<byte> tmp = new List<byte>();
byte b;
while ((b = (byte)s.ReadByte()) >= 0x80)
tmp.Add(b);
tmp.Add(b);
byte[] buff = tmp.ToArray();
int currshift = 6;
long result = buff[0] & 0x3F;
for (int i = 1; i < buff.Length; i++)
{
byte curbyte = buff[i];
long l = (curbyte & 0x7F) << currshift;
result |= l;
currshift += 7;
}
return result;
}
public static string ReadString(Stream s)
{
int len = (int)DecompressInteger(s);
string res = "";
for (int i = 0; i < len - 1; i++)
res += (char)s.ReadByte();
s.ReadByte();
return res;
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
public static byte[] PacketToRaw(Packet p)
{
List<byte> res = new List<byte>();
res.Add((byte)(p.Length >> 8));
res.Add((byte)(p.Length & 0xFF));
res.Add((byte)(p.Component >> 8));
res.Add((byte)(p.Component & 0xFF));
res.Add((byte)(p.Command >> 8));
res.Add((byte)(p.Command & 0xFF));
res.Add((byte)(p.Error >> 8));
res.Add((byte)(p.Error & 0xFF));
res.Add((byte)(p.QType >> 8));
res.Add((byte)(p.QType & 0xFF));
res.Add((byte)(p.ID >> 8));
res.Add((byte)(p.ID & 0xFF));
if ((p.QType & 0x10) != 0)
{
res.Add((byte)(p.extLength >> 8));
res.Add((byte)(p.extLength & 0xFF));
}
res.AddRange(p.Content);
return res.ToArray();
}
public struct DoubleVal
{
public long v1;
public long v2;
}
public struct TrippleVal
{
public long v1;
public long v2;
public long v3;
}

public static List<Tdf> ReadStruct(Stream s)
{
List<Tdf> res = new List<Tdf>();
byte b = 0;
while ((b = (byte)s.ReadByte()) != 0)
{
if (b != 2) //WTF?! WHY;WHY;WHY?? but it works... *shrugs*
s.Seek(-1, SeekOrigin.Current);
res.Add(ReadTdf(s));
}
return res;
}
public static List<Tdf> ReadPacketContent(Packet p)
{
List<Tdf> res = new List<Tdf>();
MemoryStream m = new MemoryStream(p.Content);
m.Seek(0, 0);
try
{
while (m.Position < m.Length - 4)
res.Add(ReadTdf(m));
}
catch (Exception ex)
{
throw new Exception(ex.Message + "\n@:" + m.Position.ToString("X"));
}
return res;
}
public static DoubleVal ReadDoubleVal(Stream s)
{
DoubleVal res = new DoubleVal();
res.v1 = DecompressInteger(s);
res.v2 = DecompressInteger(s);
return res;
}
public static TrippleVal ReadTrippleVal(Stream s)
{
TrippleVal res = new TrippleVal();
res.v1 = DecompressInteger(s);
res.v2 = DecompressInteger(s);
res.v3 = DecompressInteger(s);
return res;
}

public static Tdf ReadTdf(Stream s)
{
Tdf res = new Tdf();
uint Head = ReadUInt(s);
res.Tag = (Head & 0xFFFFFF00);
res.Label = TagToLabel(res.Tag);
res.Type = (byte)(Head & 0xFF);
switch (res.Type)
{
case 0:
case 2:
case 6:
return ReadTdfInteger(res, s);
case 1:
return ReadTdfString(res, s);
case 3:
return ReadTdfStruct(res, s);
case 4:
return ReadTdfList(res, s);
case 5:
return ReadTdfDoubleList(res, s);
case 7:
return ReadTdfIntegerList(res, s);
case 8:
return ReadTdfDoubleVal(res, s);
case 9:
return ReadTdfTrippleVal(res, s);
default:
throw new Exception("Unknown Tdf Type: " + res.Type);
}
}
public static TdfInteger ReadTdfInteger(Tdf head, Stream s)
{
TdfInteger res = new TdfInteger();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = (int)DecompressInteger(s);
return res;
}
public static TdfString ReadTdfString(Tdf head, Stream s)
{
TdfString res = new TdfString();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadString(s);
return res;
}
public static TdfStruct ReadTdfStruct(Tdf head, Stream s)
{
TdfStruct res = new TdfStruct();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Values = ReadStruct(s);
return res;
}
public static TdfTrippleVal ReadTdfTrippleVal(Tdf head, Stream s)
{
TdfTrippleVal res = new TdfTrippleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadTrippleVal(s);
return res;
}
public static TdfDoubleVal ReadTdfDoubleVal(Tdf head, Stream s)
{
TdfDoubleVal res = new TdfDoubleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadDoubleVal(s);
return res;
}
public static TdfList ReadTdfList(Tdf head, Stream s)
{
TdfList res = new TdfList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType)
{
case 0:
if (res.List == null)
res.List = new List<long>();
List<long> l1 = (List<long>)res.List;
l1.Add(DecompressInteger(s));
res.List = l1;
break;
case 1:
if (res.List == null)
res.List = new List<string>();
List<string> l2 = (List<string>)res.List;
l2.Add(ReadString(s));
res.List = l2;
break;
case 3:
if (res.List == null)
res.List = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List;
l3.Add(ReadStruct(s));
res.List = l3;
break;
case 9:
if (res.List == null)
res.List = new List<TrippleVal>();
List<TrippleVal> l4 = (List<TrippleVal>)res.List;
l4.Add(ReadTrippleVal(s));
res.List = l4;
break;
default:
throw new Exception("Unknown Tdf Type in List: " + res.Type);
}
}
return res;
}
public static TdfIntegerList ReadTdfIntegerList(Tdf head, Stream s)
{
TdfIntegerList res = new TdfIntegerList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
if (res.List == null)
res.List = new List<long>();
List<long> l1 = (List<long>)res.List;
l1.Add(DecompressInteger(s));
res.List = l1;
}
return res;
}
public static TdfDoubleList ReadTdfDoubleList(Tdf head, Stream s)
{
TdfDoubleList res = new TdfDoubleList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType1 = (byte)s.ReadByte();
res.SubType2 = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType1)
{
case 0:
if (res.List1 == null)
res.List1 = new List<long>();
List<long> l1 = (List<long>)res.List1;
l1.Add(DecompressInteger(s));
res.List1 = l1;
break;
case 1:
if (res.List1 == null)
res.List1 = new List<string>();
List<string> l2 = (List<string>)res.List1;
l2.Add(ReadString(s));
res.List1 = l2;
break;
case 3:
if (res.List1 == null)
res.List1 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List1;
l3.Add(ReadStruct(s));
res.List1 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType1);
}
switch (res.SubType2)
{
case 0:
if (res.List2 == null)
res.List2 = new List<long>();
List<long> l1 = (List<long>)res.List2;
l1.Add(DecompressInteger(s));
res.List2 = l1;
break;
case 1:
if (res.List2 == null)
res.List2 = new List<string>();
List<string> l2 = (List<string>)res.List2;
l2.Add(ReadString(s));
res.List2 = l2;
break;
case 3:
if (res.List2 == null)
res.List2 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List2;
l3.Add(ReadStruct(s));
res.List2 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType2);
}
}
return res;
}

public class Tdf
{
public string Label;
public uint Tag;
public byte Type;
public TreeNode ToTree()
{
return new TreeNode(Label + " : " + Type);
}
}
public class TdfInteger : Tdf
{
public int Value;
}
public class TdfString : Tdf
{
public string Value;
}
public class TdfStruct : Tdf
{
public List<Tdf> Values;
}
public class TdfList : Tdf
{
public byte SubType;
public int Count;
public object List;
}
public class TdfIntegerList : Tdf
{
public int Count;
public List<long> List;
}
public class TdfDoubleList : Tdf
{
public byte SubType1;
public byte SubType2;
public int Count;
public object List1;
public object List2;
}
public class TdfDoubleVal : Tdf
{
public DoubleVal Value;
}
public class TdfTrippleVal : Tdf
{
public TrippleVal Value;
}

}
}


sofar I can read 100% of all packets, even on a bigger MP-log, so now I have to write the code to WRITE that stuff back (aka reverse the reversed^^), also my editor should help too... soon :D

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section

WarrantyVoider has been thanked by:
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 15 Jun 2014, 19:42

WarrantyVoider wrote:yay found out how the labeltags work! bitcompessed ofc, but heres how:

1001 0011 0011 1001 0010 1011
9 3 3 9 2 B

x1x0 0100 x1x1 0011 x1x0 0100 x1x0 1011


0100 0100 0101 0011 0100 0100 0100 1011
4 4 5 3 4 4 4 B
"D" "S" "D" "K"


1. the first line is the 3 input bytes and their binary display
2. now insert zeroes at x-marked places to fill up to 32 bits(positions: 0,2,8,10,16,18,24,26)
3. now read as ascii :D


here a more efficent version to decode the label tags:
Spoiler:
public static string TagToLabel(uint Tag)
{
string s = "";
List<byte> buff = new List<byte>(BitConverter.GetBytes(Tag));
buff.Reverse();
byte[] res = new byte[4];
res[0] |= (byte)((buff[0] & 0x80) >> 1);
res[0] |= (byte)((buff[0] & 0x40) >> 2);
res[0] |= (byte)((buff[0] & 0x30) >> 2);
res[0] |= (byte)((buff[0] & 0x0C) >> 2);

res[1] |= (byte)((buff[0] & 0x02) << 5);
res[1] |= (byte)((buff[0] & 0x01) << 4);
res[1] |= (byte)((buff[1] & 0xF0) >> 4);

res[2] |= (byte)((buff[1] & 0x08) << 3);
res[2] |= (byte)((buff[1] & 0x04) << 2);
res[2] |= (byte)((buff[1] & 0x03) << 2);
res[2] |= (byte)((buff[2] & 0xC0) >> 6);

res[3] |= (byte)((buff[2] & 0x20) << 1);
res[3] |= (byte)((buff[2] & 0x1F));

for (int i = 0; i < 4; i++)
{
if (res[i] == 0)
res[i] = 0x20;
s += (char)res[i];
}
return s;
}

also finished the writing part of the tdfs, here the entire class:
Spoiler:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ME3Server_WV
{
public static class Blaze
{
#region Classes and Structs
public class Packet
{
public ushort Length;
public ushort Component;
public ushort Command;
public ushort Error;
public ushort QType;
public ushort ID;
public ushort extLength;
public byte[] Content;
}
public struct DoubleVal
{
public long v1;
public long v2;
}
public struct TrippleVal
{
public long v1;
public long v2;
public long v3;
}
public class Tdf
{
public string Label;
public uint Tag;
public byte Type;
public TreeNode ToTree()
{
return new TreeNode(Label + " : " + Type);
}
}
public class TdfInteger : Tdf
{
public long Value;
}
public class TdfString : Tdf
{
public string Value;
}
public class TdfStruct : Tdf
{
public List<Tdf> Values;
}
public class TdfList : Tdf
{
public byte SubType;
public int Count;
public object List;
}
public class TdfIntegerList : Tdf
{
public int Count;
public List<long> List;
}
public class TdfDoubleList : Tdf
{
public byte SubType1;
public byte SubType2;
public int Count;
public object List1;
public object List2;
}
public class TdfDoubleVal : Tdf
{
public DoubleVal Value;
}
public class TdfTrippleVal : Tdf
{
public TrippleVal Value;
}
#endregion

#region Functions
public static Packet ReadBlazePacket(Stream s)
{
Packet res = new Packet();
res.Length = ReadUShort(s);
res.Component = ReadUShort(s);
res.Command = ReadUShort(s);
res.Error = ReadUShort(s);
res.QType = ReadUShort(s);
res.ID = ReadUShort(s);
if ((res.QType & 0x10) != 0)
res.extLength = ReadUShort(s);
else
res.extLength = 0;
int len = res.Length + (res.extLength << 16);
res.Content = new byte[len];
s.Read(res.Content, 0, len);
return res;
}
public static List<Packet> FetchAllBlazePackets(Stream s)
{
List<Packet> res = new List<Packet>();
s.Seek(0, 0);
while (s.Position < s.Length)
{
res.Add(ReadBlazePacket(s));
}
return res;
}
public static ushort ReadUShort(Stream s)
{
byte[] buff = new byte[2];
s.Read(buff, 0, 2);
return (ushort)((buff[0] << 8) + buff[1]);
}
public static uint ReadUInt(Stream s)
{
byte[] buff = new byte[4];
s.Read(buff, 0, 4);
return (uint)((buff[0] << 24) + (buff[1] << 16) + (buff[2] << 8) + buff[3]);
}
public static string TagToLabel(uint Tag)
{
string s = "";
List<byte> buff = new List<byte>(BitConverter.GetBytes(Tag));
buff.Reverse();
byte[] res = new byte[4];
res[0] |= (byte)((buff[0] & 0x80) >> 1);
res[0] |= (byte)((buff[0] & 0x40) >> 2);
res[0] |= (byte)((buff[0] & 0x30) >> 2);
res[0] |= (byte)((buff[0] & 0x0C) >> 2);

res[1] |= (byte)((buff[0] & 0x02) << 5);
res[1] |= (byte)((buff[0] & 0x01) << 4);
res[1] |= (byte)((buff[1] & 0xF0) >> 4);

res[2] |= (byte)((buff[1] & 0x08) << 3);
res[2] |= (byte)((buff[1] & 0x04) << 2);
res[2] |= (byte)((buff[1] & 0x03) << 2);
res[2] |= (byte)((buff[2] & 0xC0) >> 6);

res[3] |= (byte)((buff[2] & 0x20) << 1);
res[3] |= (byte)((buff[2] & 0x1F));

for (int i = 0; i < 4; i++)
{
if (res[i] == 0)
res[i] = 0x20;
s += (char)res[i];
}
return s;
}
public static long DecompressInteger(Stream s)
{
List<byte> tmp = new List<byte>();
byte b;
while ((b = (byte)s.ReadByte()) >= 0x80)
tmp.Add(b);
tmp.Add(b);
byte[] buff = tmp.ToArray();
int currshift = 6;
ulong result = (ulong)(buff[0] & 0x3F);
for (int i = 1; i < buff.Length; i++)
{
byte curbyte = buff[i];
ulong l = (ulong)(curbyte & 0x7F) << currshift;
result |= l;
currshift += 7;
}
return (long)result;
}
public static void CompressInteger(long l, Stream s)
{
List<byte> result = new List<byte>();
if (l < 0x40)
{
result.Add((byte)(l & 0xFF));
}
else
{
byte curbyte = (byte)((l & 0x3F) | 0x80);
result.Add(curbyte);
long currshift = l >> 6;
while (currshift >= 0x80)
{
curbyte = (byte)((currshift & 0x7F) | 0x80);
currshift >>= 7;
result.Add(curbyte);
}
result.Add((byte)currshift);
}
foreach (byte b in result)
s.WriteByte(b);
}
public static string ReadString(Stream s)
{
int len = (int)DecompressInteger(s);
string res = "";
for (int i = 0; i < len - 1; i++)
res += (char)s.ReadByte();
s.ReadByte();
return res;
}
public static void WriteString(string str, Stream s)
{
int len;
if(str.EndsWith("\0"))
len = (int)str.Length;
else
len = (int)str.Length + 1;
CompressInteger(len, s);
for (int i = 0; i < len - 1; i++)
s.WriteByte((byte)str[i]);
s.WriteByte(0);
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
public static byte[] PacketToRaw(Packet p)
{
List<byte> res = new List<byte>();
res.Add((byte)(p.Length >> 8));
res.Add((byte)(p.Length & 0xFF));
res.Add((byte)(p.Component >> 8));
res.Add((byte)(p.Component & 0xFF));
res.Add((byte)(p.Command >> 8));
res.Add((byte)(p.Command & 0xFF));
res.Add((byte)(p.Error >> 8));
res.Add((byte)(p.Error & 0xFF));
res.Add((byte)(p.QType >> 8));
res.Add((byte)(p.QType & 0xFF));
res.Add((byte)(p.ID >> 8));
res.Add((byte)(p.ID & 0xFF));
if ((p.QType & 0x10) != 0)
{
res.Add((byte)(p.extLength >> 8));
res.Add((byte)(p.extLength & 0xFF));
}
res.AddRange(p.Content);
return res.ToArray();
}
public static byte[] CreatePacket(ushort Component,ushort Command, ushort Error, ushort QType, ushort ID, List<Tdf> Content)
{
List<byte> res = new List<byte>();
res.Add(0); //0
res.Add(0);
res.Add((byte)(Component >> 8));
res.Add((byte)(Component & 0xFF));
res.Add((byte)(Command >> 8)); //4
res.Add((byte)(Command & 0xFF));
res.Add((byte)(Error >> 8));
res.Add((byte)(Error & 0xFF));
res.Add((byte)(QType >> 8)); //8
res.Add((byte)(QType & 0xFF));
res.Add((byte)(ID >> 8));
res.Add((byte)(ID & 0xFF));
MemoryStream m = new MemoryStream();
foreach (Tdf tdf in Content)
WriteTdf(tdf, m);
int len = (int)m.Length;
res[0] = (byte)((len & 0xFFFF) >> 8);
res[1] = (byte)(len & 0xFF);
if (len > 0xFFFF)
{
res[9] = 0x10;
res.Add((byte)((len & 0xFF000000) >> 24));
res.Add((byte)((len & 0x00FF0000) >> 16));
}
else
res[9] = 0x00;
res.AddRange(m.ToArray());
return res.ToArray();
}
#endregion

#region Reading
public static Tdf ReadTdf(Stream s)
{
Tdf res = new Tdf();
uint Head = ReadUInt(s);
res.Tag = (Head & 0xFFFFFF00);
res.Label = TagToLabel(res.Tag);
res.Type = (byte)(Head & 0xFF);
switch (res.Type)
{
case 0:
case 2:
case 6:
return ReadTdfInteger(res, s);
case 1:
return ReadTdfString(res, s);
case 3:
return ReadTdfStruct(res, s);
case 4:
return ReadTdfList(res, s);
case 5:
return ReadTdfDoubleList(res, s);
case 7:
return ReadTdfIntegerList(res, s);
case 8:
return ReadTdfDoubleVal(res, s);
case 9:
return ReadTdfTrippleVal(res, s);
default:
throw new Exception("Unknown Tdf Type: " + res.Type);
}
}
public static TdfInteger ReadTdfInteger(Tdf head, Stream s)
{
TdfInteger res = new TdfInteger();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = DecompressInteger(s);
return res;
}
public static TdfString ReadTdfString(Tdf head, Stream s)
{
TdfString res = new TdfString();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadString(s);
return res;
}
public static TdfStruct ReadTdfStruct(Tdf head, Stream s)
{
TdfStruct res = new TdfStruct();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Values = ReadStruct(s);
return res;
}
public static TdfTrippleVal ReadTdfTrippleVal(Tdf head, Stream s)
{
TdfTrippleVal res = new TdfTrippleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadTrippleVal(s);
return res;
}
public static TdfDoubleVal ReadTdfDoubleVal(Tdf head, Stream s)
{
TdfDoubleVal res = new TdfDoubleVal();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Value = ReadDoubleVal(s);
return res;
}
public static TdfList ReadTdfList(Tdf head, Stream s)
{
TdfList res = new TdfList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType)
{
case 0:
if (res.List == null)
res.List = new List<long>();
List<long> l1 = (List<long>)res.List;
l1.Add(DecompressInteger(s));
res.List = l1;
break;
case 1:
if (res.List == null)
res.List = new List<string>();
List<string> l2 = (List<string>)res.List;
l2.Add(ReadString(s));
res.List = l2;
break;
case 3:
if (res.List == null)
res.List = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List;
l3.Add(ReadStruct(s));
res.List = l3;
break;
case 9:
if (res.List == null)
res.List = new List<TrippleVal>();
List<TrippleVal> l4 = (List<TrippleVal>)res.List;
l4.Add(ReadTrippleVal(s));
res.List = l4;
break;
default:
throw new Exception("Unknown Tdf Type in List: " + res.Type);
}
}
return res;
}
public static TdfIntegerList ReadTdfIntegerList(Tdf head, Stream s)
{
TdfIntegerList res = new TdfIntegerList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
if (res.List == null)
res.List = new List<long>();
List<long> l1 = (List<long>)res.List;
l1.Add(DecompressInteger(s));
res.List = l1;
}
return res;
}
public static TdfDoubleList ReadTdfDoubleList(Tdf head, Stream s)
{
TdfDoubleList res = new TdfDoubleList();
res.Label = head.Label;
res.Tag = head.Tag;
res.Type = head.Type;
res.SubType1 = (byte)s.ReadByte();
res.SubType2 = (byte)s.ReadByte();
res.Count = (int)DecompressInteger(s);
for (int i = 0; i < res.Count; i++)
{
switch (res.SubType1)
{
case 0:
if (res.List1 == null)
res.List1 = new List<long>();
List<long> l1 = (List<long>)res.List1;
l1.Add(DecompressInteger(s));
res.List1 = l1;
break;
case 1:
if (res.List1 == null)
res.List1 = new List<string>();
List<string> l2 = (List<string>)res.List1;
l2.Add(ReadString(s));
res.List1 = l2;
break;
case 3:
if (res.List1 == null)
res.List1 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List1;
l3.Add(ReadStruct(s));
res.List1 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType1);
}
switch (res.SubType2)
{
case 0:
if (res.List2 == null)
res.List2 = new List<long>();
List<long> l1 = (List<long>)res.List2;
l1.Add(DecompressInteger(s));
res.List2 = l1;
break;
case 1:
if (res.List2 == null)
res.List2 = new List<string>();
List<string> l2 = (List<string>)res.List2;
l2.Add(ReadString(s));
res.List2 = l2;
break;
case 3:
if (res.List2 == null)
res.List2 = new List<List<Tdf>>();
List<List<Tdf>> l3 = (List<List<Tdf>>)res.List2;
l3.Add(ReadStruct(s));
res.List2 = l3;
break;
default:
throw new Exception("Unknown Tdf Type in Double List: " + res.SubType2);
}
}
return res;
}
public static List<Tdf> ReadStruct(Stream s)
{
List<Tdf> res = new List<Tdf>();
byte b = 0;
while ((b = (byte)s.ReadByte()) != 0)
{
if (b != 2)
s.Seek(-1, SeekOrigin.Current);
res.Add(ReadTdf(s));
}
return res;
}
public static List<Tdf> ReadPacketContent(Packet p)
{
List<Tdf> res = new List<Tdf>();
MemoryStream m = new MemoryStream(p.Content);
m.Seek(0, 0);
try
{
while (m.Position < m.Length - 4)
res.Add(ReadTdf(m));
}
catch (Exception ex)
{
throw new Exception(ex.Message + "\n@:" + m.Position.ToString("X"));
}
return res;
}
public static DoubleVal ReadDoubleVal(Stream s)
{
DoubleVal res = new DoubleVal();
res.v1 = DecompressInteger(s);
res.v2 = DecompressInteger(s);
return res;
}
public static TrippleVal ReadTrippleVal(Stream s)
{
TrippleVal res = new TrippleVal();
res.v1 = DecompressInteger(s);
res.v2 = DecompressInteger(s);
res.v3 = DecompressInteger(s);
return res;
}
#endregion

#region Writing
public static void WriteTdf(Tdf tdf, Stream s)
{
s.WriteByte((byte)(tdf.Tag >> 24));
s.WriteByte((byte)(tdf.Tag >> 16));
s.WriteByte((byte)(tdf.Tag >> 8));
s.WriteByte(tdf.Type);
switch (tdf.Type)
{
case 0:
case 2:
case 6:
TdfInteger ti = (TdfInteger)tdf;
CompressInteger(ti.Value, s);
break;
case 1:
TdfString ts = (TdfString)tdf;
WriteString(ts.Value, s);
break;
case 3:
TdfStruct tst = (TdfStruct)tdf;
foreach (Tdf ttdf in tst.Values)
WriteTdf(ttdf, s);
s.WriteByte(0);
break;
case 4:
WriteTdfList((TdfList)tdf, s);
break;
case 5:
WriteTdfDoubleList((TdfDoubleList)tdf, s);
break;
case 7:
TdfIntegerList til = (TdfIntegerList)tdf;
CompressInteger(til.Count, s);
if (til.Count != 0)
foreach (long l in til.List)
CompressInteger(l, s);
break;
case 8:
WriteDoubleValue(((TdfDoubleVal)tdf).Value, s);
break;
case 9:
WriteTrippleValue(((TdfTrippleVal)tdf).Value, s);
break;
}
}
public static void WriteTdfList(TdfList tdf, Stream s)
{
s.WriteByte(tdf.SubType);
CompressInteger(tdf.Count, s);
for (int i = 0; i < tdf.Count; i++)
switch (tdf.SubType)
{
case 0:
CompressInteger(((List<long>)tdf.List)[i], s);
break;
case 1:
WriteString(((List<string>)tdf.List)[i], s);
break;
case 3:
List<Tdf> tl = ((List<List<Tdf>>)tdf.List)[i];
foreach (Tdf ttdf in tl)
WriteTdf(ttdf, s);
s.WriteByte(0);
break;
case 9:
WriteTrippleValue(((List<TrippleVal>)tdf.List)[i], s);
break;
}
}
public static void WriteTdfDoubleList(TdfDoubleList tdf, Stream s)
{
s.WriteByte(tdf.SubType1);
s.WriteByte(tdf.SubType2);
CompressInteger(tdf.Count, s);
for (int i = 0; i < tdf.Count; i++)
{
switch (tdf.SubType1)
{
case 0:
CompressInteger(((List<long>)(tdf.List1))[i], s);
break;
case 1:
WriteString(((List<string>)(tdf.List1))[i], s);
break;
case 3:
List<Tdf> tl = ((List<List<Tdf>>)(tdf.List1))[i];
foreach (Tdf ttdf in tl)
WriteTdf(ttdf, s);
s.WriteByte(0);
break;
}
switch (tdf.SubType2)
{
case 0:
CompressInteger(((List<long>)(tdf.List2))[i], s);
break;
case 1:
WriteString(((List<string>)(tdf.List2))[i], s);
break;
case 3:
List<Tdf> tl = ((List<List<Tdf>>)(tdf.List2))[i];
foreach (Tdf ttdf in tl)
WriteTdf(ttdf, s);
s.WriteByte(0);
break;
}
}
}
public static void WriteTrippleValue(TrippleVal v, Stream s)
{
CompressInteger(v.v1, s);
CompressInteger(v.v2, s);
CompressInteger(v.v3, s);
}
public static void WriteDoubleValue(DoubleVal v, Stream s)
{
CompressInteger(v.v1, s);
CompressInteger(v.v2, s);
}
#endregion
}
}

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 16 Jun 2014, 17:46

and finally here the code for compressing labels to tags:

Spoiler:
public static byte[] Label2Tag(string Label)
{
byte[] res = new byte[3];
if (Label.Length != 4)
return res;
byte[] buff = new byte[4];
for (int i = 0; i < 4; i++)
buff[i] = (byte)Label[i];
res[0] |= (byte)((buff[0] & 0x40) << 1);
res[0] |= (byte)((buff[0] & 0x10) << 2);
res[0] |= (byte)((buff[0] & 0x0F) << 2);
res[0] |= (byte)((buff[1] & 0x40) >> 5);
res[0] |= (byte)((buff[1] & 0x10) >> 4);

res[1] |= (byte)((buff[1] & 0x0F) << 4);
res[1] |= (byte)((buff[2] & 0x40) >> 3);
res[1] |= (byte)((buff[2] & 0x10) >> 2);
res[1] |= (byte)((buff[2] & 0x0C) >> 2);

res[2] |= (byte)((buff[2] & 0x03) << 6);
res[2] |= (byte)((buff[3] & 0x40) >> 1);
res[2] |= (byte)((buff[3] & 0x1F));
return res;
}

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 16 Jun 2014, 18:17

so after all, I can start "creating" packets from scratch, also filling it with values from a config file, I start to like this kind of coding... :D

Image

public static void CreateBootPacket01(Player.PlayerInfo player, Blaze.Packet p)
{
List<Blaze.Tdf> Result = new List<Blaze.Tdf>();
Result.Add(Blaze.TdfInteger.Create("ANON", ConvertHex(Config.FindEntry("ANON"))));
Result.Add(Blaze.TdfString.Create("ASRC", Config.FindEntry("ASRC")));
Result.Add(Blaze.TdfString.Create("INST", Config.FindEntry("INST")));
Result.Add(Blaze.TdfInteger.Create("MINR", ConvertHex(Config.FindEntry("MINR"))));
Result.Add(Blaze.TdfString.Create("NASP", Config.FindEntry("NASP")));
Result.Add(Blaze.TdfString.Create("PLAT", Config.FindEntry("PLAT")));
Result.Add(Blaze.TdfString.Create("RSRC", Config.FindEntry("RSRC")));
Result.Add(Blaze.TdfString.Create("SVER", Config.FindEntry("SVER")));
SendPacket(player, Blaze.CreatePacket(p.Component, p.Command, 0, 0x1000, p.ID, Result));
}


greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 16 Jun 2014, 22:29

WOW, this worked far bettern than expected! the server now works up until authentication and doesnt need to replay a thing! (well ok, the redirector response, as its static)
changes:
-redirector and main server are combined and autostarted on startup
-packetviewer actually works^^
-the packets are generated on the fly (major "!") and according to incoming commands
-added playerlist
-player id is fetched from packets
-server will recognize gamestates (for now just "boot", but later "mainmenu","lobbymp","ingame","finishing",etc)
-everything in the packets is exposed as config file

the first 4 things that can be edited are : ME3DATA, ME3MSG, ME3ENT, ME3DIME ... all as nice txt files :D

Image

as this doesnt contain any auth infos from me, its fine for me to release this one
to circumvent this and still be able to make a server with login (which is essential!), I plan to make a tool to record your own login credentials, so you can add them to the server manually and the server can be distributed without having credentials build in...
this also needs the cracked me3.exe version 1.5.5427.124, I build on this, as it uses ALOT less connections

Download

have fun playing around with it, remember it wont fully boot to mainmenu, but you can watch the inital process (also play with the config files) and read the packets with the viewer

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby WarrantyVoider » 17 Jun 2014, 18:04

here an example on how to use the code to make more complex packets, I really start to like this way of coding :D (the folder "replay" will be missing on next release^^)

The Result:
Spoiler:
Image

The Configuration:
Spoiler:
#Server_Boot_01
ANON =0x0
ASRC =303107
CIDS ={1} {25} {4} {28} {7} {9} {63490} {30720} {15} {30721} {30722} {30723} {30725} {30726} {2000}
BOOTCONF ={pingPeriod ; 15s}{voipHeadsetUpdateRate ; 1000}{xlspConnectionIdleTimeout ; 300}
INST =masseffect-3-pc
MINR =0x0
NASP =cem_ea_id
PLAT =pc
BOOTPSA0 =gossjcprod-qos01.ea.com
BOOTPSP0 =0x445E
BOOTSNA0 =prod-sjc
LNP =0xA
LTPS ={ea-sjc}{rs-iad}{rs-lhr}
BOOTPSA1 =gossjcprod-qos01.ea.com
BOOTPSP1 =0x445E
BOOTSNA1 =prod-sjc
BOOTPSA2 =gosiadprod-qos01.ea.com
BOOTPSP2 =0x445E
BOOTSNA2 =rs-prod-iad
BOOTPSA3 =gosgvaprod-qos01.ea.com
BOOTPSP3 =0x445E
BOOTSNA3 =rs-prod-lhr
SVID =0x45410805
RSRC =303107
SVER =Blaze 3.15.08.0 (CL# 750727)

Aaand the actual code making the packet from the config:
Spoiler:
public static void CreateBootPacket01(Player.PlayerInfo player, Blaze.Packet p)
{
List<Blaze.Tdf> Result = new List<Blaze.Tdf>();
Result.Add(Blaze.TdfInteger.Create("ANON", ConvertHex(Config.FindEntry("ANON"))));
Result.Add(Blaze.TdfString.Create("ASRC", Config.FindEntry("ASRC")));
List<string> t = ConvertStringList(Config.FindEntry("CIDS"));
List<long> t2 = new List<long>();
foreach (string v in t)
t2.Add(Convert.ToInt64(v));
Result.Add(Blaze.TdfList.Create("CIDS", 0, t2.Count, t2));
Result.Add(Blaze.TdfString.Create("CNGN", ""));
t = new List<string>();
List<string> t3 = new List<string>();
ConvertDoubleStringList(Config.FindEntry("BOOTCONF"),out t,out t3);
Blaze.TdfDoubleList conf2 = Blaze.TdfDoubleList.Create("CONF", 1, 1, t, t3, t.Count);
List<Blaze.Tdf> t4 = new List<Blaze.Tdf>();
t4.Add(conf2);
Result.Add(Blaze.TdfStruct.Create("CONF", t4));
Result.Add(Blaze.TdfString.Create("INST", Config.FindEntry("INST")));
Result.Add(Blaze.TdfInteger.Create("MINR", ConvertHex(Config.FindEntry("MINR"))));
Result.Add(Blaze.TdfString.Create("NASP", Config.FindEntry("NASP")));
Result.Add(Blaze.TdfString.Create("PILD", ""));
Result.Add(Blaze.TdfString.Create("PLAT", Config.FindEntry("PLAT")));
Result.Add(Blaze.TdfString.Create("PTAG", ""));
List<Blaze.Tdf> QOSS = new List<Blaze.Tdf>();
List<Blaze.Tdf> BWPS = new List<Blaze.Tdf>();
BWPS.Add(Blaze.TdfString.Create("PSA\0", Config.FindEntry("BOOTPSA0")));
BWPS.Add(Blaze.TdfInteger.Create("PSP\0", ConvertHex(Config.FindEntry("BOOTPSP0"))));
BWPS.Add(Blaze.TdfString.Create("SNA\0", Config.FindEntry("BOOTSNA0")));
QOSS.Add(Blaze.TdfStruct.Create("BWPS", BWPS));
QOSS.Add(Blaze.TdfInteger.Create("LNP\0", ConvertHex(Config.FindEntry("LNP"))));
List<Blaze.Tdf> LTPS1 = new List<Blaze.Tdf>();
LTPS1.Add(Blaze.TdfString.Create("PSA\0", Config.FindEntry("BOOTPSA1")));
LTPS1.Add(Blaze.TdfInteger.Create("PSP\0", ConvertHex(Config.FindEntry("BOOTPSP1"))));
LTPS1.Add(Blaze.TdfString.Create("SNA\0", Config.FindEntry("BOOTSNA1")));
List<Blaze.Tdf> LTPS2 = new List<Blaze.Tdf>();
LTPS2.Add(Blaze.TdfString.Create("PSA\0", Config.FindEntry("BOOTPSA2")));
LTPS2.Add(Blaze.TdfInteger.Create("PSP\0", ConvertHex(Config.FindEntry("BOOTPSP2"))));
LTPS2.Add(Blaze.TdfString.Create("SNA\0", Config.FindEntry("BOOTSNA2")));
List<Blaze.Tdf> LTPS3 = new List<Blaze.Tdf>();
LTPS3.Add(Blaze.TdfString.Create("PSA\0", Config.FindEntry("BOOTPSA3")));
LTPS3.Add(Blaze.TdfInteger.Create("PSP\0", ConvertHex(Config.FindEntry("BOOTPSP3"))));
LTPS3.Add(Blaze.TdfString.Create("SNA\0", Config.FindEntry("BOOTSNA3")));
List<List<Blaze.Tdf>> LTPS = new List<List<Blaze.Tdf>>();
LTPS.Add(LTPS1);
LTPS.Add(LTPS2);
LTPS.Add(LTPS3);
t = ConvertStringList(Config.FindEntry("LTPS"));
QOSS.Add(Blaze.TdfDoubleList.Create("LTPS", 1, 3, t, LTPS, 3));
QOSS.Add(Blaze.TdfInteger.Create("SVID", ConvertHex(Config.FindEntry("SVID"))));
Result.Add(Blaze.TdfStruct.Create("QOSS", QOSS));
Result.Add(Blaze.TdfString.Create("RSRC", Config.FindEntry("RSRC")));
Result.Add(Blaze.TdfString.Create("SVER", Config.FindEntry("SVER")));
SendPacket(player, Blaze.CreatePacket(p.Component, p.Command, 0, 0x1000, p.ID, Result));
}

dunno why, but im kinda proud of that beast of a complex packet^^ also im surprised it actually works :P

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section
User avatar
WarrantyVoider
Emeritus
 
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Current Research: Network

Postby JunkoXan » 15 Jul 2014, 10:59

you're making a lot of progress, just a few more hurdles to leap over and it'll be home free. :)
JunkoXan
User
 
Posts: 233
Joined: 26 Apr 2014, 16:02
Has thanked: 4 time
Have thanks: 15 time

PreviousNext

Return to Technical Research

Who is online

Users browsing this forum: No registered users and 0 guests

suspicion-preferred