From 5893d51ea1110b7933cfb846d64d78af89b23ffe Mon Sep 17 00:00:00 2001 From: Floogle <18466542+skyfloogle@users.noreply.github.com> Date: Sat, 13 Feb 2021 02:09:50 +0100 Subject: [PATCH] fixed crash when patching upx'd game if the path to gm8x_fix.exe has spaces (also 0.5.2 bump) --- gm8x_fix.c | 20 +++++++++++++++----- version.rc | 10 +++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gm8x_fix.c b/gm8x_fix.c index ed239a8..16e5d3c 100644 --- a/gm8x_fix.c +++ b/gm8x_fix.c @@ -181,7 +181,11 @@ static bool upx(FILE **fp, const char *fn, const char *argv0, bool make_backup) fclose(f); } // get upx path - char *cmd_buf = malloc((strlen(fn) + 5) * 4 + strlen(argv0)); + char *cmd_buf = calloc((strlen(fn) + 5) * 4 + strlen(argv0), 1); + // wrap entire thing in quotes on windows because system() on windows is `funky` +#ifdef _WIN32 + cmd_buf[0] = '"'; +#endif int path_len = strlen(argv0); while (path_len > 0 && argv0[path_len-1] != '/' #ifdef _WIN32 @@ -190,12 +194,15 @@ static bool upx(FILE **fp, const char *fn, const char *argv0, bool make_backup) ) { path_len--; } - cmd_buf[path_len] = 0; if (path_len > 0) { - strncpy(cmd_buf, argv0, path_len); + strcatfn(cmd_buf, argv0); } + cmd_buf[path_len+2] = 0; +#ifndef _WIN32 + cmd_buf[path_len+1] = 0; +#endif if (can_backup) { - strcat(cmd_buf, "upx -d -o "); + strcat(cmd_buf, "upx\" -d -o "); strcatfn(cmd_buf, fn); strcat(cmd_buf, " "); strcatfn(cmd_buf, bak_fn); @@ -203,6 +210,9 @@ static bool upx(FILE **fp, const char *fn, const char *argv0, bool make_backup) strcat(cmd_buf, "upx -d "); strcatfn(cmd_buf, fn); } +#ifdef _WIN32 + strcat(cmd_buf, "\""); +#endif int res = system(cmd_buf); if (res != 0) { printf("UPX unpack failed (error code %i).", res); @@ -278,7 +288,7 @@ int main(int argc, const char *argv[]) { valid_args = false; } // funny title - puts("Welcome to gm8x_fix v0.5.1!"); + puts("Welcome to gm8x_fix v0.5.2!"); puts("Source code is at https://github.com/skyfloogle/gm8x_fix under MIT license."); puts("---------------------------------------------------------------------------"); if (!offer_joystick && !offer_memory && !offer_dplay && !offer_scheduler && !offer_input_lag) { diff --git a/version.rc b/version.rc index 2787c2a..d490a2a 100644 --- a/version.rc +++ b/version.rc @@ -1,6 +1,6 @@ 1 VERSIONINFO -FILEVERSION 0,5,1,0 -PRODUCTVERSION 0,5,1,0 +FILEVERSION 0,5,2,0 +PRODUCTVERSION 0,5,2,0 BEGIN BLOCK "StringFileInfo" BEGIN @@ -8,12 +8,12 @@ BEGIN BEGIN VALUE "CompanyName", "Floogle @ https://github.com/skyfloogle" VALUE "FileDescription", "gm8x_fix" - VALUE "FileVersion", "0.5.1" + VALUE "FileVersion", "0.5.2" VALUE "InternalName", "gm8x_fix" VALUE "LegalCopyright", "" VALUE "OriginalFilename", "gm8x_fix.exe" - VALUE "ProductName", "gm8x_fix v0.5.1" - VALUE "ProductVersion", "0.5.1" + VALUE "ProductName", "gm8x_fix v0.5.2" + VALUE "ProductVersion", "0.5.2" END END