Task File Handlers
In order to handle uploaded scan files and prepare them for static file
analysis, TaskFileHandler
objects are used. Once created, they
will be registered in a gobal registry and can be retrieved via
TaskFileHandler.from_scan(...)
.
APK Files
To use the apk_handler
function, simply import it and call it with the source
path, destination directory, and any required application settings. Optional arguments
can be passed through the kwargs
parameter, including the observer
argument
for progress tracking. For example:
1from mastf.core.files import TaskFileHandler
2from mastf.MASTF import settings
3
4src_path = "/path/to/my/app.apk"
5dest_dir = "/path/to/output/directory"
6apk_handler = TaskFileHandler.from_scan(src_path, "android")
7if apk_handler:
8 apk_handler.apply(src_path, dest_dir, settings, observer=task_observer)
The apk_handler
function processes the specified APK file using the settings provided, then
saves the output files to the dest_dir
. The function may also perform progress tracking if
an observer object is provided.
Note that the extension and scan_type parameters for TaskFileHandler
specify that this
function should only be used for files with the .apk
extension and for Android scans.
IPA Files
Import the ipa_handler
function or get the instance via the following code:
handler = TaskFileHandler.from_scan("path/to/file.ipa", "ios")
- class mastf.core.files.handler.TaskFileHandler(extension: str, scan_type: str = None, private=False)[source]
A class that provides file handling functionality for tasks.
To use the
TaskFileHandler
class as a decorator on functions or classes, you can create an instance of the class with the desired file extension and scan type (if applicable), and then apply it to the target function or class using the@
syntax. Here is an example of how this might look:task_file_handler = TaskFileHandler(r".*\.txt") @task_file_handler def process_text_files(src_path: str, dest_dir: str, settings): # function body
In the above example, the process_text_files function is decorated with an instance of the
TaskFileHandler
class that has been configured to look for files with a.txt
extension in any scan. Whenprocess_text_files
is called, the file handling logic provided by theTaskFileHandler
instance will be applied to the specified source and destination paths.- Parameters:
extension (str) – The file extension to look for.
scan_type (str, optional) – The type of scan to perform (e.g. ‘android’ or ‘ios’). Defaults to None.
private (bool) – Tells the object whether it should be added to the global handler list
- apply(src_path: Path, dest_dir: Path, settings, **kwargs) None [source]
Applies the file handling logic to the specified source and destination paths.
- Parameters:
src_path (pathlib.Path) – The path to the source directory or file.
dest_dir (pathlib.Path) – The path to the destination directory.
settings – The settings object for the task.
kwargs (dict) – Additional keyword arguments.
- Returns:
None
- static from_scan(name: str, scan_type: str = None) TaskFileHandler [source]
Returns the TaskFileHandler instance from the specified file name and scan type.
- Parameters:
file_name (str) – The name of the file to look for.
scan_type (str) – The type of scan to perform (e.g. ‘android’ or ‘ios’).
- Returns:
A new TaskFileHandler instance.
- Return type: