Skip to content

Commit

Permalink
handler handler handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-heinz committed Jan 11, 2022
1 parent db64273 commit d485c01
Show file tree
Hide file tree
Showing 12 changed files with 18,994 additions and 32 deletions.
103 changes: 75 additions & 28 deletions Arrowgene.Ddon.Cli/Command/PcapDecryptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Arrowgene.Ddon.Cli.Misc;
using System.Text.Json;
using Arrowgene.Ddon.PacketLibrary;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
Expand All @@ -22,32 +22,89 @@ public class PcapDecryptCommand : ICommand
0x24, 0x63, 0x62, 0x4D, 0x36, 0x57, 0x50, 0x29, 0x61, 0x58, 0x3D, 0x25, 0x4A, 0x5E, 0x7A, 0x41
};

/// <summary>
/// json|pcap
/// json/pcap path
/// decryption key
/// ex.: pcap F:\\capture.pcap 00112233445566778899AABBCCDDEEFF
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public CommandResultType Run(CommandParameter parameter)
{
string pcapPath = parameter.Arguments[0];
string key = parameter.Arguments[1];
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
List<Packet> packets = new List<Packet>();
if (parameter.Arguments[0] == "json")
{
String json = File.ReadAllText(parameter.Arguments[1]);
PlPacketStream packetStream = JsonSerializer.Deserialize<PlPacketStream>(json);
if (packetStream.Encrypted)
{
byte[] keyBytes = Encoding.UTF8.GetBytes(parameter.Arguments[2]);
List<Packet> decrypted = Decrypt(packetStream.Packets, keyBytes);
packets.AddRange(decrypted);
}
else
{
List<Packet> converted = Convert(packetStream.Packets);
packets.AddRange(converted);
}
}
else if (parameter.Arguments[0] == "pcap")
{
PlFactory plFactory = new PlFactory();
List<PlSession> sessions = plFactory.Create(parameter.Arguments[1]);
List<PlPacket> encrypted = sessions[2].GetPackets(); // hardcoded session index
byte[] keyBytes = Encoding.UTF8.GetBytes(parameter.Arguments[2]);
List<Packet> decrypted = Decrypt(encrypted, keyBytes);
packets.AddRange(decrypted);
}
else
{
return CommandResultType.Continue;
}

PlFactory plFactory = new PlFactory();
List<PlSession> sessions = plFactory.Create(pcapPath);
List<PlPacket> encrypted = sessions[2].GetPackets();
PrintPackets(packets);
return CommandResultType.Continue;
}

PrintPackets(encrypted, keyBytes);
private void PrintPackets(List<Packet> packets)
{
StringBuilder sb = new StringBuilder();
foreach (Packet packet in packets)
{
string text = $"Id:{packet.Id.GroupId}.{packet.Id.HandlerId}.{packet.Id.HandlerSubId}{Environment.NewLine}" +
$"Name:{packet.Id.Name}{Environment.NewLine}" +
$"{Util.HexDump(packet.Data)}";
Console.WriteLine(text);
sb.Append(text);
}

return CommandResultType.Continue;
// string dump = PacketDump.DumpCSharpStruc(packets, "GameFull");
// File.WriteAllText("F://game_full.txt", sb.ToString());
}

private void PrintPackets(List<PlPacket> encrypted, byte[] keyBytes)
private List<Packet> Convert(List<PlPacket> plPackets)
{
List<Packet> packets = new List<Packet>();
foreach (PlPacket plPacket in plPackets)
{
// parsng decrypted packets not supported in packet factory
}

return packets;
}

private List<Packet> Decrypt(List<PlPacket> encrypted, byte[] keyBytes)
{
PacketFactory pfServer = new PacketFactory(new ServerSetting(), PacketIdResolver.GamePacketIdResolver);
PacketFactory pfClient = new PacketFactory(new ServerSetting(), PacketIdResolver.GamePacketIdResolver);
pfServer.SetCamelliaKey(keyBytes);
pfClient.SetCamelliaKey(keyBytes);

List<Packet> packets = new List<Packet>();
try

foreach (PlPacket encPacket in encrypted)
{
foreach (PlPacket encPacket in encrypted)
try
{
if (encPacket.Direction == "S2C")
{
Expand All @@ -60,23 +117,13 @@ private void PrintPackets(List<PlPacket> encrypted, byte[] keyBytes)
packets.AddRange(decrypted);
}
}
}
catch (Exception ex)
{
}

StringBuilder sb = new StringBuilder();
foreach (Packet packet in packets)
{
string text = $"Id:{packet.Id.GroupId}.{packet.Id.HandlerId}.{packet.Id.HandlerSubId}{Environment.NewLine}" +
$"Name:{packet.Id.Name}{Environment.NewLine}" +
$"{Util.HexDump(packet.Data)}";
Console.WriteLine(text);
sb.Append(text);
catch (Exception ex)
{
// try whatever we can
}
}

// string dump = PacketDump.DumpCSharpStruc(packets, "InGameDump");
// File.WriteAllText("F://game2.txt", sb.ToString());
return packets;
}

public void Shutdown()
Expand Down
12 changes: 12 additions & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public override GameClient NewClient(ITcpSocket socket)
private void LoadPacketHandler()
{
AddHandler(new AchievementAchievementGetReceivableRewardListHandler(this));

AddHandler(new AreaGetAreaBaseInfoListHandler(this));
AddHandler(new AreaGetLeaderAreaReleaseListHandler(this));

AddHandler(new BattleContentInfoListHandler(this));
AddHandler(new BlackListGetBlackListHandler(this));

Expand Down Expand Up @@ -89,11 +92,15 @@ private void LoadPacketHandler()

AddHandler(new GroupChatGroupChatGetMemberListHandler(this));

AddHandler(new InstanceGetOmInstantKeyValueAllHandler(this));

AddHandler(new ItemGetStorageItemListHandler(this));
AddHandler(new ItemSortGetItemSortDataBinHandler(this));

AddHandler(new JobGetJobChangeListHandler(this));
AddHandler(new LoadingInfoLoadingGetInfoHandler(this));

AddHandler(new LobbyLobbyChatMsgHandler(this));
AddHandler(new LobbyLobbyJoinHandler(this));

AddHandler(new MailMailGetListDataHandler(this));
Expand All @@ -107,6 +114,8 @@ private void LoadPacketHandler()

AddHandler(new PartnerPawnPawnLikabilityReleasedRewardListGetHandler(this));

AddHandler(new PartyPartyCreateHandler(this));

AddHandler(new PawnGetMyPawnListHandler(this));
AddHandler(new PawnGetRentedPawnListHandler(this));

Expand All @@ -118,7 +127,10 @@ private void LoadPacketHandler()
AddHandler(new ServerGetServerListHandler(this));

AddHandler(new SkillGetCurrentSetSkillListHandler(this));

AddHandler(new StageAreaChangeHandler(this));
AddHandler(new StageGetStageListHandler(this));

AddHandler(new StampBonusCheckHandler(this));

AddHandler(new WarpGetFavoriteWarpPointListHandler(this));
Expand Down
Loading

0 comments on commit d485c01

Please sign in to comment.