tools: move all tools to the Python3 shebang and add berdecode an option for printing hexstream
This commit is contained in:
parent
9f79afe50c
commit
e11b6bd541
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# -*- coding: UTF-8 -*-
|
||||
#/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# -*- coding: UTF-8 -*-
|
||||
#/**
|
||||
|
@ -40,17 +40,20 @@ from pycrate_asn1rt.codecs import ASN1CodecBER
|
|||
|
||||
|
||||
pprint.stdprinter = pprint.PrettyPrinter
|
||||
#
|
||||
|
||||
class MyPrettyPrinter(pprint.stdprinter):
|
||||
RA = range(128)
|
||||
|
||||
def _format(self, obj, *args, **kwargs):
|
||||
if isinstance(obj, str_types + bytes_types) and \
|
||||
not all([c in self.RA for c in obj]):
|
||||
if isinstance(obj, bytes_types):
|
||||
obj = hexlify(obj)
|
||||
elif isinstance(obj, list):
|
||||
# this is required for the Python3 pretty-printer which works line-by-line
|
||||
# and not object-by-object
|
||||
for i, objsub in enumerate(obj[:]):
|
||||
if isinstance(objsub, bytes_types):
|
||||
del obj[i]
|
||||
obj.insert(i, hexlify(objsub))
|
||||
return pprint.stdprinter._format(self, obj, *args, **kwargs)
|
||||
#
|
||||
# enabling this will print hex stream for what looks like non-ascii str / bytes
|
||||
#pprint.PrettyPrinter=MyPrettyPrinter
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -62,6 +65,8 @@ def main():
|
|||
help='file containing the binary encoded objects')
|
||||
parser.add_argument('-s', dest='stream', type=str,
|
||||
help='hexadecimal string encoding the objects')
|
||||
parser.add_argument('-x', dest='hex', action='store_true',
|
||||
help='print non-ascii strings in hexadecimal form')
|
||||
#
|
||||
args = parser.parse_args()
|
||||
if args.input:
|
||||
|
@ -81,6 +86,8 @@ def main():
|
|||
else:
|
||||
print('%s, args error: missing input encoded object' % sys.argv[0])
|
||||
return 0
|
||||
if args.hex:
|
||||
pprint.PrettyPrinter=MyPrettyPrinter
|
||||
#
|
||||
char = Charpy(buf)
|
||||
cnt = 0
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/python3
|
||||
# −*− coding: UTF−8 −*−
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# -*- coding: UTF-8 -*-
|
||||
#/**
|
||||
# * Software Name : pycrate
|
||||
# * Version : 0.4.0
|
||||
# * Version : 0.4
|
||||
# *
|
||||
# * Copyright © 2018. Benoit Michau. P1sec
|
||||
# * Copyright 2018. Benoit Michau. P1sec
|
||||
# *
|
||||
# * This program is free software: you can redistribute it and/or modify
|
||||
# * it under the terms of the GNU General Public License version 2 as published
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# -*- coding: UTF-8 -*-
|
||||
#/**
|
||||
|
|
Loading…
Reference in New Issue