當前位置: 首頁>>代碼示例>>Python>>正文


Python olefile.OleFileIO方法代碼示例

本文整理匯總了Python中olefile.OleFileIO方法的典型用法代碼示例。如果您正苦於以下問題:Python olefile.OleFileIO方法的具體用法?Python olefile.OleFileIO怎麽用?Python olefile.OleFileIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在olefile的用法示例。


在下文中一共展示了olefile.OleFileIO方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def __init__(self, file):
        self.format = "ooxml"
        file.seek(0)  # TODO: Investigate the effect (required for olefile.isOleFile)
        # olefile cannot process non password protected ooxml files.
        # TODO: this code is duplicate of OfficeFile(). Merge?
        if olefile.isOleFile(file):
            ole = olefile.OleFileIO(file)
            self.file = ole
            with self.file.openstream('EncryptionInfo') as stream:
                self.type, self.info = _parseinfo(stream)
            logger.debug("OOXMLFile.type: {}".format(self.type))
            self.secret_key = None
            if self.type == 'agile':
                # TODO: Support aliases?
                self.keyTypes = ('password', 'private_key', 'secret_key')
            elif self.type == 'standard':
                self.keyTypes = ('password', 'secret_key')
            elif self.type == 'extensible':
                pass
        elif zipfile.is_zipfile(file):
            self.file = file
            self.type, self.info = None, None
            self.secret_key = None
        else:
            raise Exception("Unsupported file format") 
開發者ID:nolze,項目名稱:msoffcrypto-tool,代碼行數:27,代碼來源:ooxml.py

示例2: __init__

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def __init__(self, file):
        self.file = file
        ole = olefile.OleFileIO(file)  # do not close this, would close file
        self.ole = ole
        self.format = "doc97"
        self.keyTypes = ['password']
        self.key = None
        self.salt = None

        # https://msdn.microsoft.com/en-us/library/dd944620(v=office.12).aspx
        with ole.openstream('wordDocument') as stream:
            fib = _parseFib(stream)

        # https://msdn.microsoft.com/en-us/library/dd923367(v=office.12).aspx
        tablename = '1Table' if fib.base.fWhichTblStm == 1 else '0Table'

        Info = namedtuple('Info', ['fib', 'tablename'])
        self.info = Info(
            fib=fib,
            tablename=tablename,
        ) 
開發者ID:nolze,項目名稱:msoffcrypto-tool,代碼行數:23,代碼來源:doc97.py

示例3: __init__

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def __init__(self, msg_file_path):
        self.msg_file_path = msg_file_path
        self.include_attachment_data = False

        if not self.is_valid_msg_file():
            raise Exception(
                "Invalid file provided, please provide valid Microsoft’s Outlook MSG file."
            )

        with OleFileIO(msg_file_path) as ole_file:
            # process directory entries
            ole_root = ole_file.root
            kids_dict = ole_root.kids_dict

            self._message = Message(kids_dict)
            self._message_dict = self._message.as_dict()

            # process msg properties
            self._set_properties()

            # process msg recipients
            self._set_recipients()

            # process attachments
            self._set_attachments() 
開發者ID:vikramarsid,項目名稱:msg_parser,代碼行數:27,代碼來源:msg_parser.py

示例4: stomp_it

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def stomp_it(stomped_file):    
    # Open file to mangle the VBA streams.
    with olefile.OleFileIO(stomped_file, write_mode=True) as ole:
    
        # Mangle the macro VBA streams.
        for stream_name in ole.listdir():
        
            # Got macros?
            data = ole.openstream(stream_name).read()
            
            marker = b"Attrib"
            if marker not in data:
                continue
           
            # Find where to write.
            start = data.rindex(marker)

            # Stomp the rest of the data.
            new_data = data[:start]
            for i in range(start, len(data)):
                # Stomp with random bytes.
                new_data += os.urandom(1)
            
            # Write out the garbage data.
            ole.write_stream(stream_name, new_data) 
開發者ID:haroldogden,項目名稱:adb,代碼行數:27,代碼來源:stomp_vba.py

示例5: is_encrypted

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def is_encrypted(self):
        # Heuristic
        if isinstance(self.file, olefile.OleFileIO):
            return True
        else:
            return False 
開發者ID:nolze,項目名稱:msoffcrypto-tool,代碼行數:8,代碼來源:ooxml.py

示例6: __init__

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def __init__(self, file):
        self.file = file
        ole = olefile.OleFileIO(file)  # do not close this, would close file
        self.ole = ole
        self.format = "xls97"
        self.keyTypes = ['password']
        self.key = None
        self.salt = None

        workbook = ole.openstream('Workbook')    # closed in destructor

        Data = namedtuple('Data', ['workbook'])
        self.data = Data(
            workbook=workbook,
        ) 
開發者ID:nolze,項目名稱:msoffcrypto-tool,代碼行數:17,代碼來源:xls97.py

示例7: _open

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def _open(self):

        # read the OLE directory and see if this is a likely
        # to be a Microsoft Image Composer file

        try:
            self.ole = olefile.OleFileIO(self.fp)
        except IOError:
            raise SyntaxError("not an MIC file; invalid OLE file")

        # find ACI subfiles with Image members (maybe not the
        # best way to identify MIC files, but what the... ;-)

        self.images = []
        for path in self.ole.listdir():
            if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
                self.images.append(path)

        # if we didn't find any images, this is probably not
        # an MIC file.
        if not self.images:
            raise SyntaxError("not an MIC file; no image entries")

        self.__fp = self.fp
        self.frame = None

        if len(self.images) > 1:
            self.category = Image.CONTAINER

        self.seek(0) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:32,代碼來源:MicImagePlugin.py

示例8: _open

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def _open(self):
        #
        # read the OLE directory and see if this is a likely
        # to be a FlashPix file

        try:
            self.ole = olefile.OleFileIO(self.fp)
        except IOError:
            raise SyntaxError("not an FPX file; invalid OLE file")

        if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
            raise SyntaxError("not an FPX file; bad root CLSID")

        self._open_index(1) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:16,代碼來源:FpxImagePlugin.py

示例9: _open

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def _open(self):

        # read the OLE directory and see if this is a likely
        # to be a Microsoft Image Composer file

        try:
            self.ole = olefile.OleFileIO(self.fp)
        except OSError:
            raise SyntaxError("not an MIC file; invalid OLE file")

        # find ACI subfiles with Image members (maybe not the
        # best way to identify MIC files, but what the... ;-)

        self.images = []
        for path in self.ole.listdir():
            if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
                self.images.append(path)

        # if we didn't find any images, this is probably not
        # an MIC file.
        if not self.images:
            raise SyntaxError("not an MIC file; no image entries")

        self.__fp = self.fp
        self.frame = None

        if len(self.images) > 1:
            self.category = Image.CONTAINER

        self.seek(0) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:32,代碼來源:MicImagePlugin.py

示例10: _open

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def _open(self):
        #
        # read the OLE directory and see if this is a likely
        # to be a FlashPix file

        try:
            self.ole = olefile.OleFileIO(self.fp)
        except OSError:
            raise SyntaxError("not an FPX file; invalid OLE file")

        if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
            raise SyntaxError("not an FPX file; bad root CLSID")

        self._open_index(1) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:16,代碼來源:FpxImagePlugin.py

示例11: __init__

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def __init__(self, filename):
        OleFile.OleFileIO.__init__(self, filename) 
開發者ID:doomedraven,項目名稱:VirusTotalApi,代碼行數:4,代碼來源:outlook_parser.py

示例12: ole_parser

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def ole_parser(s):
    ole = olefile.OleFileIO(s)
    meta = ole.get_metadata()
    attrs = meta.DOCSUM_ATTRIBS + meta.SUMMARY_ATTRIBS
    #meta.dump()
    result = {}
    for attr in attrs:
        if hasattr(meta, attr):
            result[attr] = getattr(meta, attr)
    ole.close()
    return result 
開發者ID:lanmaster53,項目名稱:recon-ng-marketplace,代碼行數:13,代碼來源:metacrawler.py

示例13: scan

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def scan(self, payload: Payload, request: Request) -> WorkerResponse:
        extracted: List[ExtractedPayload] = []
        errors: List[Error] = []
        ole_object = olefile.OleFileIO(payload.content)
        streams = ole_object.listdir(streams=True)
        for stream in streams:
            try:
                stream_buffer = ole_object.openstream(stream).read()
                name = ''.join(
                    filter(lambda x: x in string.printable, '_'.join(stream))
                )
                if stream_buffer.endswith(b'\x01Ole10Native'):
                    ole_native = oleobj.OleNativeStream(stream_buffer)
                    if ole_native.filename:
                        name = f'{name}_{str(ole_native.filename)}'
                    else:
                        name = f'{name}_olenative'
                    meta = PayloadMeta(
                        should_archive=False,
                        extra_data={'index': streams.index(stream), 'name': name},
                    )
                    extracted.append(ExtractedPayload(ole_native.data, meta))
                else:
                    meta = PayloadMeta(
                        should_archive=False,
                        extra_data={'index': streams.index(stream), 'name': name},
                    )
                    extracted.append(ExtractedPayload(stream_buffer, meta))
            except Exception as err:
                errors.append(
                    Error(
                        error=str(err),
                        plugin_name=self.plugin_name,
                        payload_id=payload.payload_id,
                    )
                )
        return WorkerResponse(extracted=extracted, errors=errors) 
開發者ID:PUNCH-Cyber,項目名稱:stoq-plugins-public,代碼行數:39,代碼來源:ole.py

示例14: extract_ole_metadata

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def extract_ole_metadata(self, file_path):
        with open(file_path, 'rb') as fh:
            if not isOleFile(fh):
                return
            fh.seek(0)
            try:
                ole = OleFileIO(fh)
                self.extract_olefileio_metadata(ole)
            except (RuntimeError, IOError):
                # OLE reading can go fully recursive, at which point it's OK
                # to just eat this runtime error quietly.
                log.warning("Failed to read OLE data: %s", self.result)
            except Exception:
                log.exception("Failed to read OLE data: %s", self.result) 
開發者ID:occrp-attic,項目名稱:ingestors,代碼行數:16,代碼來源:ole.py

示例15: ole_parser

# 需要導入模塊: import olefile [as 別名]
# 或者: from olefile import OleFileIO [as 別名]
def ole_parser(s):
    ole = olefile.OleFileIO(s)
    meta = ole.get_metadata()
    #meta.dump()
    result = {
        'author': meta.author,
        'last saved by': meta.last_saved_by,
        'company': meta.company,
    }
    ole.close()
    return result 
開發者ID:praetorian-code,項目名稱:pentestly,代碼行數:13,代碼來源:parsers.py


注:本文中的olefile.OleFileIO方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。