Ejemplo n.º 1
0
def parse_file(filename):
    global options

    log("\n#### FILE '%s' ####" % filename)

    log("   %-47s" % "* reading XML document:", False)
    f = open(filename, 'r')
    data = f.read()
    f.close()
    log("done!")

    log("   %-47s" % "* building DOM tree:", False)
    try:
        try:
            root = etree.fromstring(data)
        except etree.XMLSyntaxError, e:
            # try to fix invalid document, if required
            if 'f' not in options:
                raise e

            data = fixdocument(data)
            root = etree.fromstring(data)
    except etree.XMLSyntaxError, e:
        print colorize("\n! %s is not a valid XML document" % filename)
        sys.exit(1)
Ejemplo n.º 2
0
def parse_file(filename):
    global options

    log("\n#### FILE '%s' ####" % filename)

    log("   %-47s" % "* reading XML document:", False)
    f = open(filename, 'r')
    data = f.read()
    f.close()
    log("done!")        

    log("   %-47s" % "* building DOM tree:", False)
    try:
        try:
            root = etree.fromstring(data)
        except etree.XMLSyntaxError, e:
            # try to fix invalid document, if required
            if 'f' not in options:
                raise e

            data = fixdocument(data)
            root = etree.fromstring(data)
    except etree.XMLSyntaxError, e:
        print colorize("\n! %s is not a valid XML document" % filename)
        sys.exit(1)
Ejemplo n.º 3
0
            # try to fix invalid document, if required
            if 'f' not in options:
                raise e

            data = fixdocument(data)
            root = etree.fromstring(data)
    except etree.XMLSyntaxError, e:
        print colorize("\n! %s is not a valid XML document" % filename)
        sys.exit(1)
    log("done!")

    log("   %-47s" % "* validating XML document:", False)
    try:
        schema.assertValid(root)
    except etree.DocumentInvalid, e:
        print colorize("\n! %s does not validate" % filename)
        print colorize(e, COLOR_YELLOW)
        sys.exit(1)
    log("done!")

    log("   %-47s" % "* building objects:", False)
    trace = build_trace(root, filename)
    log("done! (%d system calls)" % len(trace))

    log("   %-47s" % "* cleaning up:", False)
    del root
    log("done| (name: '%s'; pid: %d)" % (trace.getFilename(), trace.getPID()))

    log("   %-47s" % "* normalizing system calls trace:", False)
    trace.normalize()
    log("done!")
Ejemplo n.º 4
0
            # try to fix invalid document, if required
            if 'f' not in options:
                raise e

            data = fixdocument(data)
            root = etree.fromstring(data)
    except etree.XMLSyntaxError, e:
        print colorize("\n! %s is not a valid XML document" % filename)
        sys.exit(1)
    log("done!")

    log("   %-47s" % "* validating XML document:", False)
    try:
        schema.assertValid(root)
    except etree.DocumentInvalid, e:
        print colorize("\n! %s does not validate" % filename)
        print colorize(e, COLOR_YELLOW)
        sys.exit(1)
    log("done!")

    log("   %-47s" % "* building objects:", False)
    trace = build_trace(root, filename)
    log("done! (%d system calls)" % len(trace))

    log("   %-47s" % "* cleaning up:", False)
    del root 
    log("done| (name: '%s'; pid: %d)" % (trace.getFilename(), trace.getPID()))

    log("   %-47s" % "* normalizing system calls trace:", False)
    trace.normalize()
    log("done!")