#!/usr/bin/python # In the name of God # This is a public domain work # By Mohammad Ebrahim Mohammadi Panah < mebrahim at gmail dot com > """ Paltalk Dump Formatter Formats and prints a file containing data of a Paltalk session, usually dumped by Wirashark """ import sys import struct import string DEFAULT_LINE_LENGTH = 20 DEFAULT_GROUP_LENGTH = 4 def format_line(line, expected_line_length = DEFAULT_LINE_LENGTH, group_length = DEFAULT_GROUP_LENGTH): l = len(line) out = "" for i in range(l): out += '%.2x ' % ord(line[i]) if (i + 1) % group_length == 0: out += '| ' remaining = expected_line_length - l for i in range(l, expected_line_length): out += ' ' if (i + 1) % group_length == 0: out += '| ' # Replace all non-printable chars with '?' table = list('?' * 256) for c in string.printable: table[ord(c)] = c for c in "\n\r\t\v": # Except some trouble makers! table[ord(c)] = '?' table = ''.join(table) print "%s\t%s" % (out, line.translate(table)) def format_message(file_, length, line_length = DEFAULT_LINE_LENGTH): # Process the length bytes of file, in pieces of length line_length while length > 0: line = file_.read(min(length, line_length)) if not line: raise Exception("File is truncated") format_line(line) length -= len(line) print '-' * line_length def format(filename): try: f = open(filename, 'rb') try: while True: type_buf = f.read(4) length_buf = f.read(2) if len(type_buf) != 4 or len(length_buf) != 2: break message_type = struct.unpack('>L', type_buf)[0] message_length = struct.unpack('>H', length_buf)[0] print 'Type:\t0x%x' % message_type print 'Length:\t%d' % message_length format_message(f, message_length) # except Exception, e: # print 'Error: %s' % e finally: f.close() except IOError: print 'Error: Failed to open file %s' % filename if __name__ == '__main__': if len(sys.argv) <= 1: print 'Usage: %s file1 [file2] ...' % sys.argv[0] sys.exit(1) for filename in sys.argv[1:]: format(filename) sys.exit(0)