Skip to content

Commit

Permalink
20220905a
Browse files Browse the repository at this point in the history
  • Loading branch information
DidierStevens committed Sep 5, 2022
1 parent 664178d commit e48e5c6
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 71 deletions.
23 changes: 20 additions & 3 deletions hex-to-bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

__description__ = 'Hex to bin'
__author__ = 'Didier Stevens'
__version__ = '0.0.5'
__date__ = '2020/04/16'
__version__ = '0.0.6'
__date__ = '2022/09/04'

"""
Expand All @@ -22,6 +22,7 @@
2020/02/05: 0.0.4 added --bitstream
2020/04/15: 0.0.5 added option --hexonly
2020/04/16: added option --upperonly and --loweronly
2022/09/04: 0.0.6 added error handling for non-hexadecimal digits
Todo:
Get rid of Python2/Python3 conversion kludge
Expand Down Expand Up @@ -277,7 +278,23 @@ def Hex2Bin(filename, options):
if options.bitstream:
data = DecodeBitstream(y)
else:
data = binascii.unhexlify(y)
try:
data = binascii.unhexlify(y)
except binascii.Error:
print('The following non-hexadecimal digits were found:')
dHexadecimal = {}
for i in range(0x30, 0x3A):
dHexadecimal[i] = True
for i in range(0x41, 0x47):
dHexadecimal[i] = True
for i in range(0x61, 0x67):
dHexadecimal[i] = True
for value in y:
if value in dHexadecimal:
continue
dHexadecimal[value] = False
print('%s 0x%02x' % (repr(chr(value)), value))
raise
StdoutWriteChunked(data)

def Main():
Expand Down
5 changes: 3 additions & 2 deletions oledump.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

__description__ = 'Analyze OLE files (Compound Binary Files)'
__author__ = 'Didier Stevens'
__version__ = '0.0.69'
__date__ = '2022/07/22'
__version__ = '0.0.70'
__date__ = '2022/09/04'

"""
Expand Down Expand Up @@ -118,6 +118,7 @@
2022/05/11: 0.0.67 added PrintUserdefinedProperties
2022/06/07: 0.0.68 added extra info parameters %CTIME% %MTIME% %CTIMEHEX% %MTIMEHEX%
2022/07/22: 0.0.69 minor documentation change
2022/09/04: 0.0.70 bumping version for update to plugin(s), no changes to oledump.py
Todo:
Expand Down
23 changes: 20 additions & 3 deletions translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

__description__ = 'Translate bytes according to a Python expression'
__author__ = 'Didier Stevens'
__version__ = '2.5.11'
__date__ = '2020/12/20'
__version__ = '2.5.12'
__date__ = '2022/09/04'

"""
Expand Down Expand Up @@ -45,6 +45,7 @@
2020/11/04: 2.5.10 Python 3 fix
2020/12/08: 2.5.11 Bug fix
2020/12/20: added shl and shr
2022/09/04: 2.5.12 updated Xor
Todo:
"""
Expand Down Expand Up @@ -221,7 +222,23 @@ def ZlibD(data):
def ZlibRawD(data):
return zlib.decompress(data, -8)

def Xor(data, key):
def Xor(data, key, hexadecimal=False, rotation=0):
if hexadecimal:
key = binascii.a2b_hex(key.replace(' ', '').encode())
if rotation != 0:
if rotation in ['c', 'cr']:
if rotation == 'c':
position = data.find(key)
else:
position = data.rfind(key)
if position == -1:
raise Exception('Xor rotation argument calculate: key not found in data')
rotation = position % len(key)
if rotation != 0:
rotation = len(key) - rotation
elif rotation >= len(key):
raise Exception('Xor rotation argument is too large (compared to key size)')
key = key[rotation:] + key[:rotation]
if sys.version_info[0] > 2:
return bytes([byte ^ key[index % len(key)] for index, byte in enumerate(data)])
else:
Expand Down
Loading

0 comments on commit e48e5c6

Please sign in to comment.