Use a less common flag for ape

We choose 0x101ca75, "lol cat 5".

Also makes the argc check more explicit and moves the flags to their own
section.
This commit is contained in:
Jōshin 2024-05-07 15:45:32 -07:00
parent 76b1051b64
commit 2ab7e30352
No known key found for this signature in database
4 changed files with 12 additions and 7 deletions

View file

@ -124,7 +124,6 @@ struct Syslib {
#define PT_INTERP 3
#define EI_CLASS 4
#define EI_DATA 5
#define EF_APE_MODERN 1
#define PF_X 1
#define PF_W 2
#define PF_R 4
@ -147,6 +146,9 @@ struct Syslib {
#define AT_RANDOM 25
#define AT_EXECFN 31
#define EF_APE_MODERN 0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff
#define AUXV_WORDS 31
/* from the xnu codebase */
@ -821,7 +823,7 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
if (e->e_machine != EM_AARCH64) {
return "couldn't find ELF header with ARM64 machine type";
}
if (!(e->e_flags & EF_APE_MODERN) && sp[0]) {
if ((e->e_flags & EF_APE_MODERN_MASK) != EF_APE_MODERN && sp[0] > 0) {
/* change argv[0] to resolved path for older binaries */
((char **)(sp + 1))[0] = exe;
}

View file

@ -196,7 +196,7 @@ ape_mz:
.quad ape_elf_entry // 18: e_entry
.quad ape_elf_phoff // 20: e_phoff
.quad ape_elf_shoff // 28: e_shoff
.long 1 // 30: e_flags
.long 0x101ca75 // 30: ape e_flags
.short 64 // 34: e_ehsize
.short 56 // 36: e_phentsize
.short ape_elf_phnum // 38: e_phnum
@ -669,7 +669,7 @@ apesh: .ascii "\n@\n#'\"\n" // sixth edition shebang
.shstub ape_elf_entry,8 // 18: e_entry
.shstub ape_elf_phoff,8 // 20: e_phoff
.shstub ape_elf_shoff,8 // 28: e_shoff
.ascii "\\1\\0\\0\\0" // 30: e_flags
.ascii "\\165\\312\\1\\1" // 30: ape e_flags
.ascii "\\100\\0" // 34: e_ehsize
.ascii "\\070\\0" // 36: e_phentsize
.shstub ape_elf_phnum,2 // 38: e_phnum

View file

@ -134,7 +134,6 @@
#define PT_INTERP 3
#define EI_CLASS 4
#define EI_DATA 5
#define EF_APE_MODERN 1
#define PF_X 1
#define PF_W 2
#define PF_R 4
@ -153,6 +152,9 @@
#define PR_SET_MM 35
#define PR_SET_MM_EXE_FILE 13
#define EF_APE_MODERN 0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff
#define READ32(S) \
((unsigned)(255 & (S)[3]) << 030 | (unsigned)(255 & (S)[2]) << 020 | \
(unsigned)(255 & (S)[1]) << 010 | (unsigned)(255 & (S)[0]) << 000)
@ -835,7 +837,7 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
return "couldn't find ELF header with x86-64 machine type";
}
#endif
if (!(e->e_flags & EF_APE_MODERN) && sp[0]) {
if ((e->e_flags & EF_APE_MODERN_MASK) != EF_APE_MODERN && sp[0] > 0) {
/* change argv[0] to resolved path for older binaries */
((char **)(sp + 1))[0] = exe;
}

View file

@ -85,7 +85,8 @@
#define EM_RISCV 243
#define EM_BPF 247
#define EF_APE_MODERN 1
/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN 0x101ca75
#define GRP_COMDAT 1
#define STN_UNDEF 0