This commit is contained in:
AleaJactaEst 2020-11-25 20:57:28 +01:00
parent 8c4e52f6f6
commit 65f0ee64cc
4 changed files with 59 additions and 66 deletions

View file

@ -118,9 +118,9 @@ class SpyPcap():
file = open( self.pcap_file , 'rb') file = open( self.pcap_file , 'rb')
pcapfile = savefile.load_savefile(file,verbose=False) pcapfile = savefile.load_savefile(file,verbose=False)
for pkt in pcapfile.packets: for pkt in pcapfile.packets:
print("pkt:", dir(pkt)) #print("pkt:", dir(pkt))
print("pkt.header:", dir(pkt.header)) #print("pkt.header:", dir(pkt.header))
print("pkt.packet:", dir(pkt.packet)) #print("pkt.packet:", dir(pkt.packet))
logging.getLogger(LOGGER).debug("raw: %s" % pkt.raw()) logging.getLogger(LOGGER).debug("raw: %s" % pkt.raw())
logging.getLogger(LOGGER).debug("timestamp: %s (%s)" % (pkt.timestamp,datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S"))) logging.getLogger(LOGGER).debug("timestamp: %s (%s)" % (pkt.timestamp,datetime.fromtimestamp(pkt.timestamp).strftime("%Y/%m/%d %H:%M:%S")))
eth_frame = ethernet.Ethernet(pkt.raw()) eth_frame = ethernet.Ethernet(pkt.raw())
@ -128,16 +128,16 @@ class SpyPcap():
if eth_frame.type == 2048: if eth_frame.type == 2048:
ip_packet = ip.IP(binascii.unhexlify(eth_frame.payload)) ip_packet = ip.IP(binascii.unhexlify(eth_frame.payload))
logging.getLogger(LOGGER).debug("ip packet: %s" % ip_packet) logging.getLogger(LOGGER).debug("ip packet: %s" % ip_packet)
print("ip_packet:", dir(ip_packet)) #print("ip_packet:", dir(ip_packet))
logging.getLogger(LOGGER).debug("ip packet: %s ->%s" % (ip_packet.src.decode(), ip_packet.dst.decode()) ) logging.getLogger(LOGGER).debug("ip packet: %s ->%s" % (ip_packet.src.decode(), ip_packet.dst.decode()) )
if ip_packet.p == 17: if ip_packet.p == 17:
# UDP # UDP
logging.getLogger(LOGGER).debug("ip packet: protocol UDP (%s)" % ip_packet.p) logging.getLogger(LOGGER).debug("ip packet: protocol UDP (%s)" % ip_packet.p)
udp_packet = udp.UDP(binascii.unhexlify(ip_packet.payload)) udp_packet = udp.UDP(binascii.unhexlify(ip_packet.payload))
print("udp_packet:", dir(udp_packet)) #print("udp_packet:", dir(udp_packet))
logging.getLogger(LOGGER).debug("UDP packet: %s" % udp_packet) logging.getLogger(LOGGER).debug("UDP packet: %s" % udp_packet)
data = udp_packet.payload data = udp_packet.payload
print("data:", dir(data)) #print("data:", dir(data))
logging.getLogger(LOGGER).debug("data packet: %s" % data) logging.getLogger(LOGGER).debug("data packet: %s" % data)
data = udp_packet.payload data = udp_packet.payload
logging.getLogger(LOGGER).info("data packet: timestamp:%s src:%s:%d dst:%s:%d data:%s" % (pkt.timestamp, logging.getLogger(LOGGER).info("data packet: timestamp:%s src:%s:%d dst:%s:%d data:%s" % (pkt.timestamp,
@ -240,8 +240,7 @@ class SpyPcap():
#if msgin.needRead() < (8*8): #if msgin.needRead() < (8*8):
if msgin.needRead() < 8: if msgin.needRead() < 8:
logging.getLogger(LOGGER).debug("too small no decodeVisualProperties [{0} > {1}]".format(msgin.sizeRead() + (8*8 ), msgin.sizeData() * 8 )) logging.getLogger(LOGGER).debug("too small no decodeVisualProperties [{0} > {1}]".format(msgin.sizeRead() + (8*8 ), msgin.sizeData() * 8 ))
print("-"*80) logging.getLogger(LOGGER).debug("properties:%s" % str(properties))
print(properties)
return properties return properties
logging.getLogger(LOGGER).debug("too small no decodeVisualProperties [{0} > {1}]".format(msgin.sizeRead() + (8*8 ), msgin.sizeData() * 8 )) logging.getLogger(LOGGER).debug("too small no decodeVisualProperties [{0} > {1}]".format(msgin.sizeRead() + (8*8 ), msgin.sizeData() * 8 ))
slot = msgin.readUint8("Slot") slot = msgin.readUint8("Slot")
@ -541,7 +540,7 @@ class SpyPcap():
) #, Reference = Parent, Name = "%s_%d" % (target, 0)) ) #, Reference = Parent, Name = "%s_%d" % (target, 0))
logging.getLogger(LOGGER).info("impulse:%s" % str(impulse)) logging.getLogger(LOGGER).info("impulse:%s" % str(impulse))
if impulse: if impulse:
print("spykhanat.py:412", type(impulse)) logging.getLogger(LOGGER).debug("type impulse:%s" % str(type(impulse)))
database = None database = None
#database = impulse.readDatabases(self.client_state[dst]['world'], self.decodeDatabase) #database = impulse.readDatabases(self.client_state[dst]['world'], self.decodeDatabase)
if database: if database:
@ -563,7 +562,7 @@ class SpyPcap():
) #, Reference = Parent, Name = "%s_%d" % (target, 0)) ) #, Reference = Parent, Name = "%s_%d" % (target, 0))
logging.getLogger(LOGGER).info("impulse:%s" % str(impulse)) logging.getLogger(LOGGER).info("impulse:%s" % str(impulse))
if impulse: if impulse:
print("spykhanat.py:429", type(impulse)) logging.getLogger(LOGGER).debug("type impulse:%s" % str(type(impulse)))
impulses.append(impulse) impulses.append(impulse)
except Impulse.ImpulseNoElement: except Impulse.ImpulseNoElement:
pass pass
@ -608,7 +607,7 @@ class SpyPcap():
Name = "%s_%d" % (target, 0) Name = "%s_%d" % (target, 0)
) #, Reference = Parent, Name = "%s_%d" % (target, 0)) ) #, Reference = Parent, Name = "%s_%d" % (target, 0))
if impulse: if impulse:
print("spykhanat.py:429", type(impulse)) logging.getLogger(LOGGER).debug("type impulse:%s" % str(type(impulse)))
impulses.append(impulse) impulses.append(impulse)
except Impulse.ImpulseNoElement: except Impulse.ImpulseNoElement:
pass pass
@ -940,20 +939,20 @@ def main():
logging.basicConfig(format=FORMAT) logging.basicConfig(format=FORMAT)
logger = [] logger = []
logger.append(logging.getLogger(LOGGER)) #logger.append(logging.getLogger(LOGGER))
# logger.append(logging.getLogger(CImpulseDecoder.LOGGER)) # logger.append(logging.getLogger(CImpulseDecoder.LOGGER))
# #logger.append(logging.getLogger(DecodeImpuls.LOGGER)) # #logger.append(logging.getLogger(DecodeImpuls.LOGGER))
# #logger.append(logging.getLogger(BitStream.LOGGER)) # #logger.append(logging.getLogger(BitStream.LOGGER))
# logger.append(logging.getLogger(CStringManager.LOGGER)) # logger.append(logging.getLogger(CStringManager.LOGGER))
#logger.append(logging.getLogger(CAction.LOGGER)) #logger.append(logging.getLogger(CAction.LOGGER))
#logger.append(logging.getLogger(CActionFactory.LOGGER)) #logger.append(logging.getLogger(CActionFactory.LOGGER))
logger.append(logging.getLogger(BitStream.LOGGER)) #logger.append(logging.getLogger(BitStream.LOGGER))
#logger.append(logging.getLogger(DecodeDatabase.LOGGER)) #logger.append(logging.getLogger(DecodeDatabase.LOGGER))
#logger.append(logging.getLogger(Impulse.LOGGER)) logger.append(logging.getLogger(Impulse.LOGGER))
#logger.append(logging.getLogger(TVPNodeBase.LOGGER)) #logger.append(logging.getLogger(TVPNodeBase.LOGGER))
# CImpulseDecoder # CImpulseDecoder
# logger.append(logging.getLogger('CGenericMultiPartTemp')) # logger.append(logging.getLogger('CGenericMultiPartTemp'))
logger.append(logging.getLogger(DecodeDatabase.LOGGER)) #logger.append(logging.getLogger(DecodeDatabase.LOGGER))
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--khanat-host-service", help="filter to detect khanat host:service (FES)") parser.add_argument("--khanat-host-service", help="filter to detect khanat host:service (FES)")

View file

@ -28,13 +28,13 @@ def show_dico(dico, level=1):
try: try:
for ele in dico: for ele in dico:
if isinstance(dico[ele], dict): if isinstance(dico[ele], dict):
print("." * level, ele , ":") logging.getLogger(LOGGER).debug("%s %s %s" % ("." * level, ele , ":"))
if isinstance(dico[ele], dict): if isinstance(dico[ele], dict):
show_dico(dico[ele], level+1) show_dico(dico[ele], level+1)
else: else:
print("." * level, ele, ':', dico[ele]) logging.getLogger(LOGGER).debug("%s %s %s" % ("." * level, ele, ':', dico[ele]))
except: except:
print("empty") logging.getLogger(LOGGER).debug("empty")
def child(ele): def child(ele):
ret = {} ret = {}
@ -46,7 +46,7 @@ def child(ele):
max_i = -1 max_i = -1
for k in ele.keys(): for k in ele.keys():
ret[k] = ele.get(k) ret[k] = ele.get(k)
print(k, ele.get(k)) logging.getLogger(LOGGER).debug("%s %s" % (str(k), str(ele.get(k))))
for _child in list(ele): for _child in list(ele):
x = child(_child) x = child(_child)
if x['name'] == 'branch': if x['name'] == 'branch':
@ -81,16 +81,14 @@ def child(ele):
return ret return ret
def count_elements(head): def count_elements(head):
print("%" * 80)
#print(head) #print(head)
if 'child' in head.keys(): if 'child' in head.keys():
list_ele = [x for x in list(head['child'].keys()) if isinstance(x, int)] list_ele = [x for x in list(head['child'].keys()) if isinstance(x, int)]
else: else:
list_ele = [x for x in list(head.keys()) if isinstance(x, int)] list_ele = [x for x in list(head.keys()) if isinstance(x, int)]
print(list_ele) logging.getLogger(LOGGER).debug(str(list_ele))
last_key = max(list_ele) last_key = max(list_ele)
print(last_key ) logging.getLogger(LOGGER).debug(str(last_key ))
print("%" * 80)
try: try:
last_key = max(list_ele) last_key = max(list_ele)
if 'child' in head.keys(): if 'child' in head.keys():
@ -101,12 +99,12 @@ def count_elements(head):
return 0 return 0
def get_element(head, id): def get_element(head, id):
print("id:", id) logging.getLogger(LOGGER).debug("id: %s" % str(id))
for ele in head['child']: for ele in head['child']:
print("ele:", ele) logging.getLogger(LOGGER).debug("ele:%s" % str(ele))
print("head:", head) logging.getLogger(LOGGER).debug("head:%s" % str(head))
print("max:", head['child'][ele]['max']) logging.getLogger(LOGGER).debug("max:%s", str(head['child'][ele]['max']))
print("min:", head['child'][ele]['min']) logging.getLogger(LOGGER).debug("min:%s", str(head['child'][ele]['min']))
if id <= head['child'][ele]['max'] and id >= head['child'][ele]['min']: if id <= head['child'][ele]['max'] and id >= head['child'][ele]['min']:
return head['child'][ele] return head['child'][ele]
return None return None
@ -131,7 +129,7 @@ class LeafDatabase():
return 1 return 1
def show(self, level=1): def show(self, level=1):
print(" " * level, level, " Leaf ", self.name, ":", self.count, ":", self.type) logging.getLogger(LOGGER).debug("%s %s Leaf %s : %s : %s" % (" " * level, str(level), self.name, str(self.count), str(self.type)))
def execute(self, msgin, name=""): def execute(self, msgin, name=""):
if name: if name:
@ -273,7 +271,7 @@ class BranchDatabase():
return level return level
def show(self, level=0, pos=0, filterlevel=None): def show(self, level=0, pos=0, filterlevel=None):
print(" " * level, level, "pos:", pos, " Branch ", self.name, ":", self.count, ":", self.atom, self.getIdBits()) logging.getLogger(LOGGER).debug( "%s %s pos:%s Branch:%s : %s : %s - %s" % (" " * level, str(level), str(pos), str(self.name), str(self.count), str(self.atom), str(self.getIdBits())))
if filterlevel is not None: if filterlevel is not None:
if filterlevel <= level: if filterlevel <= level:
return return
@ -396,12 +394,9 @@ class DecodeDatabase():
def loadDatabase2(self, databaseXml): def loadDatabase2(self, databaseXml):
logging.getLogger(LOGGER).debug("loadDatabase") logging.getLogger(LOGGER).debug("loadDatabase")
print("-"*80)
base = BranchDatabase() base = BranchDatabase()
print("-"*80)
#base.loadXml(databaseXml, 'PLR') #base.loadXml(databaseXml, 'PLR')
base.loadRootXml(databaseXml, 'PLR') base.loadRootXml(databaseXml, 'PLR')
print("-"*80)
base.show(filterlevel=2) base.show(filterlevel=2)
base.show() base.show()
tmp = BitStream.BitStream() tmp = BitStream.BitStream()
@ -409,8 +404,7 @@ class DecodeDatabase():
tmp.internalSerial(0,1) tmp.internalSerial(0,1)
tmp.internalSerial(13237038,32) tmp.internalSerial(13237038,32)
base.execute_root(tmp) base.execute_root(tmp)
print(tmp.showAllData()) logging.getLogger(LOGGER).debug(tmp.showAllData())
print("-"*80)
tmp = BitStream.BitStream() tmp = BitStream.BitStream()
tmp.internalSerial(21, 5) tmp.internalSerial(21, 5)
tmp.internalSerial(8,5) tmp.internalSerial(8,5)
@ -441,7 +435,7 @@ class DecodeDatabase():
tmp.internalSerial(0,8) tmp.internalSerial(0,8)
tmp.internalSerial(1,2) tmp.internalSerial(1,2)
base.execute_root(tmp) base.execute_root(tmp)
print(tmp.showAllData()) logging.getLogger(LOGGER).debug(tmp.showAllData())
raise "Stop" raise "Stop"
self.databaseXml = databaseXml self.databaseXml = databaseXml
@ -458,15 +452,12 @@ class DecodeDatabase():
self.databasePlr['child'][id]['min'] = id self.databasePlr['child'][id]['min'] = id
self.databasePlr['child'][id]['max'] = id self.databasePlr['child'][id]['max'] = id
id += 1 id += 1
print(dir(ele)) #print(dir(ele))
nb = len(self.databasePlr) - 1 nb = len(self.databasePlr) - 1
self.databasePlr['min'] = 0 self.databasePlr['min'] = 0
self.databasePlr['max'] = nb self.databasePlr['max'] = nb
print("-" * 80)
show_dico(self.databasePlr) show_dico(self.databasePlr)
print("-" * 80) logging.getLogger(LOGGER).debug("max %d" % str(self.databasePlr['max']))
print("max", self.databasePlr['max'] )
print("-" * 80)
#raise "Decode" #raise "Decode"
def execute2(self, msgin, world): def execute2(self, msgin, world):
@ -474,20 +465,17 @@ class DecodeDatabase():
head = self.databasePlr head = self.databasePlr
listpath = [] listpath = []
print("="*80) logging.getLogger(LOGGER).debug(str(head))
print(head)
print("="*80)
while True: while True:
print("---")
logging.getLogger(LOGGER).debug("count_elements:" + str(count_elements(head))) logging.getLogger(LOGGER).debug("count_elements:" + str(count_elements(head)))
nbchild = count_elements(head) nbchild = count_elements(head)
print("count_elements(head):", nbchild) logging.getLogger(LOGGER).debug("count_elements(head):", nbchild)
if nbchild == 0: if nbchild == 0:
print("Ahhhh", "+"*80) logging.getLogger(LOGGER).debug("Ahhhh", "+"*80)
return True return True
print("nbchild:", nbchild) logging.getLogger(LOGGER).debug("nbchild:", nbchild)
nbBit = getPowerOf2.getPowerOf2_Bis(nbchild) nbBit = getPowerOf2.getPowerOf2_Bis(nbchild)
print("nbBit:", nbBit) logging.getLogger(LOGGER).debug("nbBit:", nbBit)
# res=1; # res=1;
# ret=0; # ret=0;
# print("ret:", ret, "res:", res) # print("ret:", ret, "res:", res)
@ -498,35 +486,35 @@ class DecodeDatabase():
# print("ret:", ret) # print("ret:", ret)
logging.getLogger(LOGGER).debug("nbBit:" + str(nbBit)) logging.getLogger(LOGGER).debug("nbBit:" + str(nbBit))
id = msgin.readSerial(nbBit, name='DatabaseXML', typeName='Number:'+str(nbBit), emulate=True) id = msgin.readSerial(nbBit, name='DatabaseXML', typeName='Number:'+str(nbBit), emulate=True)
print("id:", id) logging.getLogger(LOGGER).debug("id:", id)
logging.getLogger(LOGGER).debug("XML DECODE : %3d -> %s" % (nbBit, ':'.join(listpath)) ) logging.getLogger(LOGGER).debug("XML DECODE : %3d -> %s" % (nbBit, ':'.join(listpath)) )
print("Ahhhh a", "-"*80) logging.getLogger(LOGGER).debug("Ahhhh a", "-"*80)
show_dico(head) show_dico(head)
ele = get_element(head, int(id)) ele = get_element(head, int(id))
print(ele) logging.getLogger(LOGGER).debug(str(ele))
show_dico(ele) show_dico(ele)
print(msgin.showAllData()) logging.getLogger(LOGGER).debug(msgin.showAllData())
name = ele['name'] name = ele['name']
id = msgin.readSerial(nbBit, name='DatabaseXML', typeName='Number:'+str(nbBit), commentValue=name) id = msgin.readSerial(nbBit, name='DatabaseXML', typeName='Number:'+str(nbBit), commentValue=name)
listpath.append(name) listpath.append(name)
fullname = ':'.join(listpath) fullname = ':'.join(listpath)
print("fullname:", fullname) logging.getLogger(LOGGER).debug("fullname:", fullname)
logging.getLogger(LOGGER).debug(fullname) logging.getLogger(LOGGER).debug(fullname)
if 'count' in ele: if 'count' in ele:
nbBit = getPowerOf2.getPowerOf2_Bis(int(ele['count'])) nbBit = getPowerOf2.getPowerOf2_Bis(int(ele['count']))
count = msgin.readSerial(nbBit, name='DatabaseXML', typeName='count:'+str(ele['count']+':'+str(nbBit))) count = msgin.readSerial(nbBit, name='DatabaseXML', typeName='count:'+str(ele['count']+':'+str(nbBit)))
listpath.append(str(count)) listpath.append(str(count))
if 'type' in ele: if 'type' in ele:
print("Ahhhh 2", "+"*80) logging.getLogger(LOGGER).debug("Ahhhh 2", "+"*80)
print(ele['type']) logging.getLogger(LOGGER).debug(str(ele['type']))
if ele['type'] == 'I32': if ele['type'] == 'I32':
_ = msgin.readSerial(32, name='DatabaseXML', typeName=ele['type']) _ = msgin.readSerial(32, name='DatabaseXML', typeName=ele['type'])
else: else:
pass pass
print(msgin.showAllData()) logging.getLogger(LOGGER).debug(msgin.showAllData())
return True return True
head = ele head = ele
print("Ahhhh 3", "-"*80) logging.getLogger(LOGGER).debug("Ahhhh 3", "-"*80)
return False return False

View file

@ -24,9 +24,9 @@ from enum import IntEnum
def GetNameIntEnum(typeEnum, value): def GetNameIntEnum(typeEnum, value):
for key in typeEnum.__dict__: for key in typeEnum.__dict__:
try: try:
print("-"*80) #print("-"*80)
print(key, dir(typeEnum.__dict__[key])) #print(key, dir(typeEnum.__dict__[key]))
print(key, typeEnum.__dict__[key].value) #print(key, typeEnum.__dict__[key].value)
if typeEnum.__dict__[key].value == value: if typeEnum.__dict__[key].value == value:
return key return key
except: except:

View file

@ -660,8 +660,16 @@ class impulseDatabaseInitPlayer(ImpulseBase):
self.name = name.replace(':', '_') self.name = name.replace(':', '_')
self.readUint32(msgin, '%s_serverTick' % id) self.readUint32(msgin, '%s_serverTick' % id)
propertyCount = self.readUint16(msgin, '%s_propertyCount' % id) propertyCount = self.readUint16(msgin, '%s_propertyCount' % id)
# for i in range(0, propertyCount):
# _ = self.readUint32(msgin, '%s_property' % id)
for i in range(0, propertyCount): for i in range(0, propertyCount):
_ = self.readUint32(msgin, '%s_property' % id) logging.getLogger(LOGGER).debug("read i:%d" % i)
databaseXml.execute(msgin, world)
#raise "TODO"
if msgin.needRead() > 5:
logging.getLogger(LOGGER).debug(msgin.showAllData())
logging.getLogger(LOGGER).debug(msgin.showAllData())
raise "TODO"
class ImpulseConnectionDeleteChar(ImpulseBase): class ImpulseConnectionDeleteChar(ImpulseBase):
@ -669,8 +677,6 @@ class ImpulseConnectionDeleteChar(ImpulseBase):
super().__init__() super().__init__()
def read(self, name, msgin, world, databaseXml): def read(self, name, msgin, world, databaseXml):
# khanat-opennel-code/code/ryzom/client/src/net_manager.cpp void impulseDatabaseInitPlayer(NLMISC::CBitMemStream &impulse)
# khanat-opennel-code/code/ryzom/server/src/simulation_service/simulated_editor.cpp void impulseDatabaseInitPlayer(NLMISC::CBitMemStream &impulse)
id = "ConnectionDeleteChar" id = "ConnectionDeleteChar"
logging.getLogger(LOGGER).debug("read") logging.getLogger(LOGGER).debug("read")
self.name = name.replace(':', '_') self.name = name.replace(':', '_')
@ -757,7 +763,7 @@ class impulseDatabaseUpdatePlayer(ImpulseBase):
databaseXml.execute(msgin, world) databaseXml.execute(msgin, world)
#raise "TODO" #raise "TODO"
if msgin.needRead() > 5: if msgin.needRead() > 5:
print(msgin.showAllData()) logging.getLogger(LOGGER).debug(msgin.showAllData())
#raise "TODO" #raise "TODO"
#raise "TODO" #raise "TODO"