VB/VB.Net Packet hash

Inscrit
28 Mars 2015
Messages
38
Reactions
0
#1
Bonjour,

j'ai remarqué lors de la réception du packet 110 que le pseudo du personnage est crypté
Je suis donc allé voir dans crypto/hash et j'y trouve plusieurs classes (Ihash, md5, md2,..)

J'ai donc pensé à HMAC :

Code:
package com.hurlant.crypto.hash
{
	import flash.utils.*;
	import obfuscated.namespace0B56.*;

	public class HMAC extends Object implements IHMAC
	{
		private var hash:IHash;
		private var bits:uint;

		public function HMAC(param1:IHash, param2:uint = 0)
		{
			super();
			this.hash = param1;
			this.bits = param2;
		}

		public function getHashSize() : uint
		{
			if(this.bits != 0)
			{
				return this.bits / 8;
			}
			return this.hash.getHashSize();
		}

		public function compute(param1:ByteArray, param2:ByteArray) : ByteArray
		{
			var _loc_3:ByteArray = null;
			if(param1.length > this.hash.getInputSize())
			{
				_loc_3 = this.hash.hash(param1);
			}
			else
			{
				_loc_3 = new ByteArray();
				_loc_3.writeBytes(param1);
			}
			while(_loc_3.length < this.hash.getInputSize())
			{
				_loc_3[_loc_3.length] = 0;
			}
			var _loc_4:ByteArray = new ByteArray();
			var _loc_5:ByteArray = new ByteArray();
			var _loc_6:uint = 0;
			while(_loc_6 < _loc_3.length)
			{
				_loc_4[_loc_6] = _loc_3[_loc_6] ^ 54;
				_loc_5[_loc_6] = _loc_3[_loc_6] ^ 92;
				_loc_6 = _loc_6 + 1;
			}
			_loc_4.position = _loc_3.length;
			_loc_4.writeBytes(param2);
			var _loc_7:ByteArray = this.hash.hash(_loc_4);
			_loc_5.position = _loc_3.length;
			_loc_5.writeBytes(_loc_7);
			var _loc_8:ByteArray = this.hash.hash(_loc_5);
			if(this.bits > 0 && this.bits < (8 * _loc_8.length))
			{
				_loc_8.length = this.bits / 8;
			}
			return _loc_8;
		}

		public function dispose() : void
		{
			this.hash = null;
			this.bits = 0;
		}

		public function toString() : String
		{
			return "hmac-" + (this.bits > 0 ? this.bits + "-" : "") + this.hash.toString();
		}
	}
}
La traduction de cette classe en vb.net suffit-elle pour décrypter le packet 110 ?

Merci
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#2
Bonjour,

bien pensé mais non, le HASH_FUNCTION est initializé par le RawDataMessage.
Il faut que tu récupère les Bytes du RawDataMessage et que tu les enregistres sous la forme d'un SWF.
Ensuite tu le décompiles et tu regardes la fonction addCryptedHash().

Bonne journée

EDIT: J'y pense le paquet 110 n'est pas crypté >< et encore moins le pseudonyme.
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#3
arf bah j'ai du mal faire quelque chose alors x'(

Merci de ses informations, sa servira surement pour plus tard ;)
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#4
Montres-nous ta fonction Deserialise() du 110.
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#5
La voici :

Code:
Public Function deserializeAs_CharacterMinimalInformations(ByVal param1 As Dofus.DofusReader)
            Me.Id = param1.ReadInt32()
            Me.Level = param1.readUnsignedByte
            Me.Name = param1.ReadUTF()
            Return Me
        End Function
et voici celle du dofusinvoker :

Code:
public function deserializeAs_CharacterMinimalInformations(param1:ICustomDataInput) : void
		{
			super.deserialize(param1);
			this.level = param1.readUnsignedByte();
			if(this.level < 1 || this.level > 200)
			{
				throw new Error("Forbidden value (" + this.level + ") on element of CharacterMinimalInformations.level.");
			}
			this.name = param1.readUTF();
		}
ah bah j'ai oublié l'héritage on dirais, je vais l'ajouter ;)
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#6
Voila le problème, tu ne peux pas lire le LEVEL et le NAME avant l'héritage.
Il y a un ordre à respecter.

Au passage c'est quoi cette variable ID ?

Code:
Me.Id = param1.ReadInt32()
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#7
En faite, c'est une classe que j'ai repris de overedge, il y a 2 ans environ, je l'ai ai reprise dans mon projet actuel sans trop me pauser de questions et j'ai pas vérifié que toutes les classes étaient correcte....
Sa m'apprendra x'(

Du coup pour l'id je sais pas, a virer surement
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#8
Noooooooooooooon malheureux

Vas dans les sources voyons
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#9
Ouais je regarde sa se soir, j'ai commencé a re-traduire les sources tout a l'heure, du coup j'ai un peu gaffé, je fini sa se soir et je vous re dit tout sa ;)
 
Inscrit
27 Juin 2012
Messages
238
Reactions
0
#10
J'ai adoré quand tu as répondu à ton propre problème dans le même post où tu postes les deux sources :D

Toujours vérifier la véracité de son code par rapport à celui des sources. On devrait le mettre en gras quelque part ça !
 

Labo

Membre Actif
Inscrit
16 Aout 2013
Messages
799
Reactions
15
#11
En plus, des sources d'Overedge :roll:
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#12
Les sources ne font que porter son nom, rien ne lui appartient.
Mise à part l'interface :ugeek:
 

Labo

Membre Actif
Inscrit
16 Aout 2013
Messages
799
Reactions
15
#13
:lol:
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#14
Au final je ne reçois rien de mieu...


Soit je reçois :


(les ---- sont pour délimiter le pseudo du niveau)

avec cette classe :

Code:
Public Class CharacterMinimalInformations
        Public Id As UInteger = 0
        Public Level As UInteger = 0
        Public Name As String = String.Empty
        Public ProtocolId As UInteger = 110
        Public Function CharacterMinimalInformations()

            Return Me
        End Function
        Public Function getTypeId() As UInteger

            Return Me.ProtocolId
        End Function
        Public Function initCharacterMinimalInformations(ByVal Param1 As UInteger, ByVal Param2 As UInteger, ByVal Param3 As String)
            Me.id = Param1
            Me.level = Param2
            Me.name = Param3

            Return Me
        End Function
        Public Function reset()
            Me.id = 0
            Me.level = 0
            Me.name = ""

            Return Me
        End Function
        'Public Function serialize(ByVal param1 As Dofus.Dofuswriter)
        '    Me.serializeAs_CharacterMinimalInformations(param1)

        '    Return Me
        'End Function
        'Public Function serializeAs_CharacterMinimalInformations(ByVal param1 As Dofus.Dofuswriter)
        '    If (Me.id < 0) Then

        '        console.writeline("Forbidden value (" + Me.id + ") on element id.")
        '    End If
        '    param1.WriteInt32(Id)

        '    If (Me.Level < 1 Or Me.Level > 200) Then

        '        Console.WriteLine("Forbidden value (" + Me.Level + ") on element level.")
        '    End If
        '    param1.WriteByte(Level)

        '    param1.WriteUTF(Name)


        '    Return Me
        'End Function
        Public Function deserialize(ByVal param1 As Dofus.DofusReader)
            Me.deserializeAs_CharacterMinimalInformations(param1)

            Return Me
        End Function
        Public Function deserializeAs_CharacterMinimalInformations(ByVal param1 As Dofus.DofusReader)
            Me.Id = param1.ReadInt32()
            'If (Me.id < 0) Then

            '    console.writeline("Forbidden value (" + Me.id + ") on element of CharacterMinimalInformations.id.")
            'End If
            Me.Level = param1.ReadByte()
            'If (Me.Level < 1 Or Me.Level > 200) Then

            '    Console.WriteLine("Forbidden value (" + Me.Level + ") on element of CharacterMinimalInformations.level.")
            'End If
            Me.Name = param1.ReadDecimal()

            Return Me
        End Function
    End Class

soit je reçois strictement rien avec :

Code:
Public Class CharacterMinimalInformations
        Inherits AbstractCharacterInformation

        Public Level As UInteger = 0
        Public Name As String = String.Empty
        Public Shadows Const ProtocolId As UInteger = 110

        Public Function CharacterMinimalInformations()
            Return Me
        End Function

        Public Function getTypeId() As UInteger
            Return CharacterMinimalInformations.ProtocolId
        End Function

        Public Function initCharacterMinimalInformations(ByVal Param1 As UInteger, ByVal Param2 As UInteger, ByVal Param3 As String)
            MyBase.initAbstractCharacterInformation(Param1)
            Me.Level = Param2
            Me.Name = Param3
            Return Me
        End Function

        Public Overloads Function reset()
            Me.id = 0
            Me.Level = 0
            Me.Name = ""
            Return Me
        End Function

        Public Overloads Function deserialize(ByVal param1 As Dofus.DofusReader)
            Me.deserializeAs_CharacterMinimalInformations(param1)
            Return Me
        End Function

        Public Function deserializeAs_CharacterMinimalInformations(ByVal param1 As Dofus.DofusReader)
            MyBase.deserialize(param1)
            Me.Level = param1.readUnsignedByte
            Me.Name = param1.ReadUTF()
            Return Me
        End Function


    End Class

et

Code:
Public Class AbstractCharacterInformation

        Public Const protocolId As UInteger = 400
        Public id As UInteger = 0

        Public Function AbstractCharacterInformation()
            Return Me
        End Function

        Public Function GetMessageID()
            Return AbstractCharacterInformation.protocolId
        End Function

        Public Function initAbstractCharacterInformation(ByVal param1 As UInteger)
            Me.id = param1
            Return Me
        End Function

        Public Sub reset()
            Me.id = 0
        End Sub

        Public Sub deserialize(ByVal param1 As Dofus.DofusReader)
            deserializeAs_AbstractCharacterInformation(param1)
        End Sub

        Public Function deserializeAs_AbstractCharacterInformation(ByVal param1 As Dofus.DofusReader)
            Me.id = param1.readUnsignedByte
            Return Me
        End Function

    End Class

J'ai cherché dans BehaviorIsManaged mais je n'ai pas trouvé la classe concernée..

Je ne vois pas ou j'ai pus faire une erreur en créant les 2 dernières classes ?
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#15
Tes deux dernières classe m'ont l'air correcte (je n'ai pas DofusInvoker sous la main).
Montre nous ta manière de Deserializer les messages.
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#16
Code:
Dim ID_Message As Object = Nothing

        Try
            Select Case ID
                Case 0
                    Beep() ' ne doit jamais passer ici

                Case 110
                    ID_Message = New Types.Game.Character.CharacterMinimalInformations
                    ID_Message.Deserialize(PacketData)
                    logsPacket(NoPacket, ID, ID_Message.Name & " ---- " & ID_Message.Level)

                Case 221
                    ID_Message = New Messages.Game.Context.Roleplay.CurrentMapMessage
                    ID_Message.Deserialize(PacketData)
                    Dim ID_Map As String = ID_Message.mapid
                    assignerMap(ID_Map)
                    logsPacket(NoPacket, ID, ID_Map)

                Case 225
                    ID_Message = New Messages.Game.Context.Roleplay.CurrentMapMessage
                    ID_Message.Deserialize(PacketData)
                    Dim ID_Map As String = ID_Message.mapid
                    assignerMap(ID_Map)
                    logsPacket(NoPacket, ID, ID_Map)

                Case Else
                    logsPacket(NoPacket, ID, "Not in use")

            End Select

        Catch e As Exception
            logsPacket(NoPacket, ID, "-> erreur : " & e.Message)
        End Try
Pour information, le 221 & 225 ce passe bien, l'IDMAP est récupéré à chaque fois, j'ai donc procédé de la même manière pour la case 110

et pour ce qui est du dofusReader :

Code:
Public Class DofusReader
        Inherits IO.BinaryReader

        Sub New(ByVal input As IO.Stream)
            MyBase.New(input)
        End Sub

        Sub New(ByVal input As IO.Stream, ByVal encoding As System.Text.Encoding)
            MyBase.New(input, encoding)
        End Sub
        Public Function readUnsignedByte()
            Return ReadByte()
        End Function
        Public Overrides Function ReadByte() As Byte
            Return MyBase.ReadByte()
        End Function

        Public Function ReadUnSignedshort()
            Return ReadUInt16()
        End Function

        Public Overrides Function ReadUInt16() As UShort
            Return (CUShort(ReadByte()) << 8) + ReadByte()
        End Function

        Public Overrides Function ReadBoolean() As Boolean
            Return ReadByte() = 1
        End Function

        Public Function ReadShort()
            Return ReadInt16()
        End Function

        Public Overrides Function ReadInt16() As Short
            Dim Value As UShort = ReadUInt16()
            If Value > Short.MaxValue Then
                Dim Value2 As Short = -(UShort.MaxValue - Value) - 1
                Return Value2
            End If
            Return Value
        End Function

        Public Function ReadInt()
            Return ReadInt32()
        End Function

        Public Overrides Function ReadInt32() As Integer
            Dim Value As UInteger = ReadUInt32()
            If Value > Integer.MaxValue Then
                Dim Value2 As Integer = -(UInteger.MaxValue - Value) - 1
                Return Value2
            End If
            Return Value
        End Function

        Public Overrides Function ReadUInt32() As UInteger
            Return (CUInt(ReadByte()) << 24) + (CUInt(ReadByte()) << 16) + (CUInt(ReadByte()) << 8) + ReadByte()
        End Function

        Public Overrides Function ReadDouble() As Double
            Try
                Dim Bytes() As Byte = ReadBytes(8)
                Array.Reverse(Bytes)
                Return BitConverter.ToDouble(Bytes, 0)
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
            Return Nothing
        End Function

        Public Function ReadUTF()
            Return ReadString()
        End Function

        Public Overrides Function ReadString() As String
            Dim ByteArray() As Byte = MyBase.ReadBytes(ReadUInt16())
            Return System.Text.Encoding.UTF8.GetString(ByteArray)
        End Function

    End Class

je n'y ai pas touché, c'est celui d'overedge


_______________________

EDIT :

Pour ce qui est des 2 classes de dofusInvoker je te les envois :

AbstractCharacterInformation
Code:
package com.ankamagames.dofus.network.types.game.character
{
	import com.ankamagames.jerakine.network.*;

	public class AbstractCharacterInformation extends Object implements INetworkType
	{
		public static const protocolId:uint = 400;
		public var id:uint = 0;

		public function AbstractCharacterInformation()
		{
			super();
		}

		public function getTypeId() : uint
		{
			return 400;
		}

		public function initAbstractCharacterInformation(param1:uint = 0) : AbstractCharacterInformation
		{
			this.id = param1;
			return this;
		}

		public function reset() : void
		{
			this.id = 0;
		}

		public function serialize(param1:ICustomDataOutput) : void
		{
			serializeAs_AbstractCharacterInformation(param1);
		}

		public function serializeAs_AbstractCharacterInformation(param1:ICustomDataOutput) : void
		{
			if(this.id < 0)
			{
				throw new Error("Forbidden value (" + this.id + ") on element id.");
			}
			param1.writeVarInt(this.id);
		}

		public function deserialize(param1:ICustomDataInput) : void
		{
			deserializeAs_AbstractCharacterInformation(param1);
		}

		public function deserializeAs_AbstractCharacterInformation(param1:ICustomDataInput) : void
		{
			this.id = param1.readVarUhInt();
			if(this.id < 0)
			{
				throw new Error("Forbidden value (" + this.id + ") on element of AbstractCharacterInformation.id.");
			}
		}
	}
}

CharacterMinimalInformations
Code:
package com.ankamagames.dofus.network.types.game.character
{
	import com.ankamagames.jerakine.network.*;

	public class CharacterMinimalInformations extends AbstractCharacterInformation implements INetworkType
	{
		public static const protocolId:uint = 110;
		public var level:uint = 0;
		public var name:String = "";

		public function CharacterMinimalInformations()
		{
			super();
		}

		override public function getTypeId() : uint
		{
			return 110;
		}

		public function initCharacterMinimalInformations(param1:uint = 0, param2:uint = 0, param3:String = "") : CharacterMinimalInformations
		{
			super.initAbstractCharacterInformation(param1);
			this.level = param2;
			this.name = param3;
			return this;
		}

		override public function reset() : void
		{
			super.reset();
			this.level = 0;
			this.name = "";
		}

		override public function serialize(param1:ICustomDataOutput) : void
		{
			serializeAs_CharacterMinimalInformations(param1);
		}

		public function serializeAs_CharacterMinimalInformations(param1:ICustomDataOutput) : void
		{
			super.serializeAs_AbstractCharacterInformation(param1);
			if(this.level < 1 || this.level > 200)
			{
				throw new Error("Forbidden value (" + this.level + ") on element level.");
			}
			param1.writeByte(this.level);
			param1.writeUTF(this.name);
		}

		override public function deserialize(param1:ICustomDataInput) : void
		{
			deserializeAs_CharacterMinimalInformations(param1);
		}

		public function deserializeAs_CharacterMinimalInformations(param1:ICustomDataInput) : void
		{
			super.deserialize(param1);
			this.level = param1.readUnsignedByte();
			if(this.level < 1 || this.level > 200)
			{
				throw new Error("Forbidden value (" + this.level + ") on element of CharacterMinimalInformations.level.");
			}
			this.name = param1.readUTF();
		}
	}
}
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#17
Dernière édition:
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#18
Ah ouais d'accord,.. effectivement, il n'y avait pas dans mon dofusReader de méthode pour lire le ReadVarUhInt du coup j'ai pensé à un ReadUnsignedByte mais bon, c'est pas la même chose x'(

je vais étudier ton github ;)
 
Inscrit
28 Mars 2015
Messages
38
Reactions
0
#19
Bon du coup j'ai utilisé ton BigEndianReader, il se trouve que pour la currentmap, sa marche, je la récupère bien.

En revanche, pour le pseudo,

j'ai mis un

Code:
Me.Level = param1.ReadByte
à la place de

Code:
Me.Level = param1.ReadUnsignedByte
Vus que je n'ai pas retrouvé le UnsignedByte mais que la fonction UnsignedByte renvoyait sur la fonction byte, je me suis alors dit que sa changeait pas grand chose de mettre un ReadByte... Peut être me suis-je trompé ?

Voici celle du dofusReader :
Code:
Public Function readUnsignedByte()
            Return ReadByte()
        End Function
        Public Overrides Function ReadByte() As Byte
            Return MyBase.ReadByte()
        End Function
Ce qui nous donne donc dans CharactereMinimalInformations
Code:
Public Overloads Function deserialize(ByVal param1 As BigEndianReader)
            Me.deserializeAs_CharacterMinimalInformations(param1)
            Return Me
        End Function

        Public Function deserializeAs_CharacterMinimalInformations(ByVal param1 As BigEndianReader)
            MyBase.deserialize(param1)
            Me.Level = param1.ReadByte
            Me.Name = param1.ReadUTF()
            Return Me
        End Function
et dans abstractCharactereInformation

Code:
Public Sub deserialize(ByVal param1 As BigEndianReader)
            deserializeAs_AbstractCharacterInformation(param1)
        End Sub

        Public Function deserializeAs_AbstractCharacterInformation(ByVal param1 As BigEndianReader)
            Me.id = param1.ReadVarUhInt
            Return Me
        End Function
Au niveau de ma classe parsing, j'appel le datacheck de cette manière (normalement sa c'est bon) vus que la map est récupérée

Code:
DataCheck(packet_id, New BigEndianReader(New IO.MemoryStream(packet)))
Enfin pour traiter le packet 110 :

Code:
Case 110
                    ID_Message = New Types.Game.Character.CharacterMinimalInformations
                    ID_Message.Deserialize(PacketData)
                    Dim pseudo As String = ID_Message.Name
                    Dim level As String = ID_Message.Level
                    logsPacket(NoPacket, ID, pseudo & " | " & level)
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
149
#20
Pour ma part je ne fais pas de ReadUnsignedByte il me semble. Je te dirais cela ce soir je n'ai rien avec moi. Mon ProtocolBuilder génére la fonction Deserialize() à partir des types de variables.
 
Haut Bas