Skip to content

Commit a2f0c5a

Browse files
committed
process xor: skips when key is zero, recognizes 1-byte case
1 parent 452e843 commit a2f0c5a

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
@@ -336,13 +336,21 @@ def bytes_terminate(data, term, include_term):
336336

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

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

0 commit comments

Comments
 (0)