diff --git a/README.md b/README.md index 2cb65c8..90090f2 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ wrappe --compression 16 dist dist/diogenes.exe packed.exe Run `wrappe` with an `input` directory, the `command` to launch and the `output` filename to create a single-binary executable. The input directory and all contained files and links will be packed. The command must be an executable file within the input directory that should be launched after unpacking. -If the packed executable needs to access files inside its working directory by relative path, use the `--current-dir` option to set the working directory to the unpack directory. The `WRAPPE_UNPACK_DIR` and `WRAPPE_LAUNCH_DIR` environment variables will always be set for the command allowing access to either location. +If the packed executable needs to access packed files by relative path and expects a certain working directory, use the [`--current-dir`](#current-dir) option to set it to its parent directory or the unpack directory. The `WRAPPE_UNPACK_DIR` and `WRAPPE_LAUNCH_DIR` environment variables will always be set for the command with the paths to the unpack directory and the inherited working directory. Packed Windows executables will have their subsystem, icons and other resources automatically transferred to the output executable through [editpe](https://github.com/Systemcluster/editpe). @@ -73,7 +73,7 @@ Options: -n, --console Show or attach to a console window (auto, always, never, attach) [default: auto] -w, --current-dir - Set the current working directory of the target to the unpack directory + Set the working directory of the command (inherit, unpack, runner, command) [default: inherit] -l, --list-runners Print available runners -h, --help @@ -155,7 +155,14 @@ It defaults to `auto`. This option currently only affects Windows runners, other #### current-dir -By default the working directory of the packed executable is set to the working directory of the runner executable. This flag changes the working directory to the unpack directory. +This option changes the working directory of the packed executable. Accepted values are: + +* `inherit`: The working directory will be inherited from the runner. This is usually the directory containing the runner or the directory from which the runner was launched. +* `unpack`: The working directory will be set to the unpack directory. This is the top-level directory of the unpacked payload. +* `runner`: The working directory will be set to the directory containing the runner, with all symbolic links resolved. +* `command`: The working directory will be set to the directory containing the unpacked executable. This will either be the unpack directory or a subdirectory within the unpacked payload. + +It defaults to `inherit`. ## Compilation diff --git a/src/args.rs b/src/args.rs index aa088a3..d0cfe00 100644 --- a/src/args.rs +++ b/src/args.rs @@ -205,6 +205,28 @@ pub fn get_show_console(show_console: &str, runner_name: &str) -> u8 { } } +pub fn get_current_dir(current_dir: &str) -> u8 { + match current_dir.to_lowercase().as_str() { + "inherit" => 0, + "unpack" => 1, + "runner" => 2, + "command" => 3, + _ => { + println!( + "{}: {}", + style("not a valid current directory option").red(), + style(current_dir).red(), + ); + println!( + "{}: inherit {}, directory, runner, command", + style("available current directory options").blue().bright(), + style("(default)").bold().dim() + ); + std::process::exit(-1); + } + } +} + pub fn get_source(source: &Path) -> PathBuf { let source = Path::new(&std::env::current_dir().unwrap()).join(source); let source = std::fs::canonicalize(&source).unwrap_or_else(|_| { diff --git a/src/main.rs b/src/main.rs index 8596933..e0c0ca2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,9 +53,9 @@ pub struct Args { /// Show or attach to a console window (auto, always, never, attach) #[arg(short = 'n', long, default_value = "auto")] console: String, - /// Set the current working directory of the target to the unpack directory - #[arg(short = 'w', long)] - current_dir: bool, + /// Set the working directory of the command (inherit, unpack, runner, command) + #[arg(short = 'w', long, default_value = "inherit")] + current_dir: String, /// Print available runners #[arg(short = 'l', long)] #[allow(dead_code)] @@ -97,6 +97,7 @@ fn main() { let verification = get_verification(&args.verification); let show_information = get_show_information(&args.show_information); let arguments = get_arguments(&args.arguments); + let current_dir = get_current_dir(&args.current_dir); let mut show_console = get_show_console(&args.console, runner_name); @@ -285,7 +286,7 @@ fn main() { let info = StarterInfo { signature: [0x50, 0x45, 0x33, 0x44, 0x41, 0x54, 0x41, 0x00], show_console, - current_dir: args.current_dir.into(), + current_dir, verification, show_information, uid: version.as_bytes().try_into().unwrap(), diff --git a/startpe/src/main.rs b/startpe/src/main.rs index cd2edcb..0aa42c8 100644 --- a/startpe/src/main.rs +++ b/startpe/src/main.rs @@ -214,10 +214,12 @@ fn main() { } let launch_dir = std::env::current_dir().unwrap(); - let current_dir = if info.current_dir == 1 { - &unpack_dir - } else { - &launch_dir + let current_dir = match info.current_dir { + 0 => &launch_dir, + 1 => &unpack_dir, + 2 => exe.parent().unwrap(), + 3 => run_path.parent().unwrap(), + _ => panic!("invalid current directory"), }; if show_information >= 2 { println!("current dir: {}", current_dir.display());