Skip to content

Commit

Permalink
fixed crash when patching upx'd game if the path to gm8x_fix.exe has …
Browse files Browse the repository at this point in the history
…spaces (also 0.5.2 bump)
  • Loading branch information
skyfloogle committed Feb 13, 2021
1 parent fb05eeb commit 5893d51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 15 additions & 5 deletions gm8x_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -190,19 +194,25 @@ 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);
} else {
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);
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions version.rc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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
BLOCK "040904E4"
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

Expand Down

0 comments on commit 5893d51

Please # to comment.