Skip to content

Commit 88e41ac

Browse files
committed
process xor: skips when key is zero, recognizes 1-byte case
1 parent 5dfb881 commit 88e41ac

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kaitaistruct.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,21 @@ def bytes_terminate(data, term, include_term):
335335

336336
@staticmethod
337337
def process_xor_one(data, key):
338+
if key == 0:
339+
return data
340+
338341
if PY2:
339342
return bytes(bytearray(v ^ key for v in bytearray(data)))
340343
else:
341344
return bytes(v ^ key for v in data)
342345

343346
@staticmethod
344347
def process_xor_many(data, key):
348+
if len(key) == 1:
349+
return KaitaiStream.process_xor_one(data, ord(key))
350+
if len(key) <= 64 and key == b'\x00' * len(key):
351+
return data
352+
345353
if PY2:
346354
return bytes(bytearray(a ^ b for a, b in zip(bytearray(data), itertools.cycle(bytearray(key)))))
347355
else:

0 commit comments

Comments
 (0)