Skip to content

Commit

Permalink
Protobuf parser
Browse files Browse the repository at this point in the history
  • Loading branch information
meji46 committed Jan 1, 2024
1 parent cd30ae4 commit 52c2f23
Show file tree
Hide file tree
Showing 73 changed files with 149,082 additions and 36 deletions.
22 changes: 22 additions & 0 deletions WowPacketParser/Enums/ServiceHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace WowPacketParser.Enums
{
public enum ServiceHash : uint
{
AccountService = 0x62DA0891,
AuthenticationListener = 0x71240E35,
AuthenticationService = 0xDECFC01,
ChallengeService = 0xBBDA171F,
ClubListener = 0x80909D73,
ClubService = 0xE273DE0E,
ClubMembershipListener = 0x2B34597B,
ClubMembershipService = 0x94B94786,
ConnectionService = 0x65446991,
FriendsService = 0xA3DDB1BD,
GameUtilitiesService = 0x3FC1274D,
PresenceListener = 0x890AB85F,
ReportService = 0x7CAF61C9,
ReportServiceV2 = 0x3A4218FB,
ResourceService = 0xECBE75BA,
UserManagerService = 0x3E19268A
}
}
22 changes: 22 additions & 0 deletions WowPacketParser/Misc/MethodCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace WowPacketParser.Misc
{
public struct MethodCall
{
public MethodCall(ulong type, ulong objectId, uint token)
{
Type = type;
ObjectId = objectId;
Token = token;
}

public ulong Type;

public ulong ObjectId;

public uint Token;

public uint GetServiceHash() { return (uint)(Type >> 32); }

public uint GetMethodId() { return (uint)(Type & 0xFFFFFFFF); }
}
}
2 changes: 1 addition & 1 deletion WowPacketParser/PacketStructures/ProtoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static UniversalSplineFlag ToUniversal(this SplineFlag flags)
universal |= UniversalSplineFlag.UncompressedPath;
return universal;
}

public static CreateObjectType ToCreateObjectType(this UpdateTypeCataclysm updateTypeCataclysm)
{
if (updateTypeCataclysm == UpdateTypeCataclysm.CreateObject1)
Expand Down
53 changes: 53 additions & 0 deletions WowPacketParser/Parsing/Parsers/BattlenetProtoHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using WowPacketParser.Enums;
using WowPacketParser.Misc;

namespace WowPacketParser.Parsing.Parsers
{
public static class BattlenetProtoHandler
{
public static MethodCall ReadMethodCall(Packet packet, params object[] idx)
{
var method = new MethodCall();

method.Type = packet.ReadUInt64("Type", idx);
method.ObjectId = packet.ReadUInt64("ObjectId", idx);
method.Token = packet.ReadUInt32("Token", idx);

return method;
}

public static void ReadProtoData(Packet packet, int length, MethodCall method, params object[] indexes)
{
packet.AddValue("MethodCall", "ServiceHash: 0x" + method.GetServiceHash().ToString("X") + " MethodID: " + method.GetMethodId(), indexes);
packet.ReadBytesTable("Message", length, indexes);
}

[Parser(Opcode.CMSG_BATTLENET_REQUEST)]
public static void HandleBattlenetRequest(Packet packet)
{
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}

[Parser(Opcode.SMSG_BATTLENET_NOTIFICATION)]
public static void HandleBattlenetNotification(Packet packet)
{
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}

[Parser(Opcode.SMSG_BATTLENET_RESPONSE)]
public static void HandleBattlenetResponse(Packet packet)
{
packet.ReadInt32E<BattlenetRpcErrorCode>("BnetStatus");
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Text.Json;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;

namespace WowPacketParserModule.V10_0_0_46181.Protos.V10_2_0_52649
{
public static class BattlenetProtoHandler
{
public static MethodCall ReadMethodCall(Packet packet, params object[] idx)
{
var method = new MethodCall();

method.Type = packet.ReadUInt64("Type", idx);
method.ObjectId = packet.ReadUInt64("ObjectId", idx);
method.Token = packet.ReadUInt32("Token", idx);

return method;
}

public static void ReadProtoData(Packet packet, int length, MethodCall method, params object[] indexes)
{
var val = packet.ReadBytes(length);

var parser = ProtobufParser.GetParser(method.GetServiceHash(), method.GetMethodId(), packet.Opcode);

if (parser == null)
{
packet.AddValue("MethodCall", "ServiceHash: 0x" + method.GetServiceHash().ToString("X") + " MethodID: " + method.GetMethodId(), indexes);
packet.AddValue("Message", Convert.ToHexString(val), indexes);
return;
}

packet.AddValue("Type", ProtobufParser.GetParserName(parser), indexes);

var msg = parser.ParseFrom(val).ToString();
var formattedMsg = JsonSerializer.Serialize(JsonDocument.Parse(msg), new JsonSerializerOptions
{
WriteIndented = true
});

packet.AddValue("Message", System.Environment.NewLine + formattedMsg, indexes);
}

[Parser(Opcode.CMSG_BATTLENET_REQUEST)]
public static void HandleBattlenetRequest(Packet packet)
{
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}

[Parser(Opcode.SMSG_BATTLENET_NOTIFICATION)]
public static void HandleBattlenetNotification(Packet packet)
{
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}

[Parser(Opcode.SMSG_BATTLENET_RESPONSE)]
public static void HandleBattlenetResponse(Packet packet)
{
packet.ReadInt32E<BattlenetRpcErrorCode>("BnetStatus");
var method = ReadMethodCall(packet, "Method");

int protoSize = packet.ReadInt32();
ReadProtoData(packet, protoSize, method, "Data");
}
}
}
Loading

0 comments on commit 52c2f23

Please sign in to comment.