From 1d35406ffee9890927efe693d79353446bea0734 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 2 Mar 2021 11:14:25 +0000 Subject: [PATCH] CLI: Improve file parameter handling --- volatility3/cli/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/volatility3/cli/__init__.py b/volatility3/cli/__init__.py index 019f28f16..9988022bc 100644 --- a/volatility3/cli/__init__.py +++ b/volatility3/cli/__init__.py @@ -16,9 +16,11 @@ import io import json import logging import os +import pathlib import sys import tempfile import traceback +import urllib from typing import Dict, Type, Union, Any from urllib import parse, request @@ -267,12 +269,14 @@ class CommandLine: # NOTE: This will *BREAK* if LayerStacker, or the automagic configuration system, changes at all ### if args.file: - file_name = os.path.abspath(args.file) - if not os.path.exists(file_name): - vollog.log(logging.INFO, "File does not exist: {}".format(file_name)) - else: - single_location = "file:" + request.pathname2url(file_name) - ctx.config['automagic.LayerStacker.single_location'] = single_location + # We want to work in URLs, but we need to accept absolute and relative files (including on windows) + single_location = urllib.parse.urlparse(args.file, 'file') + if single_location.scheme == 'file' or len(single_location.scheme) == 1: + # Otherwise construct a URL parameter + single_location = urllib.parse.urlparse(urllib.parse.urljoin('file:', request.pathname2url(os.path.abspath(args.file)))) + if not os.path.exists(single_location.path): + parser.error("File does not exist: {}".format(single_location.path)) + ctx.config['automagic.LayerStacker.single_location'] = urllib.parse.urlunparse(single_location) # UI fills in the config, here we load it from the config file and do it before we process the CL parameters if args.config: