Skip to content

Commit a26a68c

Browse files
author
Willi Ballenthin
committed
binary parser: parsing binary gets bytes
1 parent a35ba5d commit a26a68c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

Evtx/BinaryParser.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def unpack_binary(self, offset, length=False):
508508
return ""
509509
o = self._offset + offset
510510
try:
511-
return struct.unpack_from("<{}s".format(length), self._buf, o)[0]
511+
return bytes(struct.unpack_from("<{}s".format(length), self._buf, o)[0])
512512
except struct.error:
513513
raise OverrunBufferException(o, len(self._buf))
514514

@@ -521,7 +521,7 @@ def unpack_string(self, offset, length):
521521
Throws:
522522
- `OverrunBufferException`
523523
"""
524-
return self.unpack_binary(offset, length)
524+
return self.unpack_binary(offset, length).decode('ascii')
525525

526526
def unpack_wstring(self, offset, length):
527527
"""
@@ -534,11 +534,14 @@ def unpack_wstring(self, offset, length):
534534
- `UnicodeDecodeError`
535535
"""
536536
try:
537-
return self._buf[self._offset + offset:self._offset + offset + \
538-
2 * length].tostring().decode("utf16")
537+
return bytes(self._buf[self._offset + offset:self._offset + offset + \
538+
2 * length]).decode("utf16")
539539
except AttributeError: # already a 'str' ?
540-
return self._buf[self._offset + offset:self._offset + offset + \
541-
2 * length].decode("utf16")
540+
return bytes(self._buf[self._offset + offset:self._offset + offset + \
541+
2 * length]).decode("utf16")
542+
except:
543+
from IPython import embed; embed()
544+
import sys; sys.exit()
542545

543546
def unpack_dosdate(self, offset):
544547
"""

Evtx/Views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def rec(root_node):
143143
f = _make_template_xml_view(root_node, cache=cache)
144144
subs_strs = []
145145
for sub in root_node.fast_substitutions():
146-
if isinstance(sub, basestring):
146+
if isinstance(sub, str):
147147
subs_strs.append((xml_sax_escape(sub, {'"': "&quot;"})).encode("ascii", "xmlcharrefreplace"))
148148
elif isinstance(sub, RootNode):
149149
subs_strs.append(rec(sub))

0 commit comments

Comments
 (0)