Commit 5c506cfa authored by aleajactaest's avatar aleajactaest

update spykhanat.py (it can generate yaml file with detail message decoded)

parent 390c448b
*.pcap
*.yaml
*.yml
*.log
*.err
......@@ -117,7 +117,7 @@ class ClientKhanat:
'Referer': 'http://' + self.khanat_host+':'+ str(self.khanat_port_login) + '/ams/index.php?page=register',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0',
'Content-Type': 'application/x-www-form-urlencoded'}
'': 'application/x-www-form-urlencoded'}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
params = urllib.parse.urlencode({'Username': self.login, 'Password': self.password, 'ConfirmPass': self.password, 'Email': self.login+'@khaganat.net', 'TaC': 'on', 'function': 'add_user'})
......
This diff is collapsed.
......@@ -23,6 +23,7 @@ from ctypes import *
import sys
import inspect
import copy
import struct
LOGGER='BitStream'
......
......@@ -22,6 +22,7 @@
import logging
from tools import TPropIndex
from tools import TPVPMode
from tools import Enum
LOGGER='CActionFactory'
INVALID_SLOT = 0xff
......@@ -35,9 +36,23 @@ class CAction:
self.Timeout = 0
self.GameCycle = 0
self.world = world
self.Reference = []
self.Name = ""
def set_name(self, name):
self.Name = name
def get_name(self):
return self.Name
def add_reference(self, ref):
self.Reference.append(ref)
def get_reference(self):
return self.Reference
def get_parameter(self):
return {"Type": "CAction", "Code": self.Code, "Slot": self.Slot, "PropertyCode": self.PropertyCode, "GameCycle": self.GameCycle}
return {"Type": "CAction", "Code": self.Code, "Slot": self.Slot, "PropertyCode": self.PropertyCode, "GameCycle": self.GameCycle, "Reference": self.Reference}
def unpack(self, message):
raise RuntimeError
......@@ -216,7 +231,11 @@ class CActionGeneric(CAction):
def get_parameter(self):
ret = super().get_parameter()
ret["Type"] = "CActionGeneric"
ret["Message"] = self._Message.showAllData()
if not self._Message.checkOnlyZeroAtEnd():
ret["state"] = "message partially decoded"
else:
ret["state"] = 'message decoded'
ret["Message"] = self._Message.extractAllData()
return ret
def set(self, message):
......@@ -239,6 +258,11 @@ class CActionGeneric(CAction):
decodeImpulse.execute(self._Message, world)
self.decoded = True
def decodeImpulseSimple(self, decodeImpulseSimple, world, cGenericMultiPartTemp, Reference = None, Name = ""):
ret = decodeImpulseSimple.execute(self._Message, world, Reference, Name)
self.decoded = True
return ret
def __str__(self):
if self.decoded:
return "CActionGeneric" + super().__str__() + ' => ' + self._Message.showAllData()
......@@ -265,6 +289,7 @@ class CActionGenericMultiPart(CAction):
def get_parameter(self):
ret = super().get_parameter()
ret["Name"] = self.Name
ret["Type"] = "CActionGenericMultiPart"
ret["Number"] = "%d" % self.Number
ret["Part"] = "%d" % self.Part
......@@ -315,13 +340,21 @@ class CActionGenericMultiPart(CAction):
self.Part = 0
self.NbBlock = 0
def genericAction(self, decodeImpulse, world, cGenericMultiPartTemp):
def genericAction(self, decodeImpulse, world, cGenericMultiPartTemp, Reference, Name):
'''
khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::genericAction (CActionGenericMultiPart *agmp)
'''
logging.getLogger(LOGGER).debug("Number:%d Part:%d NbBlock:%d" % (self.Number, self.Part, self.NbBlock))
cGenericMultiPartTemp.addGenericMultiPartTemp(self.Number)
cGenericMultiPartTemp.setGenericMultiPartTemp(self.Number, self.Part, self.NbBlock, self.PartCont, decodeImpulse, world)
cGenericMultiPartTemp.setGenericMultiPartTemp(self.Number, self.Part, self.NbBlock, self.PartCont, decodeImpulse, world, Reference, Name)
def decodeImpulseSimple(self, decodeImpulseSimple, world, cGenericMultiPartTemp, Reference = None, Name = ""):
logging.getLogger(LOGGER).debug("Number:%d Part:%d NbBlock:%d" % (self.Number, self.Part, self.NbBlock))
cGenericMultiPartTemp.addGenericMultiPartTemp(self.Number)
ret = cGenericMultiPartTemp.setGenericMultiPartTemp(self.Number, self.Part, self.NbBlock, self.PartCont, decodeImpulseSimple, world, Reference, Name)
#ret = decodeImpulseSimple.execute(self._Message, world)
self.decoded = True
return ret
def __str__(self):
return "CActionGenericMultiPart" + super().__str__() + "[" + str(self.Number) + ',' + str(self.Part) + ',' + str(self.NbBlock) + ',read:' + self.PartCont.showAllData() + ',write:' + self.PartCont.showAllDataWrite() + ']'
......@@ -445,3 +478,27 @@ class CActionBlock:
def __str__(self):
return "CActionBlock [Cycle:" + str(self.Cycle) + ', FirstPacket:' + str(self.FirstPacket) + ', Data:' + ', '.join([ str(x) for x in self.Actions]) + "]"
class CActionFake():
def __init__(self, Type, msgin, addon = None, Reference=None, Name=""):
self.Type = Type
self.Code = Enum.TActionCode.ACTION_NONE
self._Message = msgin
self.addon = addon
self.Reference = [ Reference ]
self.Name = Name
def get_name(self):
return self.Name
def get_parameter(self):
ret = {"Type": "CActionFake.%s" % self.Type}
if not self._Message.checkOnlyZeroAtEnd():
ret["state"] = "message partially decoded"
else:
ret["state"] = 'message decoded'
if self.addon:
for key in self.addon:
ret[key] = str(self.addon[key])
ret["Reference"] = self.Reference
ret["Message"] = self._Message.extractAllData()
return ret
......@@ -91,7 +91,7 @@ class CActionFactory:
action.Slot = slot
return action
def unpack(self, msgin):
def unpack(self, msgin, Reference = None, Name = None):
'''
khanat-opennel-code/code/ryzom/common/src/game_share/action_factory.cpp : CAction *CActionFactory::unpack (NLMISC::CBitMemStream &message, NLMISC::TGameCycle /* currentCycle */ )
'''
......@@ -113,6 +113,10 @@ class CActionFactory:
else:
log = logging.getLogger('myLogger')
log.warning('Unpacking an action with unknown code, skip it (%u)' % code)
if Reference:
action.add_reference(Reference)
if Name:
action.set_name(Name)
return action
......@@ -32,12 +32,19 @@ class CGenericMultiPartTemp():
self.BlockReceived = []
self.MsgDecoded = None
self.FirstRead = False
self.Reference = []
self.Name = None
def set(self, Number, Part, NbBlock, PartCont, decodeImpulse, world):
def set(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
'''
khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::CGenericMultiPartTemp::set (CActionGenericMultiPart *agmp, CNetworkConnection *parent)
'''
logging.getLogger(LOGGER).debug("set Number:%d Part:%d NbBlock:%d" % (Number, Part, NbBlock))
ret = None
if not self.Name:
self.Name = Name
if Reference:
self.Reference.append(Reference)
if self.NbBlock == 0xFFFFFFFF:
# Initialize
self.NbBlock = NbBlock
......@@ -49,7 +56,7 @@ class CGenericMultiPartTemp():
while len(self.BlockReceived) < NbBlock:
self.BlockReceived.append(False)
if self.BlockReceived[Part]:
logging.getLogger(LOGGER).warning('This part is already received, discard it %d' % Part)
logging.getLogger(LOGGER).debug('This part is already received, discard it %d' % Part)
return
self.Temp[Part] = PartCont
self.BlockReceived[Part] = True
......@@ -64,11 +71,12 @@ class CGenericMultiPartTemp():
self.NbBlock == 0xFFFFFFFF
for data in self.Temp:
bms.pushBitStream(data)
decodeImpulse.execute(bms, world)
ret = decodeImpulse.execute(bms, world)
logging.getLogger(LOGGER).debug("CGenericMultiPartTemp : data : %s" % bms.showAllData())
self.MsgDecoded = bms
else:
logging.getLogger(LOGGER).debug("CGenericMultiPartTemp : Wait other block")
return ret
def isAvailable(self):
if self.MsgDecoded and not self.FirstRead:
......@@ -87,5 +95,5 @@ class GenericMultiPartTemp():
def addGenericMultiPartTemp(self, Number):
self.data.setdefault(Number, CGenericMultiPartTemp())
def setGenericMultiPartTemp(self, Number, Part, NbBlock, PartCont, decodeImpulse, world):
self.data[Number].set(Number, Part, NbBlock, PartCont, decodeImpulse, world)
def setGenericMultiPartTemp(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
self.data[Number].set(Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference, Name)
......@@ -38,7 +38,7 @@ class CImpulseDecoder:
def decode(self, msgin, receivedPacket, receivedAck, nextSentPacket):
'''
khanat-opennel-code/code/ryzom/client/src/impulse_decoder.cpp:38 oid CImpulseDecoder::decode(CBitMemStream &inbox, TPacketNumber receivedPacket, TPacketNumber receivedAck, TPacketNumber nextSentPacket, vector<CLFECOMMON::CAction *> &actions)
khanat-opennel-code/code/ryzom/client/src/impulse_decoder.cpp:38 void CImpulseDecoder::decode(CBitMemStream &inbox, TPacketNumber receivedPacket, TPacketNumber receivedAck, TPacketNumber nextSentPacket, vector<CLFECOMMON::CAction *> &actions)
'''
logging.getLogger(LOGGER).debug("*" * 80)
logging.getLogger(LOGGER).debug("receivedPacket:%d receivedAck:%d nextSentPacket:%d" %(receivedPacket, receivedAck, nextSentPacket))
......
......@@ -351,6 +351,11 @@ class DecodeImpulse():
def impulseDatabaseInitPlayer(self, msgin, world):
logging.getLogger(LOGGER).debug("TODO")
def impulseSetConnectionAskName(self, msgin, world):
# _ = msgin.readUtf8String('Name')
_ = msgin.readUString('Name')
_ = msgin.readUint32('HomeSessionId')
def initializeNetwork(self):
self.GenericMsgHeaderMngr.setdefault('DB_UPD_PLR', self.impulseDatabaseUpdatePlayer)
self.GenericMsgHeaderMngr.setdefault('DB_INIT:PLR', self.impulseDatabaseInitPlayer)
......@@ -493,6 +498,9 @@ class DecodeImpulse():
self.GenericMsgHeaderMngr.setdefault( "NPC_ICON:SVR_EVENT_MIS_AVL", self.impulseServerEventForMissionAvailability )
self.GenericMsgHeaderMngr.setdefault( "NPC_ICON:SET_TIMER", self.impulseSetNpcIconTimer )
# Send by client
self.GenericMsgHeaderMngr.setdefault( "CONNECTION:ASK_NAME", self.impulseSetConnectionAskName )
def sizeElement(self, keys = None):
head = self.msgXml
if not keys:
......@@ -540,6 +548,7 @@ class DecodeImpulse():
nbBit = getPowerOf2.getPowerOf2(len(head))
id = msgin.readSerial(nbBit, name='MsgXML', typeName='Number', emulate=True)
logging.getLogger(LOGGER).debug("XML DECODE : %3d -> %s" % (nbBit, ':'.join(listpath)) )
ele = head[id]
name = ele.attrib['name']
listpath.append(name)
......
......@@ -539,6 +539,8 @@ class TActionCode(IntEnum):
ACTION_LOGIN_CODE = 13
ACTION_TARGET_SLOT_CODE = 40
ACTION_DUMMY_CODE = 99
ACTION_NONE = 999
class Card(IntEnum):
BEGIN_TOKEN = 0
......@@ -550,6 +552,7 @@ class Card(IntEnum):
FLAG_TOKEN = 6
EXTEND_TOKEN = 7
class TType(IntEnum):
STRUCT_BEGIN = 0
STRUCT_END = 1
......@@ -563,3 +566,14 @@ class TType(IntEnum):
FLOAT64 = 9
EXTEND_TYPE = 10
NB_TYPE = 11
class NPC_ICON(IntEnum): # TNPCMissionGiverState
AwaitingFirstData = 0
NotAMissionGiver = 1
ListHasOutOfReachMissions = 2
ListHasAlreadyTakenMissions = 3
ListHasAvailableMission = 4
AutoHasUnavailableMissions = 5
AutoHasAvailableMission = 6
NbMissionGiverStates = 7
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment