Skip to content

Commit c9eaef0

Browse files
binary parser: correctly parse systemtime
also add tests thanks to @patatetom
1 parent 94970af commit c9eaef0

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

Evtx/BinaryParser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def dosdate(dosdate, dostime):
9898
minute = (t & 0b0000011111100000) >> 5
9999
hour = (t & 0b1111100000000000) >> 11
100100

101-
return datetime.datetime(year, month, day, hour, minute, sec)
101+
return datetime(year, month, day, hour, minute, sec)
102102
except:
103-
return datetime.datetime.min
103+
return datetime.min
104104

105105

106106
def parse_filetime(qword):
@@ -529,13 +529,13 @@ def unpack_systemtime(self, offset):
529529
"""
530530
o = self._offset + offset
531531
try:
532-
parts = struct.unpack_from("<WWWWWWWW", self._buf, o)
532+
parts = struct.unpack_from("<HHHHHHHH", self._buf, o)
533533
except struct.error:
534534
raise OverrunBufferException(o, len(self._buf))
535-
return datetime.datetime(parts[0], parts[1],
536-
parts[3], # skip part 2 (day of week)
537-
parts[4], parts[5],
538-
parts[6], parts[7])
535+
return datetime(parts[0], parts[1],
536+
parts[3], # skip part 2 (day of week)
537+
parts[4], parts[5],
538+
parts[6], parts[7])
539539

540540
def unpack_guid(self, offset):
541541
"""

tests/data/issue_39.evtx

1 MB
Binary file not shown.

tests/test_issue_39.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import pytest
3+
4+
import Evtx.Evtx as evtx
5+
6+
from fixtures import *
7+
8+
9+
10+
def one(iterable):
11+
'''
12+
fetch a single element from the given iterable.
13+
14+
Args:
15+
iterable (iterable): a sequence of things.
16+
17+
Returns:
18+
object: the first thing in the sequence.
19+
'''
20+
for i in iterable:
21+
return i
22+
23+
24+
def get_child(node, tag, ns="{http://schemas.microsoft.com/win/2004/08/events/event}"):
25+
return node.find("%s%s" % (ns, tag))
26+
27+
28+
def get_children(node, tags, ns="{http://schemas.microsoft.com/win/2004/08/events/event}"):
29+
for tag in tags:
30+
node = get_child(node, tag, ns=ns)
31+
return node
32+
33+
34+
def test_systemtime(data_path):
35+
'''
36+
regression test demonstrating issue 39.
37+
38+
Args:
39+
data_path (str): the file system path of the test directory.
40+
'''
41+
with evtx.Evtx(os.path.join(data_path, 'issue_39.evtx')) as log:
42+
for record in log.records():
43+
if record.record_num() != 129:
44+
continue
45+
46+
time_created = get_children(record.lxml(), ['System', 'TimeCreated'])
47+
assert time_created.get('SystemTime') == '2017-04-21 07:41:17.003393'
48+

0 commit comments

Comments
 (0)