Esempio n. 1
0
 def _decode_ais(self, data):
     # Decode the ais binary
     try:
         to_file(self._filter_6_bit_ascii(self._ais[0].decode(data)), sys.stdout)
     except DecodeError, ex:
         filename, line_number, column_number = self._ais[2][ex.entry]
         sys.stderr.write("%s[%i] - %s\n" % (filename, line_number, ex))
Esempio n. 2
0
#!/usr/bin/python

import os.path
import sys

sys.path.append(os.path.join(os.path.split(__file__)[0], '..', '..', '..'))

from bdec import DecodeError
from bdec.data import Data
from bdec.output.xmlout import to_file
from ole import decode, load_msword_spec

if __name__ == '__main__':

    data = Data(open(sys.argv[1], 'rb'))
    spec, common, lookup = load_msword_spec()
    try:
        to_file(decode(data, common), sys.stdout)
    except DecodeError, ex:
        try:
            (filename, line_number, column_number) = lookup[ex.entry]
        except KeyError:
            (filename, line_number, column_number) = ('unknown', 0, 0)

        print
        sys.exit("%s[%i]: %s" % (filename, line_number, str(ex)))
Esempio n. 3
0

def main():
    main_spec, specs, binary, verbose, should_remove_unused = _parse_args()
    try:
        decoder, common, lookup = load_specs([(s, None, None) for s in specs], main_spec, should_remove_unused)
    except bdec.spec.LoadError, ex:
        sys.exit(str(ex))

    data = dt.Data(binary)
    try:
        if verbose == 0:
            for item in decoder.decode(data):
                pass
        else:
            xmlout.to_file(decoder, data, sys.stdout, verbose=(verbose==2))
    except bdec.DecodeError, ex:
        try:
            (filename, line_number, column_number) = lookup[ex.entry]
        except KeyError:
            (filename, line_number, column_number) = ('unknown', 0, 0)

        # We include an extra new line, as the xml is unlikely to have finished
        # on a new line (issue164).
        print
        sys.exit("%s[%i]: %s" % (filename, line_number, str(ex)))

    try:
        # Test to see if we have data undecoded...
        remaining = data.pop(1)
Esempio n. 4
0
    try:
        decoder, common, lookup = load_specs([(s, None, None) for s in specs], main_spec, should_remove_unused)
    except bdec.spec.LoadError, ex:
        sys.exit(str(ex))

    if should_print_spec:
        print dumps(decoder, common)
        return

    data = dt.Data(binary)
    try:
        if verbose == 0:
            for item in decoder.decode(data):
                pass
        else:
            xmlout.to_file(decoder.decode(data), sys.stdout, verbose=(verbose==2))
    except bdec.DecodeError, ex:
        try:
            (filename, line_number, column_number) = lookup[ex.entry]
        except KeyError:
            (filename, line_number, column_number) = ('unknown', 0, 0)

        # We include an extra new line, as the xml is unlikely to have finished
        # on a new line (issue164).
        print
        sys.exit("%s[%i]: %s" % (filename, line_number, str(ex)))

    try:
        # Test to see if we have data undecoded...
        remaining = data.pop(1)