Skip to content

Commit df8edf4

Browse files
author
William Ballenthin
committed
evtx: by default, don't parse chunks beyond those declared in header
this addresses issue #45 reported by @john-corcoran
1 parent 1ed29cf commit df8edf4

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

Evtx/Evtx.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
from __future__ import absolute_import
2121

2222
import re
23-
import binascii
23+
import sys
2424
import mmap
25-
from functools import wraps
25+
import binascii
2626
import logging
27+
from functools import wraps
2728

2829
import Evtx.Views as e_views
2930
from .Nodes import RootNode
@@ -218,16 +219,26 @@ def current_chunk(self):
218219
ofs += (self.current_chunk_number() * 0x10000)
219220
return ChunkHeader(self._buf, ofs)
220221

221-
def chunks(self):
222+
def chunks(self, include_inactive=False):
222223
"""
223224
@return A generator that yields the chunks of the log file
224225
starting with the first chunk, which is always found directly
225-
after the FileHeader, and continuing to the end of the file.
226+
after the FileHeader.
227+
228+
If `include_inactive` is set to true, enumerate chunks beyond those
229+
declared in the file header (and may therefore be corrupt).
226230
"""
231+
if include_inactive:
232+
chunk_count = sys.maxint
233+
else:
234+
chunk_count = self.chunk_count()
235+
236+
i = 0
227237
ofs = self._offset + self.header_chunk_size()
228-
while ofs + 0x10000 <= len(self._buf):
238+
while ofs + 0x10000 <= len(self._buf) and i < chunk_count:
229239
yield ChunkHeader(self._buf, ofs)
230240
ofs += 0x10000
241+
i += 1
231242

232243
def get_record(self, record_num):
233244
"""

0 commit comments

Comments
 (0)