|iy6dZdZddlZddlZejejejeZ ejej e dZ e ejvrej de ddl Z ejddkreZdZndZdZd Zd d ed DZddZddZddZdZedkr edSdS)a ezhexviewer.py A simple hexadecimal viewer based on easygui. It should work on any platform with Python 2.x or 3.x. Usage: ezhexviewer.py [file] Usage in a python application: import ezhexviewer ezhexviewer.hexview_file(filename) ezhexviewer.hexview_data(data) ezhexviewer project website: http://www.decalage.info/python/ezhexviewer ezhexviewer is copyright (c) 2012-2019, Philippe Lagadec (http://www.decalage.info) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. z0.54Nz..TFcNt|tr|St|S)a{ workaround for ord() to work on characters from a bytes string with Python 2 and 3. If s is a bytes string, s[i] is a bytes string of length 1 on Python 2, but it is an integer on Python 3... xord(c) returns ord(c) if c is a bytes string, or c if it is already an integer. :param char: int or bytes of length 1 :return: ord(c) if bytes, c if int ) isinstanceintord)chars BC:\PYTHON\_runtimes\venv\Lib\site-packages\oletools/ezhexviewer.pyxordr Ws'$ 4yycNtrt|gSt|S)a! workaround for chr() to return a bytes string of length 1 with Python 2 and 3. On Python 3, chr returns a unicode string, but on Python 2 it is a bytes string. bchr() always returns a bytes string on Python 2+3. :param x: int :return: chr(x) as a bytes string )PYTHON3byteschr)xs r bchrrfs'aSzz1vv r r c g|]F}ttt|dkr|dkrt|pdGS) .)lenreprr.0rs r r~sJ___qCT!WW &&)5agB477Jd___r czg}tdt||D]}||||z}dd|D}|t}t r|d}|d||z|dz||fzd|S)z Returns a hexadecimal dump of a binary string. length: number of bytes per row. startindex: index of 1st byte. r c2g|]}dt|zS)z%02X)r rs r rzhexdump3..s#555a$q'')555r latin1z%08X %-*s %s r)xrangerjoin translateFILTERr decodeappend)srclength startindexresultishexa printables r hexdump3r0s F As3xx ( (XX !F( Oxx55155566KK''  3!((22I *a lF1HdI-VVWWWW 776??r r! ezhexviewercXt|||}tj|||dS)N)r)r*)msgtitletext)r0easyguicodebox)datar4r5r)r*hexs r hexview_datar;s3 4: > > >C O5s333333r crt|d}t|||||dS)Nrb)r4r5r)r*)openreadr;)filenamer4r5r)r*r9s r hexview_filerAs< $   $ $ & &D3eFzRRRRRRr c tjd}n#tj}YnxYw|r5 t |d|zdS#tjddYdSxYwdS)NzFile: %s)r4zError:r1)r4r5)sysargvr7 fileopenboxrA exceptionbox)r@s r mainrHs)8A;)&((D D zH'< = = = = = = D  X] C C C C C C C DDs,AA#__main__)rr)r!r1r2r)__doc__ __version__rDospathnormpathabspathdirname__file___thismodule_dirr# _parent_dirinsertr7 version_inforanger"r r rr%r0r;rArH__name__r r rYs''f '""27??27??83L3L#M#MNNgrw||OTBBCC chHOOA{###A!FGGG   0 __TYTYZ]T^T^___ ` `,4444 SSSS D D D zDFFFFFr