2012-12-17 14:40:49 +01:00
|
|
|
import string
|
|
|
|
import copy
|
2012-12-26 16:07:34 +01:00
|
|
|
import base64
|
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
|
|
|
|
class PacketDumper:
|
|
|
|
options = None
|
|
|
|
writeFile = None
|
|
|
|
|
|
|
|
def onEnable(self, parser):
|
2012-12-25 21:38:02 +01:00
|
|
|
parser.add_option("-d", "--dump-packets",
|
2012-12-26 16:07:34 +01:00
|
|
|
action="store_true", dest="dumpPackets", default=False,
|
|
|
|
help="run with this argument to dump packets")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
parser.add_option("-o", "--out-file", dest="filename", default="dump.txt",
|
2012-12-26 16:07:34 +01:00
|
|
|
help="file to dump packets to")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
def onDisable(self):
|
2012-12-26 16:07:34 +01:00
|
|
|
if self.writeFile is not None:
|
2012-12-17 14:40:49 +01:00
|
|
|
self.writeFile.close()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
def optionsParsed(self, parsedOptions):
|
|
|
|
self.options = parsedOptions
|
2012-12-26 16:07:34 +01:00
|
|
|
if self.options.dumpPackets:
|
2012-12-17 14:40:49 +01:00
|
|
|
self.writeFile = open(self.options.filename, 'w')
|
|
|
|
|
|
|
|
def packetReceive(self, packetID, receivedPacket):
|
|
|
|
packet = copy.deepcopy(receivedPacket)
|
2012-12-26 16:07:34 +01:00
|
|
|
if self.writeFile is not None:
|
|
|
|
if packetID == "\x33" or packetID == "\x38":
|
|
|
|
packet['Data'] = base64.b64encode(packet['RawData'])
|
|
|
|
del packet['RawData']
|
|
|
|
if packetID == "\x03":
|
2012-12-17 14:40:49 +01:00
|
|
|
packet['Message'] = filter(lambda x: x in string.printable, packet['Message'])
|
|
|
|
self.writeFile.write(hex(ord(packetID)) + " : " + str(packet) + '\n')
|