Use my_page_size, which is 0x4000 (16KiB) on arm64

https://github.com/upx/upx/issues/628
	modified:   p_mach.cpp
This commit is contained in:
John Reiser
2022-12-30 09:52:45 -08:00
committed by Markus F.X.J. Oberhumer
parent 01a30752c7
commit 77ba43328b
+5 -4
View File
@@ -1724,7 +1724,7 @@ int PackMachBase<T>::canUnpack()
} }
int const small = 32 + sizeof(overlay_offset); int const small = 32 + sizeof(overlay_offset);
unsigned bufsize = 4096 + sizeof(PackHeader); unsigned bufsize = my_page_size + sizeof(PackHeader) + sizeof(overlay_offset);
if (391 == style) { // PackHeader precedes __LINKEDIT if (391 == style) { // PackHeader precedes __LINKEDIT
fi->seek(offLINK - bufsize, SEEK_SET); fi->seek(offLINK - bufsize, SEEK_SET);
} else } else
@@ -1749,7 +1749,7 @@ int PackMachBase<T>::canUnpack()
// Do not overwrite buf[]; For scratch space, then use buf3 instead. // Do not overwrite buf[]; For scratch space, then use buf3 instead.
int i = bufsize; int i = bufsize;
while (i > small && 0 == buf[--i]) { } while (i > small && 0 == buf[--i]) { } // why is this search so slow?
i -= small; i -= small;
// allow incompressible extents // allow incompressible extents
if (i < 1 || !getPackHeader(buf + i, bufsize - i, true)) { if (i < 1 || !getPackHeader(buf + i, bufsize - i, true)) {
@@ -1761,7 +1761,7 @@ int PackMachBase<T>::canUnpack()
fi->readx(buf3, bufsize); fi->readx(buf3, bufsize);
unsigned char const *b = &buf3[0]; unsigned char const *b = &buf3[0];
unsigned disp = *(TE32 const *)&b[1]; unsigned disp = *(TE32 const *)&b[1];
// Emulate the code if (CPU_TYPE_X86_64 == my_cputype) { // Emulate the code
if (0xe8==b[0] && disp < bufsize if (0xe8==b[0] && disp < bufsize
// This has been obsoleted by amd64-darwin.macho-entry.S // This has been obsoleted by amd64-darwin.macho-entry.S
// searching for "executable_path=" etc. // searching for "executable_path=" etc.
@@ -1778,7 +1778,8 @@ int PackMachBase<T>::canUnpack()
if (overlay_offset < 0x1000) { if (overlay_offset < 0x1000) {
return true; // success return true; // success
} }
overlay_offset = 0; overlay_offset = 0; // failure
}
} }
} }
} }