def encode(self, stream: MemoryStream): if not self.frame_list: stream.write_ubyte(0) return stream.write_ubyte(len(self.frame_list)) for n in range(len(self.frame_list)): frame = self.frame_list[n] frame.encode(stream)
def decode(self, stream: MemoryStream): self.size = stream.position self.frame_index = stream.read_sint32() action_count = stream.read_ubyte() print('[frame] index:%d action_count:%d' % (self.frame_index, action_count)) self.action_list = [] for _ in range(action_count): action = ActionObject(debug=self.debug) action.decode(stream) self.action_list.append(action) self.size = stream.position - self.size
def decode(self, stream: MemoryStream): frame_count = stream.read_ubyte() self.frame_list = [] for n in range(frame_count): frame = FrameObject(debug=self.debug) frame.decode(stream) self.frame_list.append(frame)
def decode(self, stream: MemoryStream): self.length = stream.read_ubyte() self.source_player = stream.read_ubyte() self.type = stream.read_ubyte() payload = self.length - self.header if payload > 0: self.data = stream.read(payload) assert self.data and len(self.data) == payload __share_stream__.position = 0 if self.data: __share_stream__.write(self.data) __share_stream__.position = 0 self.message = message.get_message(self.type) self.message.decode(__share_stream__) self.print(self.type, message.MessageType(self.type)) if self.id != 0: print('[Action] {id=%d,size=%d} %s' % (self.id, self.length, self.message)) else: print(' [Action] uin:%d %s' % (self.source_player, self.message))
def encode(self, stream: MemoryStream): stream.write_sint32(self.frame_index) if not self.action_list: stream.write_ubyte(0) return action_count = len(self.action_list) stream.write_ubyte(action_count) for n in range(action_count): action = self.action_list[n] action.encode(stream)
def encode(self, stream: MemoryStream): if not self.content: stream.write_uint16(0) return stream.write_uint16(len(self.content)) stream.write(self.content)
def encode(self, stream: MemoryStream): stream.write_ubyte(self.source_player) stream.write_ubyte(self.type) self.message.encode(stream)
#!/usr/bin/env python #encoding:utf-8 import message, binascii from wireshark import MemoryStream, Debugger from message import ActionMessage ACTION_HEADER_SIZE = 3 __share_stream__ = MemoryStream() class ActionObject(Debugger): def __init__(self, debug: bool): super(ActionObject, self).__init__(debug) self.length = 0 self.header = 3 self.source_player = 0 self.data: bytes = None self.type: int = 0 self.message: ActionMessage = None self.id: int = 0 def decode(self, stream: MemoryStream): self.length = stream.read_ubyte() self.source_player = stream.read_ubyte() self.type = stream.read_ubyte() payload = self.length - self.header if payload > 0: self.data = stream.read(payload) assert self.data and len(self.data) == payload