From 87a69ade07f3bd276349eea7d32013b3b1240177 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 10 May 2016 09:37:35 +0200 Subject: [PATCH] made CurrentUserAtom a PptType -- streamlined last remaining class (currently) --- oletools/ppt_parser.py | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------- 1 file changed, 112 insertions(+), 105 deletions(-) diff --git a/oletools/ppt_parser.py b/oletools/ppt_parser.py index d9b4d1d..a3185f9 100644 --- a/oletools/ppt_parser.py +++ b/oletools/ppt_parser.py @@ -16,7 +16,6 @@ References: # TODO #------------------------------------------------------------------------------ # TODO: -# - make CurrentUserAtom and UserEditAtom PptTypes; adjust parse # - make stream optional in PptUnexpectedData # - can speed-up by using less bigger struct.parse calls? # - license @@ -125,97 +124,6 @@ class RecordHeader(object): return obj -class CurrentUserAtom(object): - """ An atom record that specifies information about the last user to modify - the file and where the most recent user edit is located. This is the only - record in the Current User Stream (section 2.1.1). - - https://msdn.microsoft.com/en-us/library/dd948895%28v=office.12%29.aspx - """ - - # allowed values for header_token - HEADER_TOKEN_ENCRYPT = 0xF3D1C4DF - HEADER_TOKEN_NOCRYPT = 0xE391C05F - - # allowed values for rel_version - REL_VERSION_CAN_USE = 0x00000008 - REL_VERSION_NO_USE = 0x00000009 - - # required values - RECORD_TYPE = 0x0FF6 - SIZE = 0x14 - DOC_FILE_VERSION = 0x03F4 - MAJOR_VERSION = 0x03 - MINOR_VERSION = 0x00 - - def __init__(self): - self.rec_head = None - self.size = None - self.header_token = None - self.offset_to_current_edit = None - self.len_user_name = None - self.doc_file_version = None - self.major_version = None - self.minor_version = None - self.ansi_user_name = None - self.unicode_user_name = None - self.rel_version = None - - def is_encrypted(self): - return self.header_token == self.HEADER_TOKEN_ENCRYPT - - @classmethod - def extract_from(clz, ole): - """ extract info from olefile """ - - log.debug('parsing "Current User"') - - stream = None - try: - # open stream - log.debug('opening stream') - stream = ole.openstream('Current User') - obj = clz() - - # parse record header - obj.rec_head = RecordHeader.extract_from(stream) - check_value('rec_version', obj.rec_head.rec_ver, 0) - check_value('rec_instance', obj.rec_head.rec_instance, 0) - check_value('rec_type', obj.rec_head.rec_type, clz.RECORD_TYPE) - - size, = struct.unpack(' 255: - raise PptUnexpectedData( - 'Current User', 'CurrentUserAtom.lenUserName', - obj.len_user_name, '< 256') - obj.doc_file_version, = struct.unpack('