Skip to content

Commit f0acd8a

Browse files
committed
Worked on fseventsd script
1 parent 2068104 commit f0acd8a

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

dtformats/fseventsd.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class FseventsFile(data_format.BinaryDataFile):
1313
# the dtFabric definition file.
1414
_FABRIC = data_format.BinaryDataFile.ReadDefinitionFile('fseventsd.yaml')
1515

16-
_DEBUG_INFO_DLS_PAGE_ENTRY = [
17-
('path', 'Path', '_FormatString'),
18-
('event_identifier', 'Event identifier', '_FormatIntegerAsDecimal'),
19-
('event_flags', 'Event flags', '_FormatIntegerAsHexadecimal'),
20-
('node_identifier', 'Node identifier', '_FormatIntegerAsDecimal')]
21-
2216
_DEBUG_INFO_DLS_PAGE_HEADER = [
2317
('signature', 'Signature', '_FormatStreamAsSignature'),
24-
('padding', 'Padding', '_FormatDataInHexadecimal'),
18+
('unknown1', 'Unknown1', '_FormatDataInHexadecimal'),
2519
('page_size', 'Page size', '_FormatIntegerAsDecimal')]
2620

21+
_DEBUG_INFO_DLS_RECORD = [
22+
('path', 'Path', '_FormatString'),
23+
('event_identifier', 'Event identifier', '_FormatIntegerAsDecimal'),
24+
('flags', 'Flags', '_FormatIntegerAsHexadecimal4'),
25+
('node_identifier', 'Node identifier', '_FormatIntegerAsDecimal')]
26+
2727
# The version 1 format was used in Mac OS X 10.5 (Leopard) through macOS 10.12
2828
# (Sierra).
2929
_DLS_V1_SIGNATURE = b'1SLD'
@@ -32,7 +32,7 @@ class FseventsFile(data_format.BinaryDataFile):
3232
_DLS_V2_SIGNATURE = b'2SLD'
3333

3434
def __init__(self, debug=False, output_writer=None):
35-
"""Initializes a Windows Restore Point rp.log file.
35+
"""Initializes a MacOS fseventsd file.
3636
3737
Args:
3838
debug (Optional[bool]): True if debug information should be written.
@@ -89,24 +89,23 @@ def _ReadDLSRecord(self, file_object, file_offset, format_version):
8989
format_version (int): format version.
9090
9191
Returns:
92-
int: number of bytes read.
92+
tuple[dls_record_v1|dls_record_v2, int]: record and number of bytes read.
9393
9494
Raises:
95-
ParseError: if the page entry cannot be read.
95+
ParseError: if the record cannot be read.
9696
"""
9797
if format_version == 1:
9898
data_type_map = self._GetDataTypeMap('dls_record_v1')
9999
elif format_version == 2:
100100
data_type_map = self._GetDataTypeMap('dls_record_v2')
101101

102-
dls_page_entry, bytes_read = self._ReadStructureFromFileObject(
102+
dls_record, bytes_read = self._ReadStructureFromFileObject(
103103
file_object, file_offset, data_type_map, 'DLS record')
104104

105105
if self._debug:
106-
self._DebugPrintStructureObject(
107-
dls_page_entry, self._DEBUG_INFO_DLS_PAGE_ENTRY)
106+
self._DebugPrintStructureObject(dls_record, self._DEBUG_INFO_DLS_RECORD)
108107

109-
return bytes_read
108+
return dls_record, bytes_read
110109

111110
def ReadFileObject(self, file_object):
112111
"""Reads a MacOS fseventsd file-like object.
@@ -139,7 +138,7 @@ def ReadFileObject(self, file_object):
139138
else:
140139
format_version = 0
141140

142-
bytes_read = self._ReadDLSRecord(
141+
_, bytes_read = self._ReadDLSRecord(
143142
gzipf_file, file_offset, format_version)
144143

145144
file_offset += bytes_read

tests/fseventsd.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ def testReadDLSPageHeaderV2(self):
4747
finally:
4848
gzipf_file.close()
4949

50+
def testReadDLSRecordV1(self):
51+
"""Tests the _ReadDLSRecord function on format version 1."""
52+
output_writer = test_lib.TestOutputWriter()
53+
test_file = fseventsd.FseventsFile(output_writer=output_writer)
54+
55+
test_file_path = self._GetTestFilePath(['fsevents-0000000002d89b58'])
56+
self._SkipIfPathNotExists(test_file_path)
57+
58+
gzipf_file = pygzipf.file()
59+
gzipf_file.open(test_file_path)
60+
61+
try:
62+
test_file._ReadDLSRecord(gzipf_file, 12, 1)
63+
finally:
64+
gzipf_file.close()
65+
66+
def testReadDLSRecordV2(self):
67+
"""Tests the _ReadDLSRecord function on format version 2."""
68+
output_writer = test_lib.TestOutputWriter()
69+
test_file = fseventsd.FseventsFile(output_writer=output_writer)
70+
71+
test_file_path = self._GetTestFilePath(['fsevents-00000000001a0b79'])
72+
self._SkipIfPathNotExists(test_file_path)
73+
74+
gzipf_file = pygzipf.file()
75+
gzipf_file.open(test_file_path)
76+
77+
try:
78+
test_file._ReadDLSRecord(gzipf_file, 12, 2)
79+
finally:
80+
gzipf_file.close()
81+
5082
def testReadFileObjectV1(self):
5183
"""Tests the ReadFileObject function on format version 1."""
5284
output_writer = test_lib.TestOutputWriter()

0 commit comments

Comments
 (0)