Exemplo n.º 1
0
def main(print_message = True):
    '''Runs the XML parser and the program.'''
    # Parse the XML file first
    global open_wireshark
    reader = None
    try:
        if OPEN in sys.argv:
            open_wireshark = True
        if CUSTOM in sys.argv:
            reader = custom_xml.parse(sys.argv[sys.argv.index(CUSTOM) + 1])
        if print_message and ((not open_wireshark) or (reader is None)):
            print "To open Wireshark or use a custom XML file, enter them as command-line arguments..."
            print "Usage: python main.py [" + CUSTOM + " custom_xml_file] [" + OPEN + "]"
            print "  \'" + CUSTOM + " custom_xml_file\' - uses the path/file of the custom XML file"
            print "  \'" + OPEN + "\' - causes Wireshark to be opened automatically"
        if reader is None:
            reader = custom_xml.parse()
    except:
        sys.stderr.write("Error while parsing XML file:" + NEW_LINE)
        traceback.print_exc(sys.exc_info()[2])
    
    # If no errors, run the program
    if reader is not None:
        try:
            program.Program(reader).run(process_extra_attribs, process_remainder)
        except:
            sys.stderr.write("Error while running program:" + NEW_LINE)
            traceback.print_exc(sys.exc_info()[2])
Exemplo n.º 2
0
'''

import sys, os, traceback, custom_xml, program, main

PACKET_FILE = main.PACKETS_DIR + os.sep + "packet"
TEMP = main.PACKETS_DIR + os.sep + "temp.txt"

try:
    # Parse the packets file
    file = open(sys.argv[1], 'r')
    packets = file.read().split()
    file.close()
    # Parse the XML file, and generate the Reader
    reader = None
    if main.CUSTOM in sys.argv:
        reader = custom_xml.parse(sys.argv[sys.argv.index(main.CUSTOM) + 1])
    else:
        reader = custom_xml.parse()
    # Make the packet output dir if it doesn't exist
    if not os.path.isdir(main.PACKETS_DIR):
        os.makedirs(main.PACKETS_DIR)
    # Check for pre-existing packet files
    starting_offset = 0
    while os.path.isfile(PACKET_FILE + str(starting_offset) + ".txt"):
        starting_offset += 1
    # Start processing packets
    print "\nWriting " + str(len(packets)) + " files, starting with \'" + PACKET_FILE + str(starting_offset) + ".txt\'.\n"
    for i, packet in enumerate(packets):
        # set up input
        input_packet_file = open(TEMP, 'w')
        input_packet_file.write(packet)