Skip to content

Commit

Permalink
Updates to the testing framework and the command line arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rowingdude committed Sep 4, 2024
1 parent 75f737c commit 4c12452
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 16 deletions.
6 changes: 2 additions & 4 deletions analyzeMFT.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import asyncio
import sys
import asyncio
from src.analyzeMFT.cli import main

if __name__ == "__main__":
if sys.platform == "win32":
# This sets the event loop policy to use the ProactorEventLoop on Windows
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
16 changes: 14 additions & 2 deletions src/analyzeMFT/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from .windows_time import WindowsTime
from .mft_record import MftRecord
from .mft_analyzer import MftAnalyzer
from .constants import VERSION
from .file_writers import FileWriters
from .constants import VERSION, CSV_HEADER
from .cli import main

__all__ = ['WindowsTime', 'MftRecord', 'MftAnalyzer', 'VERSION']
__all__ = [
'WindowsTime',
'MftRecord',
'MftAnalyzer',
'FileWriters',
'VERSION',
'CSV_HEADER',
'main'
]

__version__ = VERSION
27 changes: 23 additions & 4 deletions src/analyzeMFT/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,35 @@ async def main():

(options, args) = parser.parse_args()

if not options.filename or not options.output_file:
if not options.filename:
parser.print_help()
print("\nError: No input file specified. Use -f or --file to specify an MFT file.")
sys.exit(1)

if not options.output_file:
parser.print_help()
print("\nError: No output file specified. Use -o or --output to specify an output file.")
sys.exit(1)

if not options.export_format:
options.export_format = "csv" # Default to CSV if no format specified

analyzer = MftAnalyzer(options.filename, options.output_file, options.debug, options.compute_hashes, options.export_format)
await analyzer.analyze()
print(f"Analysis complete. Results written to {options.output_file}")
try:
analyzer = MftAnalyzer(options.filename, options.output_file, options.debug, options.compute_hashes, options.export_format)
await analyzer.analyze()
print(f"Analysis complete. Results written to {options.output_file}")
except FileNotFoundError:
print(f"Error: The file '{options.filename}' was not found.")
sys.exit(1)
except PermissionError:
print(f"Error: Permission denied when trying to read '{options.filename}' or write to '{options.output_file}'.")
sys.exit(1)
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
if options.debug:
import traceback
traceback.print_exc()
sys.exit(1)

if __name__ == "__main__":
asyncio.run(main())
2 changes: 1 addition & 1 deletion src/analyzeMFT/mft_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import zlib
from .constants import *
from .windows_time import WindowsTime
from typing import Dict, Set, List, Optional, Any
from typing import Dict, Set, List, Optional, Any,Union


class MftRecord:
Expand Down
Loading

0 comments on commit 4c12452

Please sign in to comment.