+
    ¿Ìjr   ã                   ó  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIt^ RIt]P                  P                  ]P                  P!                  ]P                  P#                  ]4      4      4      t]P                  P                  ]P                  P)                  ]R4      4      t]]P                  9  d   ]P                  P-                  ^ ]4       ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIH t  R	t!R
t"R]PF                  R]PH                  R
]PJ                  R]PL                  R]PN                  R]PF                  /t( ! R R]PR                  4      t*]PN                  ^,           3R lt+]+! R4      t,R t-]P\                  ^ ,          ^8:  d   Rt/M^ t/]0t1Rt2Rt3Rt4]Pj                  ! R4      t6]6Pn                  ^8X  g   Q h]Pj                  ! R4      t8]8Pn                  ^8X  g   Q hRt9Rt:^ t;^t<^t=^t>^t?. R4Ot@^ÿtA^dtBR tCR tDR tER  tFR! tG ! R" R#]H4      tI ! R$ R%]H4      tJR& tKR']A3R( ltLR) tMR* tN ! R+ R,]	Pž                  4      tPR5R- ltQR. tRR/ tSR5R0 ltTR1 tUR5R2 ltV]WR38X  d   ]P°                  ! ]V! 4       4       R# R# )6a_  
oleobj.py

oleobj is a Python script and module to parse OLE objects and files stored
into various MS Office file formats (doc, xls, ppt, docx, xlsx, pptx, etc)

Author: Philippe Lagadec - http://www.decalage.info
License: BSD, see source code or documentation

oleobj is part of the python-oletools package:
http://www.decalage.info/python/oletools
)Úprint_functionN)Ú
is_zipfileú..)Úxglob)Úis_pptÚPptFileÚPptRecordExOleVbaActiveXAtom)Ú	XmlParser)Úensure_stdout_handles_unicodez0.60.1ÚwarningÚdebugÚinfoÚerrorÚcriticalúdebug-olefilec                   ó*   a € ] tR t^zt o RtR tRtV tR# )ÚNullHandlera  
Log Handler without output, to avoid printing messages if logging is not
configured by the main application.
Python 2.7 has logging.NullHandler, but this is necessary for 2.6:
see https://docs.python.org/2.6/library/logging.html section
configuring-logging-for-a-library
c                ó   € R # ©N© )ÚselfÚrecords   &&Úi/home/l0st/web/w4ttz.lol/public_html/toolz/MsgDoxxer/venv/lib/python3.14/site-packages/oletools/oleobj.pyÚemitÚNullHandler.emit‚   s   € Ùó    r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r   z   s   ø‡ € ñ÷ð r   r   c                ó*  € V \         P                  P                  P                  9   d*   \         P                  ! V 4      pVP                  V4       V# \         P                  ! V 4      pVP                  \        4       4       VP                  V4       V# )aR  
Create a suitable logger object for this module.
The goal is not to change settings of the root logger, to avoid getting
other modules' logs on the screen.
If a logger exists with same name, reuse it. (Else it would have duplicate
handlers and messages would be doubled.)
The level is set to CRITICAL+1 by default, to avoid any logging.
)ÚloggingÚLoggerÚmanagerÚ
loggerDictÚ	getLoggerÚsetLevelÚ
addHandlerr   )ÚnameÚlevelÚloggers   && r   Ú
get_loggerr0   †   sr   € ð Œw�~‰~×%Ñ%×0Ñ0Ô0ô ×"Ò" 4Ó(ˆà�‰˜ÔØˆä×Ò˜tÓ$€Fð ×Ñ”k“mÔ$Ø
‡O�O�EÔØ€Mr   Úoleobjc                 óL   € \         P                  \        P                  4       R# )zµ
Enable logging for this module (disabled by default).
This will set the module-specific logger level to NOTSET, which
means the main application controls the actual logging level.
N)Úlogr+   r&   ÚNOTSETr   r   r   Úenable_loggingr5   ¥   s   € ô ‡L�L”—‘Ö r   Ú zJ{http://schemas.openxmlformats.org/package/2006/relationships}Relationshipz>{http://schemas.microsoft.com/office/2006/01/customui}customUIz>{http://schemas.microsoft.com/office/2009/07/customui}customUIz<Lz<Hi   i   c                óÈ   € Vf/   \         P                  V P                  ^4      4      ^ ,          pW!3# \         P                  WV^,            4      ^ ,          pV^,          pW!3# )a>  
Read an unsigned integer from the first 32 bits of data.

:param data: bytes string or stream containing the data to be extracted.
:param index: index to start reading from or None if data is stream.
:return: tuple (value, index) containing the read value (int),
         and the index to continue reading next time.
)ÚSTRUCT_UINT32ÚunpackÚread©ÚdataÚindexÚvalues   && r   Úread_uint32r?   ó   óa   € ð ‚}Ü×$Ñ$ T§Y¡Y¨q£\Ó2°1Õ5ˆð ˆ>Ðô ×$Ñ$ T°°aµÐ%8Ó9¸!Õ<ˆØ��
ˆØˆ>Ðr   c                óÈ   € Vf/   \         P                  V P                  ^4      4      ^ ,          pW!3# \         P                  WV^,            4      ^ ,          pV^,          pW!3# )aG  
Read an unsigned integer from the 16 bits of data following index.

:param data: bytes string or stream containing the data to be extracted.
:param index: index to start reading from or None if data is stream
:return: tuple (value, index) containing the read value (int),
         and the index to continue reading next time.
)ÚSTRUCT_UINT16r9   r:   r;   s   && r   Úread_uint16rC     r@   r   c                ó  € \        W4      w  r!V^ 8X  d   RV3# Vf+   V P                  V^,
          4      pV P                  ^4      pM/WW,           ^,
           pWV,           ^,
          ,          pW,          pV\        8X  g   Q hW13# )aU  
Read a length-prefixed ANSI string from data.

:param data: bytes string or stream containing the data to be extracted.
:param index: index in data where string size start or None if data is
              stream
:return: tuple (value, index) containing the read value (bytes string),
         and the index to start reading from next time.
Ú )r?   r:   Ú	NULL_CHAR)r<   r=   ÚlengthÚansi_stringÚ	null_chars   &&   r   Úread_length_prefixed_stringrJ     s…   € ô   Ó,�M€Fà�„{Ø�Eˆ{Ðà‚}Ø—i‘i  q¥Ó)ˆØ—I‘I˜a“L‰	à ¥¨a¥Ð0ˆØ˜v� a�Õ(ˆ	Ø�ˆð œ	Ô!Ð!Ð!ØÐÐr   c                óü   € R F=  p V P                  VRR7      p\        P                  RP                  W4      4       Vu # 	  \        P                  R4       V P                  RRR7      #   \         d     Kw  i ; i)z¡guess encoding of byte string to create unicode

Since this is used to decode path names from ole objects, prefer latin1
over utf* codecs if ascii is not enough
ÚasciiÚstrict)Úerrorszdecoded using {0}: "{1}"zGfailed to guess encoding for string, falling back to ascii with replaceÚreplace)rL   Úlatin1Úutf8z	utf-16-leÚutf16)Údecoder3   r   ÚformatÚUnicodeErrorr   )r<   ÚencodingÚresults   &  r   Úguess_encodingrX   1  s~   € ó Dˆð	Ø—[‘[ °(�[Ó;ˆFÜ�I‰IÐ1×8Ñ8¸ÓJÔKØŠMñ	 Dô ‡K�Kð %ô &à�;‰;�w yˆ;Ó1Ð1øô	 ô 	Úð	ús   ‡8A,Á,A;Á:A;c                óH  € Vfm   \        4       p\        \        4       FD  p\        V P	                  ^4      4      pV^ 8X  d   \        V4      V3u # VP                  V4       KF  	  \        R4      hV P                  RW\        ,           4      p\        WV 4      V^,           3# )aC  
Read a zero-terminated string from data

:param data: bytes string or stream containing an ansi string
:param index: index at which the string should start or None if data is
              stream
:return: tuple (unicode, index) containing the read string (unicode),
         and the index to start reading from next time.
z&found no string-terminating zero-byte!ó    )	Ú	bytearrayÚxrangeÚSTR_MAX_LENÚordr:   rX   ÚappendÚ
ValueErrorr=   )r<   r=   rW   Ú_ÚcharÚend_idxs   &&    r   Úread_zero_terminated_stringrd   C  s�   € ð ‚}Ü“ˆäœÖ$ˆAÜ�t—y‘y “|Ó$ˆDØ�qŒyÜ% fÓ-¨uÐ4Ò4Ø�M‰M˜$Öñ	 %ô
 ÐAÓBÐBà—*‘*˜W e´;Õ->Ó?ˆä˜d¨Ð1Ó2°G¸AµIÐ=Ð=r   c                   ó<   a € ] tR tRt o Rt^t^tRR ltR tRt	V t
R# )ÚOleNativeStreami_  zŠ
OLE object contained into an OLENativeStream structure.
(see MS-OLEDS 2.3.6 OLENativeStream)

Filename and paths are decoded to unicode.
Nc                óÎ   € RV n         RV n        RV n        RV n        RV n        RV n        RV n        RV n        W n        RV n	        RV n
        Ve   V P                  VR7       R# R# )z÷
Constructor for OleNativeStream.
If bindata is provided, it will be parsed using the parse() method.

:param bindata: forwarded to parse, see docu there
:param package: bool, set to True when extracting from an OLE Package
                object
N)r<   )ÚfilenameÚsrc_pathÚunknown_shortÚunknown_long_1Úunknown_long_2Ú	temp_pathÚactual_sizer<   ÚpackageÚis_linkÚdata_is_streamÚparse)r   Úbindataro   s   &&&r   Ú__init__ÚOleNativeStream.__init__k  sm   € ð ˆŒØˆŒØ!ˆÔØ"ˆÔØ"ˆÔØˆŒØˆÔØˆŒ	ØŒØˆŒØ"ˆÔØÒØ�J‰J˜GˆJÖ$ñ r   c                ó  € \        VR4      '       d   RV n        RpM	RV n        ^ pV P                  '       gB   \        W4      w  V n        p\
        P                  RP                  V P                  4      4       \        W4      w  V n	        p\        W4      w  V n        p\        W4      w  V n        p\        W4      w  V n        p\        W4      w  V n        p\        W4      w  V n        p \        W4      w  V n        pV P                  '       d   Wn        MWW P                   ,            V n        RV n        R#   \&        \(        P*                  3 d/    \
        P                  R4       RT n        ^ T n        RT n         R# i ; i)a  
Parse binary data containing an OLENativeStream structure,
to extract the OLE object it contains.
(see MS-OLEDS 2.3.6 OLENativeStream)

:param data: bytes array or stream, containing OLENativeStream
             structure containing an OLE object
:return: None
r:   TNFz*OLE native data size = {0:08X} ({0} bytes)z$data is not embedded but only a link)Úhasattrrq   ro   r?   Únative_data_sizer3   r   rT   rC   rj   rd   rh   ri   rk   rl   rm   rn   r<   rp   ÚIOErrorÚstructr   ©r   r<   r=   s   && r   rr   ÚOleNativeStream.parse‚  sS  € ô �4˜× Ò Ø"&ˆDÔØ‰Eà"'ˆDÔØˆEð �|�|ˆ|Ü+6°tÓ+CÑ(ˆDÔ! 5Ü�I‰IÐBß‘v˜d×3Ñ3Ó4ô6ô %0°Ó$<Ñ!ˆÔ˜EÜ:¸4ÓGÑˆŒ�uä:¸4ÓGÑˆŒ�uä%0°Ó%=Ñ"ˆÔ˜UÜ%0°Ó%=Ñ"ˆÔ˜Uä ;¸DÓ HÑˆŒ˜ð	Ü&1°$Ó&>Ñ#ˆDÔ˜eØ×"×"Ð"Ø •	à  u×-=Ñ-=Õ'=Ð>�”	Ø ˆDŽLøô œŸ™Ð&ô 	Ü�I‰IÐ<Ô=ØˆDŒLØ ˆDÔØˆD�Ið		ús   Ã,AD: Ä:AFÆF)rn   r<   rq   rh   rp   rx   ro   ri   rm   rk   rl   rj   )NF©r   r   r   r   r    ÚTYPE_LINKEDÚTYPE_EMBEDDEDrt   rr   r!   r"   r#   s   @r   rf   rf   _  s%   ø‡ € ñð €KØ€Mô%÷.0ð 0r   rf   c                   ó<   a € ] tR tRt o Rt^t^tRR ltR tRt	V t
R# )Ú	OleObjectiµ  z;
OLE 1.0 Object

see MS-OLEDS 2.2 OLE1.0 Format Structures
Nc                ó–   € RV n         RV n        RV n        RV n        RV n        RV n        RV n        Ve   V P                  V4       R# R# )a  
Constructor for OleObject.
If bindata is provided, it will be parsed using the parse() method.

:param bindata: bytes, OLE 1.0 Object structure containing OLE object

Note: Code can easily by generalized to work with byte streams instead
      of arrays just like in OleNativeStream.
N)Úole_versionÚ	format_idÚ
class_nameÚ
topic_nameÚ	item_namer<   Ú	data_sizerr   )r   rs   s   &&r   rt   ÚOleObject.__init__Á  sM   € ð  ˆÔØˆŒØˆŒØˆŒØˆŒØˆŒ	ØˆŒØÒØ�J‰J�wÖñ r   c                óP  € ^ p\        W4      w  V n        p\        W4      w  V n        p\        P	                  RV P                  V P                  4       V P                  V P
                  V P                  39   g   Q h\        W4      w  V n        p\        W4      w  V n	        p\        W4      w  V n
        p\        P	                  RV P                  V P                  V P                  4       V P                  V P
                  8X  d    \        W4      w  V n        p\        P	                  RV P                  \        V4      V,
          4       WW P                  ,            V n        \        V P                  4      V P                  8X  g   Q hWV P                  ,           R V n        R# R# )zÞ
Parse binary data containing an OLE 1.0 Object structure,
to extract the OLE object it contains.
(see MS-OLEDS 2.2 OLE1.0 Format Structures)

:param data: bytes, OLE 1.0 Object structure containing an OLE object
:return:
z!OLE version=%08X - Format ID=%08Xz,Class name=%r - Topic name=%r - Item name=%rz)Declared data size=%d - remaining size=%dN)r?   rƒ   r„   r3   r   r   r~   rJ   r…   r†   r‡   rˆ   Úlenr<   Ú
extra_datar{   s   && r   rr   ÚOleObject.parseÕ  sR  € ð ˆÜ"-¨dÓ":ÑˆÔ˜%Ü +¨DÓ 8ÑˆŒ˜Ü�	‰	Ð5Ø×"Ñ" D§N¡Nô	4à�~‰~ $×"4Ñ"4°d×6FÑ6FÐ!GÔGÐGÐGÜ!<¸TÓ!IÑˆŒ˜Ü!<¸TÓ!IÑˆŒ˜Ü ;¸DÓ HÑˆŒ˜Ü�	‰	Ð@Ø—/‘/ 4§?¡?°D·N±Nô	Dà�>‰>˜T×/Ñ/Ô/ô %0°Ó$<Ñ!ˆDŒN˜EÜ�I‰IÐAØ—n‘n¤c¨$£i°¥oô7ð  5¯©Õ#7Ð8ˆDŒIÜ�t—y‘y“> T§^¡^Ô3Ð3Ð3Ø"¨¯©Õ#7Ð#8Ð9ˆDŽOñ 0r   )r…   r<   rˆ   rŒ   r„   r‡   rƒ   r†   r   r}   r#   s   @r   r�   r�   µ  s%   ø‡ € ñð €KØ€Mô ÷(!:ð !:r   r�   c                óÄ   € V'       g   V # \        V 4      pW!8  d   V # V P                  R4      pVR8X  d   V RV # W#,
          pWA8”  d   V RV # V RW,
           WR ,           # )z@Create filename shorter than max_len, trying to preserve suffix.Ú.Néÿÿÿÿ)r‹   Úrfind)ÚfnameÚmax_lenÚname_lenÚidxÚ
suffix_lens   &&   r   Úshorten_filenamer—   ù  sv   € ÷ ØˆÜ�5‹z€HØÔØˆà
�+‰+�cÓ
€CØ
ˆb„yØ�X�gˆÐà•€JØÔØ�X�gˆÐð Ð$�'Õ$Ð%¨¨d¨Õ3Ð3r   ra   c                ó"  € \         P                  P                  V 4      P                  4       p\        P
                  ! RW4      p\        V4      pRV9   d   VP                  RR4      pK  RV9   d   VP                  RR4      pK  \        WB4      # )a  
Return filename that is save to work with.

Removes path components, replaces all non-whitelisted characters (so output
is always a pure-ascii string), replaces '..' and '  ' and shortens to
given max length, trying to preserve suffix.

Might return empty string
z[^a-zA-Z0-9._ -]r   r�   z  Ú )	ÚosÚpathÚbasenameÚstripÚreÚsubÚstrrO   r—   )rh   Úreplacementr“   ÚbasepathÚ
sane_fnames   &&&  r   Úsanitize_filenamer¤     s|   € ô �w‰w×Ñ Ó)×/Ñ/Ó1€HÜ—’Ð+¨[ÓC€JÜ�Z“€Jà
�*Ô
Ø×'Ñ'¨¨cÓ2Š
à
�*Ô
Ø×'Ñ'¨¨cÓ2Š
ô ˜JÓ0Ð0r   c              #  óð  "  € . p. pWV3 FÈ  p\        VP                  R4      VP                  R4      4      pWx^,           R P                  4       p\        WsR7      pV'       g   K\  VP                  R4      pVR	8X  d   VP	                  V4       K‡  V\        V4      ^,
          8  d   VP	                  V4       K±  VP	                  WxR 4       Vx € KÊ  	  V F  pVx € K	  	  VP	                  R4       \        \        4       Fa  p	V FX  p
V\        V
4      ,
          pV^8  d   K  RP                  \        P                  ! R\        ^V4      4      4      pWÊ,           x € KZ  	  Kc  	  RV,          x € R# 5i)
a  
Get some sane filenames out of path information, preserving file suffix.

Returns several canddiates, first with suffix, then without, then random
with suffix and finally one last attempt ignoring max_len using arg
`noname_index`.

In some malware examples, filename (on which we relied sofar exclusively
for this) is empty or " ", but src_path and tmp_path contain paths with
proper file names. Try to extract filename from any of those.

Preservation of suffix is especially important since that controls how
windoze treats the file.
Ú/Ú\N©r“   r�   rE   Úabcdefghijklmnopqrstuvwxyzzoleobj_%03dr�   )Úmaxr‘   r�   r¤   r_   r‹   ÚrangeÚMAX_FILENAME_ATTEMPTSÚjoinÚrandomÚsampleÚmin)rh   ri   Útmp_pathr“   Únoname_indexÚsuffixesÚcandidates_without_suffixÚ	candidater•   ra   ÚsuffixÚleftover_lenr-   s   &&&&&        r   Úget_sane_embedded_filenamesr¸   '  sX  é € ð  €HØ "ÐØ¨(Ó3ˆ	ä�)—/‘/ #Ó&¨	¯©¸Ó(=Ó>ˆØ !�e˜fÐ%×+Ñ+Ó-ˆ	ô & iÔAˆ	çÙð �o‰o˜cÓ"ˆØ�"Œ9Ø%×,Ñ,¨YÔ7ÙØ”3�y“> !Õ#Ô#Ø%×,Ñ,¨YÔ7Ùð 	�‰˜	 $˜Ô(àŒñ/ 4ó4 /ˆ	ØŒñ /ð ‡O�O�BÔÜÔ(Ö)ˆÛˆFØ"¤S¨£[Õ0ˆLØ˜aÔÙØ—7‘7œ6Ÿ=š=Ð)EÜ),¨R°Ó)>ó@ó AˆDà•-Ôó ñ *ð ˜,Õ
&Ô&ùs   ‚E4E6c              #  ó†  "  € Rp \        V 4      pVP                  4        Fú  p\        VP                  4       4       FÚ  w  r4\	        V\
        4      '       g   K  Rp \        VP                  4       4      pVR\        \        P                  4       \        P                  8w  d    Vf   Ko  VP                  4        K�  \        P                  RP                  VP                  V4      4       VP!                  4       pVx € Ve   VP                  4        KÚ  KÜ  	  Kü  	  Ve   VP                  4        R# R#   \"         dI    \        P%                  RP                  TP                  4      4       \        P                  RRR7        Lˆi ; i  Te   TP                  4        i i ; i  Te   TP                  4        i i ; i5i)a  find ole streams in ppt

This may be a bit confusing: we get an ole file (or its name) as input and
as output we produce possibly several ole files. This is because the
data structure can be pretty nested:
A ppt file has many streams that consist of records. Some of these records
can contain data which contains data for another complete ole file (which
we yield). This embedded ole file can have several streams, one of which
can contain the actual embedded file we are looking for (caller will check
for these).
NzJFound record with embedded ole object in ppt (stream "{0}", record no {1})zCError reading data from {0} stream or interpreting it as OLE objectrE   T©Úexc_info)r   Úiter_streamsÚ	enumerateÚiter_recordsÚ
isinstancer   ÚnextÚiter_uncompressedr‹   ÚolefileÚMAGICÚcloser3   r   rT   r-   Úget_data_as_olefilery   r   )rh   Úppt_fileÚstreamÚ
record_idxr   ÚoleÚ
data_starts   &      r   Úfind_ole_in_pptrË   f  s{  é € ð €HðÜ˜8Ó$ˆØ×+Ñ+Ö-ˆFÜ&/°×0CÑ0CÓ0EÖ&FÑ"�
Ü˜fÔ&B×CÔCØ�Cð(Ü%)¨&×*BÑ*BÓ*DÓ%E˜
Ø%Ð&9¤s¬7¯=©=Ó'9Ð:¼g¿m¹mÔKØ$ð œ?ØŸI™IžKô Ÿ	™	ð #Fç#)¡6¨&¯+©+°zÓ#BôDð %×8Ñ8Ó:˜Ø!š	ð š?ØŸI™IžKñ +ó) 'Gñ .ð0 ÒØ�N‰NÖñ  øô #ô 5ÜŸ™ð %Dç%+¡V¨F¯K©KÓ%8ô:ô Ÿ	™	 "¨t˜	Ö4ð	5ûð š?ØŸI™I�Kð +ûð ÒØ�N‰NÕð  üsh   ‚G†AF' ÁF' ÁAD7Â&F' Â,F' Â>AD7ÄF' ÄGÄ7AF
ÆFÆ	F
Æ
FÆF$Æ$F' Æ'F>Æ>Gc                   ó~   a a€ ] tR tRt oRtV 3R ltR tR tR tR t	RR lt
]P                  3R	 ltR
 tRtVtV ;t# )ÚFakeFilei‘  al  create file-like object from data without copying it

BytesIO is what I would like to use but it copies all the data. This class
does not. On the downside: data can only be read and seeked, not written.

Assume that given data is bytes (str in py2, bytes in py3).

See also (and maybe can put into common file with):
ppt_record_parser.IterStream, ooxml.ZipSubFile
c                óf   <€ \         \        V `  4        Wn        ^ V n        \        V4      V n        R# )z&create FakeFile with given bytes data N)ÚsuperrÍ   rt   r<   Úposr‹   Úsize)r   r<   Ú	__class__s   &&€r   rt   ÚFakeFile.__init__�  s'   ø€ äŒh˜Ñ&Ô(ØŒ	ØˆŒÜ˜“IˆŽ	r   c                ó   € R # ©Tr   ©r   s   &r   ÚreadableÚFakeFile.readable¤  ó   € Ùr   c                ó   € R # )Fr   rÖ   s   &r   ÚwritableÚFakeFile.writable§  s   € Ùr   c                ó   € R # rÕ   r   rÖ   s   &r   ÚseekableÚFakeFile.seekableª  rÙ   r   c                ó  € \        \        V4      V P                  V P                  ,
          4      pV^ 8X  d   ^ # V P                  V P                  V P                  V,            VRV% V ;P                  V,          un        V# )zread into pre-allocated target N)r°   r‹   rÑ   rÐ   r<   )r   ÚtargetÚn_datas   && r   ÚreadintoÚFakeFile.readinto­  s^   € ä”S˜“[ $§)¡)¨D¯H©HÕ"4Ó5ˆØ�QŒ;ÙØŸ)™) D§H¡H¨T¯X©X°f­_Ð=ˆˆw�ˆØ�Š�FÕ�Øˆr   c                ó  € V P                   V P                  8¼  d   \        4       # VR8X  d   V P                  V P                   ,
          pV P                  V P                   V P                   V,            pV ;P                   V,          un         V# )zread and return data r�   )rÐ   rÑ   Úbytesr<   )r   râ   rW   s   && r   r:   ÚFakeFile.read¶  sa   € à�8‰8�t—y‘yÔ Ü“7ˆNØ�RŒ<Ø—Y‘Y §¡Õ)ˆFØ—‘˜4Ÿ8™8 D§H¡H¨V¥OÐ4ˆØ�Š�FÕ�Øˆr   c                ó>  € V\         P                  8X  d   TpMlV\         P                  8X  d   V P                  V,           pMCV\         P                  8X  d   V P
                  V,           pM\        RP                  V4      4      hV^ 8  d   \        R4      hW0n        R# )z!jump to another position in file z(invalid offset {0}, need SEEK_* constantz%Seek beyond start of file not allowedN)	ÚioÚSEEK_SETÚSEEK_CURrÐ   ÚSEEK_ENDrÑ   r`   rT   ry   )r   rÐ   ÚoffsetÚnew_poss   &&& r   ÚseekÚFakeFile.seekÀ  sx   € ð ”R—[‘[Ô Ø‰GØ”r—{‘{Ô"Ø—h‘h •n‰GØ”r—{‘{Ô"Ø—i‘i #•o‰GäÐGß$™f V›nó.ð .à�QŒ;ÜÐAÓBÐBØŽr   c                ó   € V P                   # )z%tell where in file we are positioned )rÐ   rÖ   s   &r   ÚtellÚFakeFile.tellÐ  s   € à�x‰xˆr   )r<   rÐ   rÑ   )r�   )r   r   r   r   r    rt   r×   rÛ   rÞ   rã   r:   ré   rê   rï   rò   r!   r"   Ú__classcell__)rÒ   r$   s   @@r   rÍ   rÍ   ‘  s@   ù‡ € ñ	õòòòòôð  "Ÿ{™{ô ÷ ò r   rÍ   c              #  ó‚  "  € Ve$   \         P                  R4       Tp\        V4      pM\         P                  R4       T pT pRp \        P                  ! V4      '       d~   \        V4      '       d5   \         P                  RV ,           4       \        V4       F	  pVx € RpK  	  \         P                  RV ,           4       \        P                  ! V4      pVx € EMXVf   \        V4      '       Ed   Vf#   \        V4      pVP                  4        F  pK  	  \         P                  RV ,           4       VP                  4        FÂ  w  rvp VP                  \        \        P                  4      4      p	T	\        P                  8X  dc   TP%                  ^ 4       \         P                  RT,           4        \        P                  ! T4      pTx € Te   TP-                  4        RpK¤  K¦  \         P                  RT,           4       KÄ  	  M)\         P)                  RP+                  V 4      4       Rx €  Ve   VP-                  4        R# R#   \          d&    \         P#                  RT ,           4       Rx €  EK7  i ; i  \&         d?    \         P)                  R	P+                  Y4      4       \         P                  R
RR7        L÷i ; i  Te   TP-                  4        Rpi i ; i  \.         d.    \         P#                  RP+                  T 4      RR7       Rx €  Lêi ; i  Te   TP-                  4        i i ; i5i)z try to open somehow as zip/ole/rtf/... ; yield None if fail

If data is given, filename is (mostly) ignored.

yields embedded ole streams in form of OleFileIO.
Nz*working on data, file is not touched belowzworking on file by namezis ppt file: zis ole file: zis zip file: zzip is encrypted: z  unzipping ole: z@Error reading data from {0}/{1} or interpreting it as OLE objectrE   Trº   zunzip skip: z5open failed: {0} (or its data) is neither zip nor OLEzCaught exception opening {0})r3   r   rÍ   rÂ   Ú	isOleFiler   r   rË   Ú	OleFileIOr   r	   Úiter_xmlÚiter_non_xmlr:   r‹   rÃ   ÚRuntimeErrorr   rï   ry   r   rT   rÄ   Ú	Exception)
rh   r<   Ú
xml_parserÚarg_for_oleÚarg_for_ziprÉ   ra   ÚsubfileÚfile_handleÚheads
   &&&       r   Úfind_oler  Õ  sº  é € ð Òô 	�	‰	Ð>Ô?ØˆÜ˜t“n‰ô 	�	‰	Ð+Ô,ØˆØˆà
€Cð:Ü×Ò˜[×)Ò)Ü�k×"Ò"Ü—‘˜¨8Õ3Ô4Ü*¨;Ö7�CØ’IØ’Cñ 8ô �H‰H�_ xÕ/Ô0Ü×#Ò# KÓ0ˆCØŒIØÒ#¤z°+×'>Ó'>ð Ò!Ü& {Ó3�
à#×,Ñ,Ö.�AÙñ /ô �H‰H�_ xÕ/Ô0ð ,6×+BÑ+BÖ+DÑ'�˜KðØ&×+Ñ+¬C´·±Ó,>Ó?�Dð œ7Ÿ=™=Ô(Ø×$Ñ$ QÔ'Ü—H‘HÐ0°7Õ:Ô;ð'Ü%×/Ò/°Ó<˜Ø!š	ð š?ØŸI™IœKØ"&šCñ +ô —I‘I˜n¨wÕ6Ö7ò1 ,Eô4 �K‰KÐOß™ Ó)ô+à‹Jð Š?Ø�I‰IŽKñ øô? $ô Ü—I‘IÐ2°XÕ=Ô>Ø’JÛðûô #ô 5ÜŸ™ð %Dç%+¡V¨HÓ%>ô@ô Ÿ	™	 "¨t˜	Ö4ð	5ûð š?ØŸI™IœKØ"&™Cð +ûô ô Ü�	‰	Ð0×7Ñ7¸ÓAØð 	ô 	!àŒ
ðûð
 Š?Ø�I‰I�Kð üs¬   ‚AL?ÁBK* ÃL% ÃA.K* Å(IÅ6AK* Æ9JÇ:K* ÈL% È(K* È6L% È7L?É+I?É:K* É>I?É?K* ÊAKËKË
KËKËK'Ë'K* Ë*5L"ÌL% Ì!L"Ì"L% Ì%L<Ì<L?c              #  óP  "  € V P                  RR\        4       Fn  w  rp VP                  R,          R8X  dP   VP                  R,          P                  R^4      ^,          pV\        9   d   W2P                  R,          3x € Kl  Kn  Kp  	  R#   \
        \        3 d     Kˆ  i ; i5i)zDiterate XML files looking for relationships to external objects
    NFÚ
TargetModeÚExternalÚTyper¦   ÚTarget)rø   ÚOOXML_RELATIONSHIP_TAGÚattribÚrsplitÚBLACKLISTED_RELATIONSHIP_TYPESÚAttributeErrorÚKeyError)rü   ra   ÚelemÚrelationship_types   &   r   Úfind_external_relationshipsr  '  s�   é € ð !×)Ñ)¨$°Ô7MÖN‰
ˆ�ð		Ø�{‰{˜<Õ(¨JÔ6Ø$(§K¡K°Õ$7×$>Ñ$>¸sÀAÓ$FÀqÕ$IÐ!à$Ô(FÔFØ+¯[©[¸Õ-BÐBÔBñ Gñ 7ó Oøô ¤Ð)ô 	ò ð	üs)   ‚B&¡A#BÂ
B&ÂB#ÂB&Â"B#Â#B&c              #  ó’   "  € V P                  RR\        \        34       F!  w  rpVP                  R4      pVf   K  Vx € K#  	  R# 5i)a\  
iterate XML files looking for customUI to external objects or VBA macros
Examples of malicious usage, to load an external document or trigger a VBA macro:
https://www.trellix.com/en-us/about/newsroom/stories/threat-labs/prime-ministers-office-compromised.html
https://www.netero1010-securitylab.com/evasion/execution-of-remote-vba-script-in-excel
NFÚonLoad)rø   ÚTAG_CUSTOMUI_2007ÚTAG_CUSTOMUI_2010Úget)rü   ra   r  Úcustomui_onloads   &   r   Úfind_customUIr  7  sF   é € ð !×)Ñ)¨$°Ô8IÔK\Ð7]Ö^‰
ˆ�ØŸ™ (Ó+€Ø
Ô
%Ø!Ô!ó _ùs
   ‚6A½
Ac                ó
  € \        V \        ^,
          R7      ;'       g    RpV'       dr   \        P                  P	                  V4      '       g-   \
        P                  RV4       \        P                  ! V4       \        P                  P                  W#4      pM>\        P                  P                  V 4      p\        P                  P                  WS4      p\        R4       \        RV ,          4       ^pRpRpRp	Rp
\        V 4      '       d”   \
        P                  R4       \        V 4      p
\        V
4       F>  w  r¼Rp	\        R	V: R
V: 24       VP                  R4      '       g   K3  \        R4       K@  	  \        V
4       F  pRp	\        RV,          4       K  	  \!        WV
4       EF¬  pVf   K
  VP#                  4        EF�  pRP                  V4      p\
        P%                  RV4       VR,          P'                  4       R8X  g   KI  Rp VP)                  V4      p\        RV,          4       \        R4       \+        V4      pTP2                  '       d   \
        P%                  R4       K®  \        RTP4                  ,          4       \        RTP6                  ,          4       \        RTP8                  ,          4       \;        TP4                  TP6                  TP8                  \        \=        T4      ,
          ^,
          T4       F:  pTR,           T,           p\        P                  P?                  T4      '       d   K:   M	   \        RX,          4       \A        TR4      ;_uu_ 4       p^ p\C        \D        TPF                  4      pT'       d—   TPI                  T4      pTPK                  T4       T\=        T4      ,          p\=        T4      T8w  d0   \
        P/                  RPM                  T\=        T4      4      4       M#\C        \D        TPF                  T,
          4      pKž  RRR4       Rp	TP1                  4        T^,          pEK�  	  EK¯  	  WxV	3#   \,         d1    \
        P/                  R4       RpTe   TP1                  4         EKÕ  i ; i  + '       g   i     Lw; i  \,         d2   p\
        P/                  RPM                  XT4      4       Rp Rp?L¯Rp?ii ; i  TP1                  4        i ; i)aE  find embedded objects in given file

if data is given (from xglob for encrypted zip files), then filename is
not used for reading. If not (usual case), then data is read from filename
on demand.

If output_dir is given and does not exist, it is created. If it is not
given, data is saved to same directory as the input file.
r¨   ÚNONAMEzcreating output directory %szFile: %rFNzJfile could be an OOXML file, looking for relationships with external linksTzFound relationship 'z' with external link zmhtml:z$Potential exploit for CVE-2021-40444zZFound customUI tag with external link or VBA macro %s (possibly exploiting CVE-2021-42292)r¦   zChecking stream %rzole10nativez3extract file embedded in OLE object from stream %r:zParsing OLE Packagez*** Not an OLE 1.0 Objectz0Object is not embedded but only linked to - skipzFilename = "%s"zSource path = "%s"zTemp path = "%s"ra   zsaving to file %sÚwbzWanted to read {0}, got {1}zerror dumping to {0} ({1})zO-------------------------------------------------------------------------------r�   )'r¤   ÚMAX_FILENAME_LENGTHrš   r›   Úisdirr3   r   Úmkdirr­   ÚdirnameÚprintr   r	   r  Ú
startswithr  r  Úlistdirr   ÚlowerÚ
openstreamrf   rû   r   rÄ   rp   rh   ri   rm   r¸   r‹   ÚisfileÚopenr°   ÚDUMP_CHUNK_SIZErn   r:   ÚwriterT   )rh   r<   Ú
output_dirr£   Úfname_prefixÚbase_dirr=   Ú
err_streamÚerr_dumpingÚdid_dumprü   Úrelationshiprá   rÉ   Ú
path_partsÚstream_pathrÇ   ÚopkgÚembedded_fnamer’   ÚwriterÚn_dumpedÚ	next_sizeÚexcs   &&&                     r   Úprocess_filer7  D  sñ  € ô # 8Ô5HÈÕ5JÔK÷ ð Øð çÜ�w‰w�}‰}˜Z×(Ò(Ü�H‰HÐ3°ZÔ@Ü�HŠH�ZÔ ä—w‘w—|‘| JÓ;‰ä—7‘7—?‘? 8Ó,ˆÜ—w‘w—|‘| HÓ9ˆô 
ˆ&„MÜ	ˆ*�xÕ
Ô Ø€Eð €JØ€KØ€Hà€JÜ�(×ÒÜ�‰ð "ô 	#ä˜xÓ(ˆ
Ü$?À
Ö$KÑ ˆLØˆHÝÃ\ÒSYÐZÔ[Ø× Ñ  ×*Ô*ÜÐ<Ö=ñ	 %Lô
 $ JÖ/ˆFØˆHÜÐnÐqwÕwÖxñ 0ô ˜¨
×3ˆØŠ;ÙàŸ+™+Ÿ-ˆJØŸ(™( :Ó.ˆKÜ�I‰IÐ*¨KÔ8Ø˜"�~×#Ñ#Ó%Ð):Ö:Ø�ðØ Ÿ^™^¨JÓ7�FÜÐOØ'õ(ô )äÐ/Ô0Ü*¨6Ó2�Dð —<—<�<Ü—I‘Ið 'ô (áÜÐ(¨4¯=©=Õ8Ô9ÜÐ+¨d¯m©mÕ;Ô<ÜÐ)¨D¯N©NÕ:Ô;Ü&AØŸ™ t§}¡}°d·n±nÜ+¬c°*«oÕ=ÀÕAÀ5ö'J�Nð )¨3Õ.°Õ?�EÜŸ7™7Ÿ>™>¨%×0Ô0Ùñ'Jð#ÜÐ-°Õ5Ô6Ü˜e T×*Ô*¨fØ#$˜Ü$'¬¸×9IÑ9IÓ$J˜	ß'Ø#)§;¡;¨yÓ#9˜DØ"ŸL™L¨Ô.Ø$¬¨D«	Õ1˜HÜ" 4›y¨IÔ5Ü #§¡Ð,Iß-3©V°I¼sÀ4»yÓ-Iô!Kà %Ü(+¬OØ,0×,<Ñ,<¸xÕ,Gó)IšI÷ +ð  $�Hð —L‘L”Nà˜•
“ôu (ñ	 4ð~  HÐ,Ð,øô_ !ô Ü—K‘KÐ ;Ô<Ø!%�JØÒ)ØŸ™œÛðú÷2 +×*ûô !ô 'Ü—K‘KÐ <ß!'¡¨¨sÓ!3ô5à"&•Kûð'ûð
 —L‘L•Nús[   È9Q&Í&R7Í:$R$	ÎBR$	Ð5
R7Ñ&6R!Ò R!Ò$R4Ò/R7Ò7S3Ó'S.Ó)S6Ó.S3Ó3S6Ó6Tc                óš   € \         P                  P                  V 4      '       g&   \        P                  ! RP                  V 4      4      hV # )z;called by argument parser to see whether given file exists z{0} is not a file.)rš   r›   r$  ÚargparseÚArgumentTypeErrorrT   )rh   s   &r   Úexisting_filer;  »  s7   € ä�7‰7�>‰>˜(×#Ò#Ü×(Ò(Ð)=×)DÑ)DÀXÓ)NÓOÐOØ€Or   c           	     ó8  € \        4        \        R\        ,          4       \        R4       \        R4       \        R4       Rp\        P                  ! VR7      pVP                  RRR	R
R7       VP                  R\        RRRR7       VP                  RRR\        RRR7       VP                  RRR\        RRR7       VP                  RRRR\        RR 7       VP                  R!R\        R"R#R$7       VP                  R%R&\        R"R'R(7       VP                  R)R*RR+R,7       VP                  V 4      pVP                  '       d%   V;P                  VP                  .,          un        VP                  '       d   R-Vn        VP                  '       g   VP                  4        \        # \         P"                  ! \$        VP                  ,          \&        P(                  R.R/7       \*        P-                  \         P.                  4       VP                  R08X  d   \0        P2                  ! 4        R1pR1pR1p\4        P6                  ! VP                  VP8                  VP:                  VP<                  R27       FX  w  rxp	V'       d   VP?                  R34      '       d   K'  \A        W‰VPB                  4      w  r«pWJ,          pW[,          pWl,          pKZ  	  \D        pV'       d   V\F        ,          pV'       d   V\H        ,          pV'       d   V\J        ,          pV# )4z–main function, called when running this as script

Per default (cmd_line_args=None) uses sys.argv. For testing, however, can
provide other arguments.
z)oleobj %s - http://decalage.info/oletoolsz3THIS IS WORK IN PROGRESS - Check updates regularly!zGPlease report any issue at https://github.com/decalage2/oletools/issuesrE   z4usage: %(prog)s [options] <filename> [filename2 ...])Úusagez-rÚ
store_trueÚ	recursivez)find files recursively in subdirectories.)ÚactionÚdestÚhelpz-dr(  Nz(use specified directory to output files.)ÚtyperA  ÚdefaultrB  z-zz--zipÚzip_passwordziif the file is a zip archive, open first file from it, using the provided password (requires Python 2.6+))rA  rC  rD  rB  z-fz
--zipfnameÚ	zip_fnameÚ*zoif the file is a zip archive, file(s) to be opened within the zip. Wildcards * and ? are supported. (default:*)z-lz
--loglevelÚloglevelÚstorezElogging level debug/info/warning/error/critical (default=%(default)s))rA  r@  rD  rB  ÚinputÚFILEz"Office files to parse (same as -i))ÚnargsrC  ÚmetavarrB  z-iz--more-inputz7Additional file to parse (same as positional arguments))rC  rM  rB  z-vz	--verbosez2verbose mode, set logging to DEBUG (overwrites -l))r@  rB  r   z%(levelname)-8s %(message)s)r.   rÇ   rT   r   F)r?  rE  rF  r¦   )&r
   r  Ú__version__r9  ÚArgumentParserÚadd_argumentr    ÚDEFAULT_LOG_LEVELr;  Ú
parse_argsÚ
more_inputrJ  ÚverboserH  Ú
print_helpÚRETURN_ERR_ARGSr&   ÚbasicConfigÚ
LOG_LEVELSÚsysÚstdoutr3   r+   r4   rÂ   r5   r   Ú
iter_filesr?  rE  rF  Úendswithr7  r(  ÚRETURN_NO_DUMPÚRETURN_DID_DUMPÚRETURN_ERR_STREAMÚRETURN_ERR_DUMP)Úcmd_line_argsr=  ÚparserÚoptionsÚany_err_streamÚany_err_dumpingÚany_did_dumpÚ	containerrh   r<   r+  r,  r-  Ú
return_vals   &             r   Úmainri  Â  sÚ  € ô "Ô#Ü	Ð
5¼Õ
CÔDÜ	Ð
?Ô@Ü	ð 9ô :ä	ˆ"„IàB€EÜ×$Ò$¨5Ô1€Fð
 ×Ñ˜ \¸ØHð ô Jà
×Ñ˜¤3¨\À4ØGð ô Ià
×Ñ˜˜g¨NÄØ $ð,ð ô -ð
 ×Ñ˜˜l°Ä3Ø #ð6ð ô 7ð
 ×Ñ˜˜l°ÀGÜ 1ð5ð ô 6ð ×Ñ˜ s´ÈØAð ô Cð ×Ñ˜˜n´3Àð*ð ô +ð ×Ñ˜˜k°,ð/ð ô 0ð ×Ñ Ó.€GØ××ÐØ�Š˜'×,Ñ,Ð/Õ/�Ø‡‡€Ø"ˆÔð �=�=ˆ=Ø×ÑÔÜÐô
 ×Òœj¨×)9Ñ)9Õ:Ä3Ç:Á:Ø<õ>ô ‡L�L”—‘Ô Ø×Ñ˜?Ô*Ü×ÒÔ ð €NØ€OØ€Lô ×Ò˜WŸ]™]°g×6GÑ6GØ*1×*>Ñ*>Ø'.×'8Ñ'8÷:ñ 	"ˆ	˜T÷
 ˜×*Ñ*¨3×/Ò/Ùä˜¨×);Ñ);Ó<ñ 	*ˆ
 àÕ$ˆØÕ&ˆØÕ Šñ:ô  €JßØ”oÕ%ˆ
ßØÔ'Õ'ˆ
ßØ”oÕ%ˆ
ØÐr   Ú__main__)ÚattachedTemplateÚexternalLinkÚexternalLinkPathÚexternalReferenceÚframeÚ	hyperlinkÚofficeDocumentÚ	oleObjectro   ÚslideUpdateUrlÚslideMasterÚslideÚslideUpdateInfoÚsubDocumentÚ	worksheetr   )Yr    Ú
__future__r   r&   rz   r9  rš   rž   rY  ré   Úzipfiler   r®   rÂ   r›   ÚnormpathÚabspathr  Ú__file__Ú_thismodule_dirr­   Ú_parent_dirÚinsertÚoletools.thirdpartyr   Úoletools.ppt_record_parserr   r   r   Úoletools.ooxmlr	   Úoletools.common.io_encodingr
   rN  rQ  ÚDEBUGÚINFOÚWARNINGÚERRORÚCRITICALrX  ÚHandlerr   r0   r3   r5   Úversion_inforF   r«   r\   r  r  r  ÚStructr8   rÑ   rB   r]   r&  r]  r^  rV  r_  r`  r  r  r¬   r?   rC   rJ   rX   rd   Úobjectrf   r�   r—   r¤   r¸   rË   Ú	RawIOBaserÍ   r  r  r  r7  r;  ri  r   Úexitr   r   r   Ú<module>r�     s£  ðñõT &ã Û Û Û 	Û 	Û 
Û 	Ý Û ã ð —'‘'×"Ñ" 2§7¡7§?¡?°2·7±7·?±?À8Ó3LÓ#MÓN€à�g‰g×Ñ˜rŸw™wŸ|™|¨O¸TÓBÓC€à�c—h‘hÔØ‡H�H‡O�O�A�{Ô#å %÷Fñ Få $Ý Eð& €ð( Ð Ø˜'Ÿ-™-Ø˜'Ÿ,™,Ø˜'Ÿ/™/Ø˜'Ÿ-™-Ø˜'×*Ñ*Ø˜wŸ}™}ð.€
ô	�'—/‘/ô 	ð #×+Ñ+¨AÕ-ô ñ8 �Ó€ò!ð ×Ñ�AÕ˜!Ôà�Ið €IØ€FàeÐ àTÐ ØTÐ ð
 —’˜dÓ#€Ø×Ñ˜QÔÐ Ðð —’˜dÓ#€Ø×Ñ˜QÔÐ Ðð €ð €ð €Ø€Ø€ØÐ Ø€ò"Ð ð& Ð ð Ð ò
ò"ò" ò82ò$>ô8S�fô SôlA:�ô A:òH4ð* -0Ø1ô1ò2<'ò~(ôVAˆr�|‰|ô AôHOòdò 
"ôq-ònô`ðF ˆzÔØ‡H‚H‰T‹VÖñ r   