-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
182 additions
and
36 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
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 |
---|---|---|
@@ -1,14 +1,29 @@ | ||
# coding: utf-8 | ||
from typing import List, Literal, Optional | ||
from typing import Literal, Optional | ||
|
||
from ntfsdump.presenters.NtfsDumpPresenter import NtfsDumpPresenter | ||
|
||
def ntfsdump(imagefile_path: str, output_path: str, target_queries: List[str], volume_num: Optional[int] = None, file_type: Literal['raw', 'e01'] = 'raw'): | ||
|
||
def ntfsdump( | ||
imagefile_path: str, | ||
output_path: str, | ||
target_queries: list[str], | ||
volume_num: Optional[int] = None, | ||
file_type: Literal['raw', 'e01'] = 'raw' | ||
): | ||
"""A tool for extract any files from an NTFS volume on an image file. | ||
Args: | ||
imagefile_path (str): target image file path. | ||
output_path (str): output target file path, or output target directory path. | ||
target_queries (list[str]): query for extracted file paths. | ||
volume_num (Optional[int], optional): system volume number. Defaults to None. | ||
file_type (Literal['raw', 'e01'], optional): target image file format. Defaults to 'raw'. | ||
""" | ||
NtfsDumpPresenter().ntfsdump( | ||
imagefile_path=imagefile_path, | ||
output_path=output_path, | ||
target_queries=target_queries, | ||
volume_num=volume_num, | ||
file_type=file_type, | ||
imagefile_path, | ||
output_path, | ||
target_queries, | ||
volume_num, | ||
file_type, | ||
) |
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,77 @@ | ||
# coding: utf-8 | ||
from pathlib import Path | ||
from typing import Literal | ||
from traceback import format_exc | ||
from datetime import datetime | ||
|
||
from ntfsdump.models.MetaData import MetaData | ||
|
||
|
||
def get_datetime() -> datetime: | ||
return datetime.utcnow() | ||
|
||
def get_logfile_time(): | ||
if not MetaData.run_time: | ||
MetaData.run_time = get_datetime() | ||
return MetaData.run_time.strftime('%Y%m%d_%H%M%S_%f') | ||
|
||
|
||
class Log(object): | ||
def __init__( | ||
self, | ||
path: Path = Path('.', f"{MetaData.name}_{get_logfile_time()}.log"), | ||
): | ||
"""Logging class | ||
Args: | ||
path (Path, optional): path of log file. Defaults to Path('.', f"{MetaData.name}_{get_logfile_time()}.log"). | ||
is_quiet (bool, optional): flag to supress standard output. Defaults to False. | ||
""" | ||
self.path = path | ||
self.is_quiet = MetaData.quiet | ||
|
||
if not MetaData.nolog: | ||
self.__create_logfile() | ||
|
||
def __create_logfile(self): | ||
if not self.path.exists(): | ||
self.path.write_text(f"- {MetaData.name} v{MetaData.version} - \n") | ||
|
||
def __write_to_log(self, message: str): | ||
try: | ||
with self.path.open('a') as f: | ||
f.write(f"{get_datetime().isoformat()}: {message}\n") | ||
except Exception as e: | ||
self.print_danger(format_exc()) | ||
|
||
def print_info(self, message: str): | ||
"""print with cyan color | ||
Args: | ||
message (str): a message to be printed. | ||
""" | ||
print(f"\033[36m{message}\033[0m") | ||
|
||
def print_danger(self, message: str): | ||
"""print with red color | ||
Args: | ||
message (str): a message to be printed. | ||
""" | ||
print(f"\033[31m{message}\033[0m") | ||
|
||
def log(self, message: str, type: Literal['system', 'info', 'danger'] = 'system'): | ||
"""print and write message to logfile | ||
Args: | ||
message (str): a message to be logged. | ||
type (Literal['system', 'info', 'danger']): 'system ' is used only for logging. | ||
""" | ||
if not MetaData.nolog: | ||
self.__write_to_log(message) | ||
|
||
if not self.is_quiet: | ||
if type == 'info': | ||
self.print_info(message) | ||
elif type == 'danger': | ||
self.print_danger(message) |
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,12 @@ | ||
# coding: utf-8 | ||
from typing import Optional, Final | ||
from datetime import datetime | ||
from importlib.metadata import version | ||
|
||
|
||
class MetaData(object): | ||
name: Final[str] = 'ntfsdump' | ||
version: Final[str] = version(name) | ||
run_time: Optional[datetime] = None | ||
quiet: bool = True | ||
nolog: bool = True |
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
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
Oops, something went wrong.