diff --git a/oletools/common/io_encoding.py b/oletools/common/io_encoding.py index b32d82d..0bf4db2 100644 --- a/oletools/common/io_encoding.py +++ b/oletools/common/io_encoding.py @@ -58,7 +58,7 @@ PY3 = sys.version_info.major >= 3 if PY3: from builtins import open as builtin_open else: - from __builtin__ import open as builtin_open + from __builtin__ import open as builtin_open # pylint: disable=import-error # -- CONSTANTS ---------------------------------------------------------------- #: encoding to use for redirection if no good encoding can be found diff --git a/oletools/mraptor_milter.py b/oletools/mraptor_milter.py index eaf01f6..36d38e1 100644 --- a/oletools/mraptor_milter.py +++ b/oletools/mraptor_milter.py @@ -69,7 +69,7 @@ __version__ = '0.51' # --- IMPORTS ---------------------------------------------------------------- -import Milter +import Milter # not part of requirements, therefore: # pylint: disable=import-error import io import time import email @@ -78,7 +78,7 @@ import os import logging import logging.handlers import datetime -import StringIO +import StringIO # not part of requirements, therefore: # pylint: disable=import-error from socket import AF_INET6 @@ -96,7 +96,7 @@ if not _parent_dir in sys.path: from oletools import olevba, mraptor -from Milter.utils import parse_addr +from Milter.utils import parse_addr # not part of requirements, therefore: # pylint: disable=import-error from zipfile import is_zipfile @@ -389,7 +389,7 @@ if __name__ == "__main__": # Using daemonize: # See http://daemonize.readthedocs.io/en/latest/ - from daemonize import Daemonize + from daemonize import Daemonize # not part of requirements, therefore: # pylint: disable=import-error daemon = Daemonize(app="mraptor_milter", pid=PIDFILE, action=main) daemon.start() diff --git a/oletools/msodde.py b/oletools/msodde.py index 303d974..49fa42c 100644 --- a/oletools/msodde.py +++ b/oletools/msodde.py @@ -149,69 +149,69 @@ LOCATIONS = ('word/document.xml', 'word/endnotes.xml', 'word/footnotes.xml', # switches_with_args, switches_without_args, format_switches) FIELD_BLACKLIST = ( # date and time: - ('CREATEDATE', 0, 0, '', 'hs', 'datetime'), # pylint: disable=bad-whitespace - ('DATE', 0, 0, '', 'hls', 'datetime'), # pylint: disable=bad-whitespace - ('EDITTIME', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('PRINTDATE', 0, 0, '', 'hs', 'datetime'), # pylint: disable=bad-whitespace - ('SAVEDATE', 0, 0, '', 'hs', 'datetime'), # pylint: disable=bad-whitespace - ('TIME', 0, 0, '', '', 'datetime'), # pylint: disable=bad-whitespace + ('CREATEDATE', 0, 0, '', 'hs', 'datetime'), + ('DATE', 0, 0, '', 'hls', 'datetime'), + ('EDITTIME', 0, 0, '', '', 'numeric'), + ('PRINTDATE', 0, 0, '', 'hs', 'datetime'), + ('SAVEDATE', 0, 0, '', 'hs', 'datetime'), + ('TIME', 0, 0, '', '', 'datetime'), # exclude document automation (we hate the "auto" in "automation") # (COMPARE, DOCVARIABLE, GOTOBUTTON, IF, MACROBUTTON, PRINT) # document information - ('AUTHOR', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('COMMENTS', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('DOCPROPERTY', 1, 0, '', '', 'string/numeric/datetime'), # pylint: disable=bad-whitespace - ('FILENAME', 0, 0, '', 'p', 'string'), # pylint: disable=bad-whitespace - ('FILESIZE', 0, 0, '', 'km', 'numeric'), # pylint: disable=bad-whitespace - ('KEYWORDS', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('LASTSAVEDBY', 0, 0, '', '', 'string'), # pylint: disable=bad-whitespace - ('NUMCHARS', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('NUMPAGES', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('NUMWORDS', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('SUBJECT', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('TEMPLATE', 0, 0, '', 'p', 'string'), # pylint: disable=bad-whitespace - ('TITLE', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace + ('AUTHOR', 0, 1, '', '', 'string'), + ('COMMENTS', 0, 1, '', '', 'string'), + ('DOCPROPERTY', 1, 0, '', '', 'string/numeric/datetime'), + ('FILENAME', 0, 0, '', 'p', 'string'), + ('FILESIZE', 0, 0, '', 'km', 'numeric'), + ('KEYWORDS', 0, 1, '', '', 'string'), + ('LASTSAVEDBY', 0, 0, '', '', 'string'), + ('NUMCHARS', 0, 0, '', '', 'numeric'), + ('NUMPAGES', 0, 0, '', '', 'numeric'), + ('NUMWORDS', 0, 0, '', '', 'numeric'), + ('SUBJECT', 0, 1, '', '', 'string'), + ('TEMPLATE', 0, 0, '', 'p', 'string'), + ('TITLE', 0, 1, '', '', 'string'), # equations and formulas # exlude '=' formulae because they have different syntax (and can be bad) - ('ADVANCE', 0, 0, 'dlruxy', '', ''), # pylint: disable=bad-whitespace - ('SYMBOL', 1, 0, 'fs', 'ahju', ''), # pylint: disable=bad-whitespace + ('ADVANCE', 0, 0, 'dlruxy', '', ''), + ('SYMBOL', 1, 0, 'fs', 'ahju', ''), # form fields - ('FORMCHECKBOX', 0, 0, '', '', ''), # pylint: disable=bad-whitespace - ('FORMDROPDOWN', 0, 0, '', '', ''), # pylint: disable=bad-whitespace - ('FORMTEXT', 0, 0, '', '', ''), # pylint: disable=bad-whitespace + ('FORMCHECKBOX', 0, 0, '', '', ''), + ('FORMDROPDOWN', 0, 0, '', '', ''), + ('FORMTEXT', 0, 0, '', '', ''), # index and tables - ('INDEX', 0, 0, 'bcdefghklpsz', 'ry', ''), # pylint: disable=bad-whitespace + ('INDEX', 0, 0, 'bcdefghklpsz', 'ry', ''), # exlude RD since that imports data from other files - ('TA', 0, 0, 'clrs', 'bi', ''), # pylint: disable=bad-whitespace - ('TC', 1, 0, 'fl', 'n', ''), # pylint: disable=bad-whitespace - ('TOA', 0, 0, 'bcdegls', 'fhp', ''), # pylint: disable=bad-whitespace - ('TOC', 0, 0, 'abcdflnopst', 'huwxz', ''), # pylint: disable=bad-whitespace - ('XE', 1, 0, 'frty', 'bi', ''), # pylint: disable=bad-whitespace + ('TA', 0, 0, 'clrs', 'bi', ''), + ('TC', 1, 0, 'fl', 'n', ''), + ('TOA', 0, 0, 'bcdegls', 'fhp', ''), + ('TOC', 0, 0, 'abcdflnopst', 'huwxz', ''), + ('XE', 1, 0, 'frty', 'bi', ''), # links and references # exclude AUTOTEXT and AUTOTEXTLIST since we do not like stuff with 'AUTO' - ('BIBLIOGRAPHY', 0, 0, 'lfm', '', ''), # pylint: disable=bad-whitespace - ('CITATION', 1, 0, 'lfspvm', 'nty', ''), # pylint: disable=bad-whitespace + ('BIBLIOGRAPHY', 0, 0, 'lfm', '', ''), + ('CITATION', 1, 0, 'lfspvm', 'nty', ''), # exclude HYPERLINK since we are allergic to URLs # exclude INCLUDEPICTURE and INCLUDETEXT (other file or maybe even URL?) # exclude LINK and REF (could reference other files) - ('NOTEREF', 1, 0, '', 'fhp', ''), # pylint: disable=bad-whitespace - ('PAGEREF', 1, 0, '', 'hp', ''), # pylint: disable=bad-whitespace - ('QUOTE', 1, 0, '', '', 'datetime'), # pylint: disable=bad-whitespace - ('STYLEREF', 1, 0, '', 'lnprtw', ''), # pylint: disable=bad-whitespace + ('NOTEREF', 1, 0, '', 'fhp', ''), + ('PAGEREF', 1, 0, '', 'hp', ''), + ('QUOTE', 1, 0, '', '', 'datetime'), + ('STYLEREF', 1, 0, '', 'lnprtw', ''), # exclude all Mail Merge commands since they import data from other files # (ADDRESSBLOCK, ASK, COMPARE, DATABASE, FILLIN, GREETINGLINE, IF, # MERGEFIELD, MERGEREC, MERGESEQ, NEXT, NEXTIF, SET, SKIPIF) # Numbering - ('LISTNUM', 0, 1, 'ls', '', ''), # pylint: disable=bad-whitespace - ('PAGE', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('REVNUM', 0, 0, '', '', ''), # pylint: disable=bad-whitespace - ('SECTION', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('SECTIONPAGES', 0, 0, '', '', 'numeric'), # pylint: disable=bad-whitespace - ('SEQ', 1, 1, 'rs', 'chn', 'numeric'), # pylint: disable=bad-whitespace - # user information # pylint: disable=bad-whitespace - ('USERADDRESS', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('USERINITIALS', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace - ('USERNAME', 0, 1, '', '', 'string'), # pylint: disable=bad-whitespace + ('LISTNUM', 0, 1, 'ls', '', ''), + ('PAGE', 0, 0, '', '', 'numeric'), + ('REVNUM', 0, 0, '', '', ''), + ('SECTION', 0, 0, '', '', 'numeric'), + ('SECTIONPAGES', 0, 0, '', '', 'numeric'), + ('SEQ', 1, 1, 'rs', 'chn', 'numeric'), + # user information + ('USERADDRESS', 0, 1, '', '', 'string'), + ('USERINITIALS', 0, 1, '', '', 'string'), + ('USERNAME', 0, 1, '', '', 'string'), ) FIELD_DDE_REGEX = re.compile(r'^\s*dde(auto)?\s+', re.I) diff --git a/oletools/oleobj.py b/oletools/oleobj.py index eef96b6..f31010b 100644 --- a/oletools/oleobj.py +++ b/oletools/oleobj.py @@ -180,7 +180,7 @@ if sys.version_info[0] <= 2: NULL_CHAR = '\x00' else: # Python 3.x - NULL_CHAR = 0 # pylint: disable=redefined-variable-type + NULL_CHAR = 0 xrange = range # pylint: disable=redefined-builtin, invalid-name OOXML_RELATIONSHIP_TAG = '{http://schemas.openxmlformats.org/package/2006/relationships}Relationship' diff --git a/oletools/olevba.py b/oletools/olevba.py index 52ffd51..00f1eb9 100644 --- a/oletools/olevba.py +++ b/oletools/olevba.py @@ -3087,7 +3087,7 @@ class VBA_Parser(object): log.info('Check whether OLE file is PPT') try: ppt = ppt_parser.PptParser(self.ole_file, fast_fail=True) - for vba_data in ppt.iter_vba_data(): + for vba_data in ppt.iter_vba_data(): # pylint: disable=no-value-for-parameter self.append_subfile(None, vba_data, container='PptParser') log.info('File is PPT') self.ole_file.close() # just in case diff --git a/oletools/ooxml.py b/oletools/ooxml.py index 57fd16f..9522b98 100644 --- a/oletools/ooxml.py +++ b/oletools/ooxml.py @@ -160,7 +160,7 @@ def debug_str(elem): def isstr(some_var): """ version-independent test for isinstance(some_var, (str, unicode)) """ if sys.version_info.major == 2: - return isinstance(some_var, basestring) # true for str and unicode + return isinstance(some_var, basestring) # true for str and unicode # pylint: disable=undefined-variable return isinstance(some_var, str) # there is no unicode diff --git a/oletools/ppt_parser.py b/oletools/ppt_parser.py index 93b75a4..0ba7974 100644 --- a/oletools/ppt_parser.py +++ b/oletools/ppt_parser.py @@ -1377,7 +1377,7 @@ class PptParser(object): # first identified in step 3 of Part 1, that is, the UserEditAtom # record closest to the end of the stream. if self.persist_object_directory is None: - self.parse_persist_object_directory() + self.parse_persist_object_directory() # pylint: disable=no-value-for-parameter # Step 2: Lookup the value of the docPersistIdRef field in the persist # object directory constructed in step 8 of Part 1 to find the stream @@ -1462,7 +1462,7 @@ class PptParser(object): rec_len=VBAInfoAtom.RECORD_LENGTH) # try parse - for idx in self.search_pattern(pattern): + for idx in self.search_pattern(pattern): # pylint: disable=no-value-for-parameter # assume that in stream at idx there is a VBAInfoContainer stream.seek(idx) log.debug('extracting at idx {0}'.format(idx)) @@ -1515,7 +1515,7 @@ class PptParser(object): pattern = obj_type.generate_pattern() # try parse - for idx in self.search_pattern(pattern): + for idx in self.search_pattern(pattern): # pylint: disable=no-value-for-parameter # assume a ExternalObjectStorage in stream at idx stream.seek(idx) log.debug('extracting at idx {0}'.format(idx)) @@ -1589,7 +1589,7 @@ class PptParser(object): n_infos = 0 n_macros = 0 - for info in self.search_vba_info(): + for info in self.search_vba_info(stream): n_infos += 1 if info.vba_info_atom.f_has_macros > 0: n_macros += 1 @@ -1597,13 +1597,13 @@ class PptParser(object): # --> no vba-info, so all storages probably ActiveX or other OLE n_storages = 0 n_compressed = 0 - for storage in self.search_vba_storage(): + for storage in self.search_vba_storage(): # pylint: disable=no-value-for-parameter n_storages += 1 if storage.is_compressed: n_compressed += 1 - yield self.decompress_vba_storage(storage) + yield self.decompress_vba_storage(storage) # pylint: disable=no-value-for-parameter else: - yield self.read_vba_storage_data(storage) + yield self.read_vba_storage_data(storage) # pylint: disable=no-value-for-parameter log.info('found {0} infos ({1} with macros) and {2} storages ' '({3} compressed)' diff --git a/oletools/rtfobj.py b/oletools/rtfobj.py index f0b4e65..c8d2033 100644 --- a/oletools/rtfobj.py +++ b/oletools/rtfobj.py @@ -337,7 +337,7 @@ if sys.version_info[0] <= 2: BACKSLASH = '\\' BRACE_OPEN = '{' BRACE_CLOSE = '}' - UNICODE_TYPE = unicode + UNICODE_TYPE = unicode # pylint: disable=undefined-variable else: # Python 3.x - Integers BACKSLASH = ord('\\') diff --git a/oletools/xls_parser.py b/oletools/xls_parser.py index 2f0bdad..7abb96f 100644 --- a/oletools/xls_parser.py +++ b/oletools/xls_parser.py @@ -229,46 +229,46 @@ class XlsbStream(record_base.OleRecordStream): # records that appear often but do not need their own XlsRecord subclass (yet) FREQUENT_RECORDS = dict([ - ( 156, 'BuiltInFnGroupCount'), # pylint: disable=bad-whitespace - (2147, 'BookExt'), # pylint: disable=bad-whitespace - ( 442, 'CodeName'), # pylint: disable=bad-whitespace - ( 66, 'CodePage'), # pylint: disable=bad-whitespace - (4195, 'Dat'), # pylint: disable=bad-whitespace - (2154, 'DataLabExt'), # pylint: disable=bad-whitespace - (2155, 'DataLabExtContents'), # pylint: disable=bad-whitespace - ( 215, 'DBCell'), # pylint: disable=bad-whitespace - ( 220, 'DbOrParmQry'), # pylint: disable=bad-whitespace - (2051, 'DBQueryExt'), # pylint: disable=bad-whitespace - (2166, 'DConn'), # pylint: disable=bad-whitespace - ( 35, 'ExternName'), # pylint: disable=bad-whitespace - ( 23, 'ExternSheet'), # pylint: disable=bad-whitespace - ( 255, 'ExtSST'), # pylint: disable=bad-whitespace - (2052, 'ExtString'), # pylint: disable=bad-whitespace - (2151, 'FeatHdr'), # pylint: disable=bad-whitespace - ( 91, 'FileSharing'), # pylint: disable=bad-whitespace - (1054, 'Format'), # pylint: disable=bad-whitespace - ( 49, 'Font'), # pylint: disable=bad-whitespace - (2199, 'GUIDTypeLib'), # pylint: disable=bad-whitespace - ( 440, 'HLink'), # pylint: disable=bad-whitespace - ( 225, 'InterfaceHdr'), # pylint: disable=bad-whitespace - ( 226, 'InterfaceEnd'), # pylint: disable=bad-whitespace - ( 523, 'Index'), # pylint: disable=bad-whitespace - ( 24, 'Lbl'), # pylint: disable=bad-whitespace - ( 193, 'Mms'), # pylint: disable=bad-whitespace - ( 93, 'Obj'), # pylint: disable=bad-whitespace - (4135, 'ObjectLink'), # pylint: disable=bad-whitespace - (2058, 'OleDbConn'), # pylint: disable=bad-whitespace - ( 222, 'OleObjectSize'), # pylint: disable=bad-whitespace - (2214, 'RichTextStream'), # pylint: disable=bad-whitespace - (2146, 'SheetExt'), # pylint: disable=bad-whitespace - (1212, 'ShrFmla'), # pylint: disable=bad-whitespace - (2060, 'SxViewExt'), # pylint: disable=bad-whitespace - (2136, 'SxViewLink'), # pylint: disable=bad-whitespace - (2049, 'WebPub'), # pylint: disable=bad-whitespace - ( 224, 'XF (formatting)'), # pylint: disable=bad-whitespace - (2173, 'XFExt (formatting)'), # pylint: disable=bad-whitespace - ( 659, 'Style'), # pylint: disable=bad-whitespace - (2194, 'StyleExt') # pylint: disable=bad-whitespace + ( 156, 'BuiltInFnGroupCount'), + (2147, 'BookExt'), + ( 442, 'CodeName'), + ( 66, 'CodePage'), + (4195, 'Dat'), + (2154, 'DataLabExt'), + (2155, 'DataLabExtContents'), + ( 215, 'DBCell'), + ( 220, 'DbOrParmQry'), + (2051, 'DBQueryExt'), + (2166, 'DConn'), + ( 35, 'ExternName'), + ( 23, 'ExternSheet'), + ( 255, 'ExtSST'), + (2052, 'ExtString'), + (2151, 'FeatHdr'), + ( 91, 'FileSharing'), + (1054, 'Format'), + ( 49, 'Font'), + (2199, 'GUIDTypeLib'), + ( 440, 'HLink'), + ( 225, 'InterfaceHdr'), + ( 226, 'InterfaceEnd'), + ( 523, 'Index'), + ( 24, 'Lbl'), + ( 193, 'Mms'), + ( 93, 'Obj'), + (4135, 'ObjectLink'), + (2058, 'OleDbConn'), + ( 222, 'OleObjectSize'), + (2214, 'RichTextStream'), + (2146, 'SheetExt'), + (1212, 'ShrFmla'), + (2060, 'SxViewExt'), + (2136, 'SxViewLink'), + (2049, 'WebPub'), + ( 224, 'XF (formatting)'), + (2173, 'XFExt (formatting)'), + ( 659, 'Style'), + (2194, 'StyleExt') ]) #: records found in xlsb binary parts diff --git a/tests/ooxml/test_zip_sub_file.py b/tests/ooxml/test_zip_sub_file.py index 6e6085b..5998fbe 100644 --- a/tests/ooxml/test_zip_sub_file.py +++ b/tests/ooxml/test_zip_sub_file.py @@ -111,8 +111,8 @@ class TestZipSubFile(unittest.TestCase): self.assertEqual(self.subfile.tell(), self.compare.tell()) # seek backward (only implemented case: back to start) - self.subfile.seek(-self.subfile.tell(), os.SEEK_CUR) - self.compare.seek(-self.compare.tell(), os.SEEK_CUR) + self.subfile.seek(-1 * self.subfile.tell(), os.SEEK_CUR) + self.compare.seek(-1 * self.compare.tell(), os.SEEK_CUR) self.assertEqual(self.subfile.read(1), self.compare.read(1)) self.assertEqual(self.subfile.tell(), self.compare.tell())