Skip to content

Commit

Permalink
improved UPX support
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfloogle committed Dec 20, 2021
1 parent 875d10e commit 2fe1e5b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions gm8x_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,18 @@ static bool rename_for_backup(const char *fn, const char *bak_fn) {
// de-upx if necessary, return true if unpacked
static bool upx(FILE **fp, const char *fn, const char *argv0, bool make_backup) {
FILE *f = *fp;
// identify UPX headers
fseek(f, 0x170, SEEK_SET);
const char head1[] = {0x55, 0x50, 0x58, 0x30, 0, 0, 0, 0};
// identify UPX0 header
fseek(f, 0x3c, SEEK_SET);
int pe_pointer;
fread(&pe_pointer, 4, 1, f);
fseek(f, pe_pointer + 0x14, SEEK_SET);
short opt_len;
fread(&opt_len, 2, 1, f);
fseek(f, opt_len + 2, SEEK_CUR);
const char head1[] = "UPX0\0\0\0"; // 4th null is implicit
for (int i = 0; i < 8; i++) {
if (fgetc(f) != head1[i]) return false;
}
fseek(f, 0x198, SEEK_SET);
const char head2[] = {0x55, 0x50, 0x58, 0x31, 0, 0, 0, 0};
for (int i = 0; i < 8; i++) {
if (fgetc(f) != head2[i]) return false;
}
char *bak_fn = NULL;
bool can_backup = false;
if (make_backup) {
Expand Down

0 comments on commit 2fe1e5b

Please sign in to comment.