Commit d604e72da9a9424c832f7d87281f7280a6439081
1 parent
9e355a9d
if catching exceptions and logging stuff, also print info about exception
Showing
1 changed file
with
13 additions
and
8 deletions
oletools/olevba.py
| @@ -894,7 +894,8 @@ def mso_file_extract(data): | @@ -894,7 +894,8 @@ def mso_file_extract(data): | ||
| 894 | extracted_data = zlib.decompress(data[start:]) | 894 | extracted_data = zlib.decompress(data[start:]) |
| 895 | return extracted_data | 895 | return extracted_data |
| 896 | except zlib.error as exc: | 896 | except zlib.error as exc: |
| 897 | - log.exception('zlib decompression failed') | 897 | + log.exception('zlib decompression failed for offset %s (%s)' |
| 898 | + % (start, exc)) | ||
| 898 | # None of the guessed offsets worked, let's try brute-forcing by looking | 899 | # None of the guessed offsets worked, let's try brute-forcing by looking |
| 899 | # for potential zlib-compressed blocks starting with 0x78: | 900 | # for potential zlib-compressed blocks starting with 0x78: |
| 900 | log.debug('Looking for potential zlib-compressed blocks in MSO file') | 901 | log.debug('Looking for potential zlib-compressed blocks in MSO file') |
| @@ -905,7 +906,7 @@ def mso_file_extract(data): | @@ -905,7 +906,7 @@ def mso_file_extract(data): | ||
| 905 | extracted_data = zlib.decompress(data[start:]) | 906 | extracted_data = zlib.decompress(data[start:]) |
| 906 | return extracted_data | 907 | return extracted_data |
| 907 | except zlib.error as exc: | 908 | except zlib.error as exc: |
| 908 | - log.exception('zlib decompression failed') | 909 | + log.exception('zlib decompression failed (%s)' % exc) |
| 909 | raise MsoExtractionError('Unable to decompress data from a MSO/ActiveMime file') | 910 | raise MsoExtractionError('Unable to decompress data from a MSO/ActiveMime file') |
| 910 | 911 | ||
| 911 | 912 | ||
| @@ -1633,6 +1634,7 @@ def detect_base64_strings(vba_code): | @@ -1633,6 +1634,7 @@ def detect_base64_strings(vba_code): | ||
| 1633 | results.append((value, decoded)) | 1634 | results.append((value, decoded)) |
| 1634 | found.add(value) | 1635 | found.add(value) |
| 1635 | except (TypeError, ValueError) as exc: | 1636 | except (TypeError, ValueError) as exc: |
| 1637 | + log.debug('Failed to base64-decode (%s)' % exc) | ||
| 1636 | # if an exception occurs, it is likely not a base64-encoded string | 1638 | # if an exception occurs, it is likely not a base64-encoded string |
| 1637 | pass | 1639 | pass |
| 1638 | return results | 1640 | return results |
| @@ -1659,7 +1661,8 @@ def detect_dridex_strings(vba_code): | @@ -1659,7 +1661,8 @@ def detect_dridex_strings(vba_code): | ||
| 1659 | decoded = DridexUrlDecode(value) | 1661 | decoded = DridexUrlDecode(value) |
| 1660 | results.append((value, decoded)) | 1662 | results.append((value, decoded)) |
| 1661 | found.add(value) | 1663 | found.add(value) |
| 1662 | - except Exception: | 1664 | + except Exception as exc: |
| 1665 | + log.debug('Failed to Dridex-decode (%s)' % exc) | ||
| 1663 | # if an exception occurs, it is likely not a dridex-encoded string | 1666 | # if an exception occurs, it is likely not a dridex-encoded string |
| 1664 | pass | 1667 | pass |
| 1665 | return results | 1668 | return results |
| @@ -2057,15 +2060,16 @@ class VBA_Parser(object): | @@ -2057,15 +2060,16 @@ class VBA_Parser(object): | ||
| 2057 | ole_data = z.open(subfile).read() | 2060 | ole_data = z.open(subfile).read() |
| 2058 | try: | 2061 | try: |
| 2059 | self.ole_subfiles.append(VBA_Parser(filename=subfile, data=ole_data)) | 2062 | self.ole_subfiles.append(VBA_Parser(filename=subfile, data=ole_data)) |
| 2060 | - except Exception: | ||
| 2061 | - log.debug('%s is not a valid OLE file' % subfile) | 2063 | + except FileOpenError as exc: |
| 2064 | + log.error('%s is not a valid OLE file (%s)' % (subfile, exc)) | ||
| 2062 | continue | 2065 | continue |
| 2063 | z.close() | 2066 | z.close() |
| 2064 | # set type only if parsing succeeds | 2067 | # set type only if parsing succeeds |
| 2065 | self.type = TYPE_OpenXML | 2068 | self.type = TYPE_OpenXML |
| 2066 | except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile, IOError) as exc: | 2069 | except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile, IOError) as exc: |
| 2067 | # TODO: handle parsing exceptions | 2070 | # TODO: handle parsing exceptions |
| 2068 | - log.exception('Failed Zip/OpenXML parsing for file %r' % self.filename) | 2071 | + log.exception('Failed Zip/OpenXML parsing for file %r (%s)' |
| 2072 | + % (self.filename, exc)) | ||
| 2069 | pass | 2073 | pass |
| 2070 | 2074 | ||
| 2071 | def open_word2003xml(self, data): | 2075 | def open_word2003xml(self, data): |
| @@ -2099,9 +2103,10 @@ class VBA_Parser(object): | @@ -2099,9 +2103,10 @@ class VBA_Parser(object): | ||
| 2099 | log.error('%s is not a valid MSO file' % fname) | 2103 | log.error('%s is not a valid MSO file' % fname) |
| 2100 | # set type only if parsing succeeds | 2104 | # set type only if parsing succeeds |
| 2101 | self.type = TYPE_Word2003_XML | 2105 | self.type = TYPE_Word2003_XML |
| 2102 | - except Exception: | 2106 | + except Exception as exc: |
| 2103 | # TODO: differentiate exceptions for each parsing stage | 2107 | # TODO: differentiate exceptions for each parsing stage |
| 2104 | - log.exception('Failed XML parsing for file %r' % self.filename) | 2108 | + # (but ET is different libs, no good exception description in API) |
| 2109 | + log.exception('Failed XML parsing for file %r (%s)' % (self.filename, exc)) | ||
| 2105 | pass | 2110 | pass |
| 2106 | 2111 | ||
| 2107 | def open_mht(self, data): | 2112 | def open_mht(self, data): |