Skip to content

Commit d946da3

Browse files
author
Willi Ballenthin
committed
nodes, bp: use six for binary indexing. py2 support.
1 parent acd3648 commit d946da3

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

Evtx/BinaryParser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from datetime import datetime
2424
from functools import partial
2525

26+
import six
27+
2628

2729
class memoize(object):
2830
"""cache the return value of a method
@@ -557,7 +559,7 @@ def unpack_guid(self, offset):
557559
raise OverrunBufferException(o, len(self._buf))
558560

559561
# Yeah, this is ugly
560-
h = _bin
562+
h = [six.indexbytes(_bin, i) for i in range(len(_bin))]
561563
return """{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}""".format(
562564
h[3], h[2], h[1], h[0],
563565
h[5], h[4],

Evtx/Nodes.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import base64
2020
import itertools
2121

22+
import six
2223
import hexdump
2324

2425
from .BinaryParser import Block
@@ -1010,17 +1011,19 @@ def fast_substitutions(self):
10101011
val = self.unpack_dword(ofs + 8 + (4 * i))
10111012
value += "-{}".format(val)
10121013
sub_def.append(value)
1013-
#[20] = parse_hex32_type_node, -- Hex32TypeNoe, 0x14
1014+
#[20] = parse_hex32_type_node, -- Hex32TypeNode, 0x14
10141015
elif type_ == 0x14:
10151016
value = "0x"
1016-
for c in self.unpack_binary(ofs, size)[::-1]:
1017-
value += "{:02x}".format(c)
1017+
b = self.unpack_binary(ofs, size)[::-1]
1018+
for i in range(len(b) - 1):
1019+
value += '{:02x}'.format(six.indexbytes(b, i))
10181020
sub_def.append(value)
10191021
#[21] = parse_hex64_type_node, -- Hex64TypeNode, 0x15
10201022
elif type_ == 0x15:
10211023
value = "0x"
1022-
for c in bytes(self.unpack_binary(ofs, size)[::-1]):
1023-
value += "{:02x}".format(c)
1024+
b = self.unpack_binary(ofs, size)[::-1]
1025+
for i in range(len(b) - 1):
1026+
value += '{:02x}'.format(six.indexbytes(b, i))
10241027
sub_def.append(value)
10251028
#[33] = parse_bxml_type_node, -- BXmlTypeNode, 0x21
10261029
elif type_ == 0x21:

0 commit comments

Comments
 (0)