Skip to content

Commit

Permalink
Changed tools to entry points log2timeline#4769 (log2timeline#4811)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Feb 21, 2024
1 parent e1fbb6d commit 4a56b75
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 93 deletions.
14 changes: 7 additions & 7 deletions config/end-to-end.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source=test_data/vsstest.qcow2

[extract_and_output1]
case=extract_and_output
extract_options=--no-vss
extract_options=--vss_stores=none
output_file=extract_and_output1.log
output_format=dynamic
output_options=--dynamic-time
Expand All @@ -27,7 +27,7 @@ source=test_data/vsstest.qcow2

[extract_and_output2]
case=extract_and_output
extract_options=--no-vss
extract_options=--vss_stores=none
output_file=extract_and_output2.log
output_format=dynamic
output_options=--additional-fields=myfield --dynamic-time
Expand All @@ -36,7 +36,7 @@ source=test_data/vsstest.qcow2

[extract_and_output3]
case=extract_and_output
extract_options=--no-vss
extract_options=--vss_stores=none
output_file=extract_and_output3.log
output_format=dynamic
output_options=--custom-fields=custom:MyField --dynamic-time
Expand All @@ -45,7 +45,7 @@ source=test_data/vsstest.qcow2

[extract_and_output4]
case=extract_and_output_with_psteal
extract_options=--no-vss
extract_options=--vss_stores=none
output_file=extract_and_output4.log
output_format=dynamic
output_options=--dynamic-time
Expand All @@ -54,7 +54,7 @@ source=test_data/vsstest.qcow2

[extract_and_output5]
case=extract_and_output
extract_options=--no-vss
extract_options=--vss_stores=none
output_file=extract_and_output5.log
output_format=dynamic
output_options=--dynamic-time
Expand All @@ -64,7 +64,7 @@ source=test_data/vsstest.qcow2

[extract_and_output_empty]
case=extract_and_output
extract_options=--no-vss --parsers=bodyfile
extract_options=--parsers=bodyfile --vss_stores=none
output_file=extract_and_output_empty.log
output_format=dynamic
output_options=--dynamic-time
Expand All @@ -89,7 +89,7 @@ source=test_data/syslog.zip

[extract_and_output_no_hashers1]
case=extract_and_output
extract_options=--no-vss --hashers=none
extract_options=--hashers=none --vss_stores=none
output_file=extract_and_output_no_hashers1.log
output_format=dynamic
output_options=--dynamic-time
Expand Down
4 changes: 2 additions & 2 deletions config/end_to_end/run_tests_with_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ do
# Note that output is mapped to /home/test/plaso/plaso-out to ensure files
# created by the end-to-end.py script are stored outside the container.

COMMAND="./tests/end-to-end.py --config /config/${TEST_NAME}.ini --references-directory test_data/end_to_end --results-directory plaso-out --sources-directory /sources --tools-directory ./tools";
COMMAND="./tests/end-to-end.py --config /config/${TEST_NAME}.ini --references-directory test_data/end_to_end --results-directory plaso-out --sources-directory /sources --scripts-directory plaso/scripts";

# TODO: move custom test setup and teardown scripts to configuration parameter?

Expand All @@ -81,7 +81,7 @@ do

if [[ ${TEST_NAME} == "acserver-mounted" ]];
then
COMMAND="mkdir -p /mnt/acserver_mount && mount -o ro,noload,noacl,loop,offset=1048576 /sources/acserver.dd /mnt/acserver_mount && ./tests/end-to-end.py --config /config/${TEST_NAME}.ini --references-directory test_data/end_to_end --results-directory plaso-out --sources-directory /mnt --tools-directory ./tools && umount /mnt/acserver_mount && rmdir /mnt/acserver_mount";
COMMAND="mkdir -p /mnt/acserver_mount && mount -o ro,noload,noacl,loop,offset=1048576 /sources/acserver.dd /mnt/acserver_mount && ./tests/end-to-end.py --config /config/${TEST_NAME}.ini --references-directory test_data/end_to_end --results-directory plaso-out --sources-directory /mnt --scripts-directory plaso/scripts && umount /mnt/acserver_mount && rmdir /mnt/acserver_mount";

elif [[ ${TEST_NAME} == *\-nsrlsvr ]];
then
Expand Down
2 changes: 1 addition & 1 deletion config/jenkins/linux/run_end_to_end_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PYTHONPATH=. python3 ./utils/check_dependencies.py

# Start the end-to-end tests in the background so we can capture the PID of
# the process while the script is running.
PYTHONPATH=. python3 ./tests/end-to-end.py --config ${CONFIGURATION_FILE} --sources-directory ${SOURCES_DIRECTORY} --tools-directory ./tools --results-directory ${RESULTS_DIRECTORY} --references-directory ${REFERENCES_DIRECTORY} &
PYTHONPATH=. python3 ./tests/end-to-end.py --config ${CONFIGURATION_FILE} --sources-directory ${SOURCES_DIRECTORY} --scripts-directory plaso/scripts --results-directory ${RESULTS_DIRECTORY} --references-directory ${REFERENCES_DIRECTORY} &

PID_COMMAND=$!;

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/user/Log2Timeline-Perl-(Legacy).md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ none will be processed. You can abort with Ctrl^C.
```

The options can also be supplied on the command line, `--vss_stores '1,2'` for
defining the VSS stores to parse, or `--no-vss` or `-vss-stores all` for
processing all VSS stores.
defining the VSS stores to parse, or `--vss_stores=none` or `-vss-stores=all`
for respectively processing no or all VSS stores.

This can be achieved without calculating the offset into the disk image.

Expand Down
File renamed without changes.
27 changes: 12 additions & 15 deletions tools/image_export.py → plaso/scripts/image_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


def Main():
"""The main function.
"""Entry point of console script to extract files from images.
Returns:
bool: True if successful or False otherwise.
int: exit code that is provided to sys.exit().
"""
tool = image_export_tool.ImageExportTool()

if not tool.ParseArguments(sys.argv[1:]):
return False
return 1

if tool.show_troubleshooting:
print('Using Python version {0!s}'.format(sys.version))
Expand All @@ -34,12 +34,12 @@ def Main():

print('Also see: https://plaso.readthedocs.io/en/latest/sources/user/'
'Troubleshooting.html')
return True
return 0

try:
tool.CheckOutDated()
except KeyboardInterrupt:
return False
return 1

if tool.list_signature_identifiers:
try:
Expand All @@ -48,9 +48,9 @@ def Main():
# BadConfigOption will be raised if signatures.conf cannot be found.
except errors.BadConfigOption as exception:
logging.warning(exception)
return False
return 1

return True
return 0

if not tool.has_filters:
logging.warning('No filter defined exporting all files.')
Expand All @@ -68,28 +68,25 @@ def Main():

except (KeyboardInterrupt, errors.UserAbort):
logging.warning('Aborted by user.')
return False
return 1

except errors.BadConfigOption as exception:
logging.warning(exception)
return False
return 1

except errors.SourceScannerError as exception:
logging.warning((
'Unable to scan for a supported file system with error: {0!s}\n'
'Most likely the image format is not supported by the '
'tool.').format(exception))
return False
return 1

return True
return 0


if __name__ == '__main__':
# For PyInstaller sake we need to define this directly after "__main__".
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
multiprocessing.freeze_support()

if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
29 changes: 15 additions & 14 deletions tools/log2timeline.py → plaso/scripts/log2timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@


def Main():
"""The main function."""
"""Entry point of console script to extract events.
Returns:
int: exit code that is provided to sys.exit().
"""
tool = log2timeline_tool.Log2TimelineTool()

if not tool.ParseArguments(sys.argv[1:]):
return False
return 1

if tool.show_troubleshooting:
print('Using Python version {0!s}'.format(sys.version))
Expand All @@ -30,16 +34,16 @@ def Main():

print('Also see: https://plaso.readthedocs.io/en/latest/sources/user/'
'Troubleshooting.html')
return True
return 0

try:
tool.CheckOutDated()
except KeyboardInterrupt:
return False
return 1

if tool.show_info:
tool.ShowInfo()
return True
return 0

have_list_option = False
if tool.list_archive_types:
Expand Down Expand Up @@ -67,11 +71,11 @@ def Main():
have_list_option = True

if have_list_option:
return True
return 0

if tool.dependencies_check and not dependencies.CheckDependencies(
verbose_output=False):
return False
return 1

try:
tool.ExtractEventsFromSources()
Expand All @@ -83,24 +87,21 @@ def Main():

except (KeyboardInterrupt, errors.UserAbort):
logging.warning('Aborted by user.')
return False
return 1

except (IOError, errors.BadConfigOption,
errors.SourceScannerError) as exception:
# Display message on stdout as well as the log file.
print(exception)
logging.error(exception)
return False
return 1

return True
return 0


if __name__ == '__main__':
# For PyInstaller sake we need to define this directly after "__main__".
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
multiprocessing.freeze_support()

if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
28 changes: 16 additions & 12 deletions tools/pinfo.py → plaso/scripts/pinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@


def Main():
"""The main function."""
"""Entry point of console script to provide information about extracted data.
Returns:
int: exit code that is provided to sys.exit().
"""
tool = pinfo_tool.PinfoTool()

if not tool.ParseArguments(sys.argv[1:]):
return False
return 1

if tool.show_troubleshooting:
print('Using Python version {0!s}'.format(sys.version))
Expand All @@ -33,12 +37,12 @@ def Main():

print('Also see: https://plaso.readthedocs.io/en/latest/sources/user/'
'Troubleshooting.html')
return True
return 0

try:
tool.CheckOutDated()
except KeyboardInterrupt:
return False
return 1

have_list_option = False
if tool.list_reports:
Expand All @@ -50,7 +54,7 @@ def Main():
have_list_option = True

if have_list_option:
return True
return 0

result = True
try:
Expand All @@ -68,21 +72,21 @@ def Main():

except (KeyboardInterrupt, errors.UserAbort):
logging.warning('Aborted by user.')
return False
return 1

except errors.BadConfigOption as exception:
logging.warning(exception)
return False
return 1

if not result:
return 1

return result
return 0


if __name__ == '__main__':
# For PyInstaller sake we need to define this directly after "__main__".
# https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
multiprocessing.freeze_support()

if not Main():
sys.exit(1)
else:
sys.exit(0)
sys.exit(Main())
Loading

0 comments on commit 4a56b75

Please sign in to comment.