コード例 #1
0
ファイル: phd.py プロジェクト: LukeHarding/pwntools
def main():
    args = parser.parse_args()

    infile = args.file
    width  = asint(args.width)
    skip   = asint(args.skip)
    count  = asint(args.count)
    offset = asint(args.offset)

    # if `--color` has no argument it is `None`
    color = args.color or 'always'
    text.when = color

    if skip:
        if infile == sys.stdin:
            infile.read(skip)
        else:
            infile.seek(skip, os.SEEK_CUR)

    data = infile.read(count)

    hl = []
    if args.highlight:
        for hs in args.highlight:
            for h in hs.split(','):
                hl.append(asint(h))

    try:
        for line in hexdump_iter(data, width, highlight = hl, begin = offset + skip):
            print line
    except (KeyboardInterrupt, IOError):
        pass
コード例 #2
0
ファイル: phd.py プロジェクト: BrieflyX/pwntools
def main():
    args = parser.parse_args()

    infile = args.file
    width  = asint(args.width)
    skip   = asint(args.skip)
    count  = asint(args.count)
    offset = asint(args.offset)

    # if `--color` has no argument it is `None`
    color = args.color or 'always'
    text.when = color

    if skip:
        if infile == sys.stdin:
            infile.read(skip)
        else:
            infile.seek(skip, os.SEEK_CUR)

    data = infile.read(count)

    hl = []
    if args.highlight:
        for hs in args.highlight:
            for h in hs.split(','):
                hl.append(asint(h))

    try:
        for line in hexdump_iter(data, width, highlight = hl, begin = offset + skip):
            print line
    except (KeyboardInterrupt, IOError):
        pass
コード例 #3
0
ファイル: phd.py プロジェクト: zneak/pwntools
def main():
    args = parser.parse_args()

    infile = args.file
    width = asint(args.width)
    skip = asint(args.skip)
    count = asint(args.count)
    offset = asint(args.offset)

    # if `--color` has no argument it is `None`
    color = args.color or 'always'
    text.when = color

    if skip:
        if infile == sys.stdin:
            infile.read(skip)
        else:
            infile.seek(skip, os.SEEK_CUR)

    if args.highlight:

        def canon(hl):
            out = []
            i = 0
            while i < len(hl):
                c = hl[i]
                if c == '\\' and len(hl) > i + 1:
                    c2 = hl[i + 1]
                    if c2 == 'x':
                        try:
                            b = chr(int(hl[i + 2:i + 4], 16))
                        except:
                            print 'Bad escape sequence:', hl[i:]
                            sys.exit(1)
                        out.append(b)
                        i += 3
                    elif c2 in '\\?':
                        out.append(c2)
                        i += 1
                    else:
                        out.append(c)
                elif c == '?':
                    out.append(None)
                else:
                    out.append(c)
                i += 1
            return out

        highlight = map(canon, args.highlight)
    else:
        highlight = []

    try:
        for line in hexdump_iter(infile,
                                 width,
                                 highlight=highlight,
                                 begin=offset + skip):
            print line
    except (KeyboardInterrupt, IOError):
        pass
コード例 #4
0
ファイル: phd.py プロジェクト: 601040605/pwntools
def main():
    args = parser.parse_args()

    infile = args.file
    width  = asint(args.width)
    skip   = asint(args.skip)
    count  = asint(args.count)
    offset = asint(args.offset)

    # if `--color` has no argument it is `None`
    color = args.color or 'always'
    text.when = color

    if skip:
        if infile == sys.stdin:
            infile.read(skip)
        else:
            infile.seek(skip, os.SEEK_CUR)

    if args.highlight:
        def canon(hl):
            out = []
            i = 0
            while i < len(hl):
                c = hl[i]
                if c == '\\' and len(hl) > i + 1:
                    c2 = hl[i + 1]
                    if   c2 == 'x':
                        try:
                            b = chr(int(hl[i + 2: i + 4], 16))
                        except:
                            print 'Bad escape sequence:', hl[i:]
                            sys.exit(1)
                        out.append(b)
                        i += 3
                    elif c2 in '\\?':
                        out.append(c2)
                        i += 1
                    else:
                        out.append(c)
                elif c == '?':
                    out.append(None)
                else:
                    out.append(c)
                i += 1
            return out
        highlight = map(canon, args.highlight)
    else:
        highlight = []

    try:
        for line in hexdump_iter(infile, width, highlight = highlight, begin = offset + skip):
            print line
    except (KeyboardInterrupt, IOError):
        pass