Skip to content

Support new socket parsing

LucBerge edited this page Apr 26, 2021 · 8 revisions

B4D can read incoming sockets from the Dofus server. While creating you API, you might want to be able to parse sockets that are not parsed yet. I'll introduce you how I reversed engineer chat message sockets. Before going any futher, you'll need to understand the general structure of a dofus socket.

Dofus socket structure

Explain the dofus socket structure

ID Flags Length Payload Checksum
1 1 * * *

Prerequisits

  • Download and install WireShark
  • Start Dofus and connect to a server
  • Start WireShark and start listening

Reverse Engineering

Step 1 : Identify the sockets you need to parse

The objective of this step is to identify, in WireShark, the sockets you are looking for.

  • Open a terminal and paste the following command to identify the dofus server you are connected to: netstat -a -p TCP -n | findstr :5555

  • In WireShark, add an ip filter to see the incoming sockets from the server: ip.src == 172.65.232.71

  • In the dofus chat, copy a word that someone said. eg: "Kamas".
  • In WireShark, add a content filter to see the sockets containing the word. ip.src == 172.65.232.71 && frame contains "Kamas"

  • In WireShark, identify the socket id (0x03 in V2.59).

  • In WireShark, add a byte filter to see the sockets starting with this id: ip.src == 172.65.232.71 && data[0] == 03

The displayed sockets are now chat messages only. Those are the one you'll need to reverse engineer and parse.

Step 2 : Reverse Engineer the socket

This step is the most complicated and long one. You'll have to find the payload structure from scratch without any documentation. There are multiple ways of doing it. Here is a list of tips you can do:

  • Start by collecting a lot of sockets in WireShark and save the records in a local file. You can then work from this file in offline without Dofus.
  • In the recorded sockets, find the common bytes to identify the delimiters.
  • You can also force the event to happend and look for the location of the expected data in the socket.

Be patient and try hard, ask for help if needed...

The payload structure I found for chat messages is the following:

Channel ID Message length Message 0x5e Id something Length something Something Something else Pseudo length Pseudo ...
1 2 * 1 3 2 * 8 2 * ...

Step 3 : Create the parser

  • In the package fr.B4D.socket.event, create a new event class extending the DofusEvent class. This class will represent you dofus event once parsed. It must be a simple class containing attributs and there getters. The attributs can only be defined in the constructor.

  • In the package fr.B4D.socket.parse, create a new parse class extending the SocketParser<YOU_EVENT_CLASS> class.

  • Implement the parse method based on the payload structure you identified in step 2. Once all the fields have been identified, you can create the event and return it.

  • In the class fr.B4D.socket.DofusSocketType, map the socket id with the parser by adding a value.

At this step, all the sockets starting with the registered id will be parsed using the parser. The event will be created and added to the event store.

Clone this wiki locally