-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worked on script to parse WEVT_TEMPLATE
- Loading branch information
1 parent
5886f31
commit e2c9bff
Showing
5 changed files
with
762 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the dfVFS helpers.""" | ||
|
||
import pathlib | ||
import os | ||
import unittest | ||
|
||
from dfvfs.lib import definitions as dfvfs_definitions | ||
from dfvfs.path import factory as path_spec_factory | ||
|
||
from winevtrc import dfvfs_helpers | ||
|
||
from tests import test_lib | ||
|
||
|
||
class DFVFSFileSystemHelperTest(test_lib.BaseTestCase): | ||
"""dfVFS file system helper tests.""" | ||
|
||
def testBasenamePath(self): | ||
"""Tests the BasenamePath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
basename = test_helper.BasenamePath(test_file_path) | ||
self.assertEqual(basename, 'utmp-linux_libc6') | ||
|
||
def testCheckFileExistsByPath(self): | ||
"""Tests the CheckFileExistsByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
result = test_helper.CheckFileExistsByPath(test_file_path) | ||
self.assertTrue(result) | ||
|
||
def testDirnamePath(self): | ||
"""Tests the DirnamePath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
dirname = test_helper.DirnamePath(test_file_path) | ||
self.assertEqual(dirname, test_lib.TEST_DATA_PATH) | ||
|
||
def testGetFileSizeByPath(self): | ||
"""Tests the GetFileSizeByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
file_size = test_helper.GetFileSizeByPath(test_file_path) | ||
self.assertEqual(file_size, 5376) | ||
|
||
def testJoinPath(self): | ||
"""Tests the JoinPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
path_segments = os.path.split(test_file_path) | ||
|
||
path = test_helper.JoinPath(path_segments) | ||
self.assertEqual(path, test_file_path) | ||
|
||
def testListDirectory(self): | ||
"""Tests the ListDirectory function.""" | ||
test_file_path = self._GetTestFilePath(['unified_logging']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
expected_directory_entries = [ | ||
'0000000000000030.tracev3', | ||
'0000000000000f85.tracev3', | ||
'timesync', | ||
'uuidtext'] | ||
|
||
directory_entries = sorted(test_helper.ListDirectory(test_file_path)) | ||
self.assertEqual(directory_entries, expected_directory_entries) | ||
|
||
def testOpenFileByPath(self): | ||
"""Tests the OpenFileByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
file_object = test_helper.OpenFileByPath(test_file_path) | ||
self.assertIsNotNone(file_object) | ||
|
||
file_object.close() | ||
|
||
def testSplitPath(self): | ||
"""Tests the SplitPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = dfvfs_helpers.DFVFSFileSystemHelper(None) | ||
|
||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) | ||
test_helper.OpenFileSystem(path_spec) | ||
|
||
expected_path_segments = list(pathlib.Path(test_file_path).parts) | ||
expected_path_segments.pop(0) | ||
|
||
path_segments = test_helper.SplitPath(test_file_path) | ||
self.assertEqual(path_segments, expected_path_segments) | ||
|
||
|
||
# TODO: add test for SetDFVFSBackEnd | ||
# TODO: add test for AddDFVFSCLIArguments | ||
# TODO: add test for ParseDFVFSCLIArguments | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the file system helper.""" | ||
|
||
import pathlib | ||
import platform | ||
import unittest | ||
|
||
from winevtrc import file_system | ||
|
||
from tests import test_lib | ||
|
||
|
||
class NativeFileSystemHelperTest(test_lib.BaseTestCase): | ||
"""Python native system helper tests.""" | ||
|
||
def testBasenamePath(self): | ||
"""Tests the BasenamePath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
basename = test_helper.BasenamePath(test_file_path) | ||
self.assertEqual(basename, 'utmp-linux_libc6') | ||
|
||
def testCheckFileExistsByPath(self): | ||
"""Tests the CheckFileExistsByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
result = test_helper.CheckFileExistsByPath(test_file_path) | ||
self.assertTrue(result) | ||
|
||
def testDirnamePath(self): | ||
"""Tests the DirnamePath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
dirname = test_helper.DirnamePath(test_file_path) | ||
self.assertEqual(dirname, test_lib.TEST_DATA_PATH) | ||
|
||
def testGetFileSizeByPath(self): | ||
"""Tests the GetFileSizeByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
file_size = test_helper.GetFileSizeByPath(test_file_path) | ||
self.assertEqual(file_size, 5376) | ||
|
||
def testJoinPath(self): | ||
"""Tests the JoinPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
path_segments = list(pathlib.Path(test_file_path).parts) | ||
path_segments.pop(0) | ||
|
||
if platform.system() == 'Windows': | ||
expected_path = test_file_path[2:] | ||
else: | ||
expected_path = test_file_path | ||
|
||
path = test_helper.JoinPath(path_segments) | ||
self.assertEqual(path, expected_path) | ||
|
||
def testListDirectory(self): | ||
"""Tests the ListDirectory function.""" | ||
test_file_path = self._GetTestFilePath(['unified_logging']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
expected_directory_entries = [ | ||
'0000000000000030.tracev3', | ||
'0000000000000f85.tracev3', | ||
'timesync', | ||
'uuidtext'] | ||
|
||
directory_entries = sorted(test_helper.ListDirectory(test_file_path)) | ||
self.assertEqual(directory_entries, expected_directory_entries) | ||
|
||
def testOpenFileByPath(self): | ||
"""Tests the OpenFileByPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
file_object = test_helper.OpenFileByPath(test_file_path) | ||
self.assertIsNotNone(file_object) | ||
|
||
file_object.close() | ||
|
||
def testSplitPath(self): | ||
"""Tests the SplitPath function.""" | ||
test_file_path = self._GetTestFilePath(['utmp-linux_libc6']) | ||
self._SkipIfPathNotExists(test_file_path) | ||
|
||
test_helper = file_system.NativeFileSystemHelper() | ||
|
||
expected_path_segments = list(pathlib.Path(test_file_path).parts) | ||
expected_path_segments.pop(0) | ||
|
||
path_segments = test_helper.SplitPath(test_file_path) | ||
if platform.system() == 'Windows': | ||
path_segments.pop(0) | ||
|
||
self.assertEqual(path_segments, expected_path_segments) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.