From a58e76e63219bff19d66f07cd09bbf116c349180 Mon Sep 17 00:00:00 2001 From: Drew Bonasera Date: Wed, 2 Nov 2016 15:05:25 -0400 Subject: [PATCH 1/2] Change exception.ValueError to ValueError --- pefile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pefile.py b/pefile.py index 18c2a31..4859418 100644 --- a/pefile.py +++ b/pefile.py @@ -932,7 +932,7 @@ def dump(self, indentation=0): if key == 'TimeDateStamp' or key == 'dwTimeStamp': try: val_str += ' [%s UTC]' % time.asctime(time.gmtime(val)) - except exceptions.ValueError as e: + except ValueError as e: val_str += ' [INVALID TIME]' else: val_str = bytearray(val) @@ -963,7 +963,7 @@ def dump_dict(self): if key == 'TimeDateStamp' or key == 'dwTimeStamp': try: val = '0x%-8X [%s UTC]' % (val, time.asctime(time.gmtime(val))) - except exceptions.ValueError as e: + except ValueError as e: val = '0x%-8X [INVALID TIME]' % val else: val = b([b for b in val if b != 0]) From a93f560f0602906ade5bcbc17ba0fc2a21d15fa9 Mon Sep 17 00:00:00 2001 From: Drew Bonasera Date: Wed, 2 Nov 2016 15:06:14 -0400 Subject: [PATCH 2/2] Add convert_to_printable() to fix unresolved reference on line 4932 (old line 4910) --- pefile.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pefile.py b/pefile.py index 4859418..df9ec34 100644 --- a/pefile.py +++ b/pefile.py @@ -566,6 +566,28 @@ def get_sublang_name_for_lang( lang_value, sublang_value ): return SUBLANG.get(sublang_value, ['*unknown*'])[0] +def convert_to_printable(s): + """Convert string to printable string. + @param s: string. + @return: sanitized string. + """ + printable = True + for c in s: + if c not in string.printable: + printable = False + break + if printable: + return s + else: + new_string = '' + for c in s: + if c in string.printable: + new_string += c + else: + new_string += "\\x%02x" % ord(c) + return new_string + + # Ange Albertini's code to process resources' strings # def parse_strings(data, counter, l):