If the magic number is 0xfeedface instead of 0xcafebabe, this means that
the executable is not fat. The binary starts with an object header instead of a mach fat header.
This commit is contained in:
parent
d285dd8c38
commit
b57515f2c4
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: exec_macho.c,v 1.8 2002/10/05 22:34:05 chs Exp $ */
|
||||
/* $NetBSD: exec_macho.c,v 1.9 2002/10/29 19:28:19 manu Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.8 2002/10/05 22:34:05 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: exec_macho.c,v 1.9 2002/10/29 19:28:19 manu Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -98,9 +98,9 @@ static void
|
||||
exec_macho_print_fat_arch(struct exec_macho_fat_arch *arch) {
|
||||
printf("arch.cputype %x\n", be32toh(arch->cputype));
|
||||
printf("arch.cpusubtype %d\n", be32toh(arch->cpusubtype));
|
||||
printf("arch.offset 0x%x\n", be32toh(arch->offset));
|
||||
printf("arch.size %d\n", be32toh(arch->size));
|
||||
printf("arch.align 0x%x\n", be32toh(arch->align));
|
||||
printf("arch.offset 0x%lx\n", be32toh(arch->offset));
|
||||
printf("arch.size %ld\n", be32toh(arch->size));
|
||||
printf("arch.align 0x%lx\n", be32toh(arch->align));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -352,30 +352,43 @@ exec_macho_load_vnode(struct proc *p, struct exec_package *epp,
|
||||
size_t size;
|
||||
void *buf = &lc;
|
||||
|
||||
if (be32toh(fat->magic) != MACHO_FAT_MAGIC) {
|
||||
DPRINTF(("bad exec_macho fat magic %x\n", fat->magic));
|
||||
goto bad;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MACHO
|
||||
exec_macho_print_fat_header(fat);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < be32toh(fat->nfat_arch); i++, arch) {
|
||||
if ((error = exec_read_from(p, vp, sizeof(*fat) +
|
||||
sizeof(arch) * i, &arch, sizeof(arch))) != 0)
|
||||
goto bad;
|
||||
switch(be32toh(fat->magic)){
|
||||
case MACHO_FAT_MAGIC:
|
||||
for (i = 0; i < be32toh(fat->nfat_arch); i++, arch) {
|
||||
if ((error = exec_read_from(p, vp, sizeof(*fat) +
|
||||
sizeof(arch) * i, &arch, sizeof(arch))) != 0)
|
||||
goto bad;
|
||||
#ifdef DEBUG_MACHO
|
||||
exec_macho_print_fat_arch(&arch);
|
||||
exec_macho_print_fat_arch(&arch);
|
||||
#endif
|
||||
switch (be32toh(arch.cputype)) {
|
||||
MACHO_MACHDEP_CASES
|
||||
switch (be32toh(arch.cputype)) {
|
||||
MACHO_MACHDEP_CASES
|
||||
}
|
||||
}
|
||||
}
|
||||
DPRINTF(("This MACH-O binary does not support your cpu"));
|
||||
goto bad;
|
||||
|
||||
DPRINTF(("This MACH-O binary does not support your cpu"));
|
||||
goto bad;
|
||||
done:
|
||||
break;
|
||||
|
||||
case MACHO_MOH_MAGIC:
|
||||
/*
|
||||
* This is not a FAT Mach-O binary, the file starts
|
||||
* with the object header.
|
||||
*/
|
||||
arch.offset = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
DPRINTF(("bad exec_macho magic %x\n", fat->magic));
|
||||
goto bad;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((error = exec_read_from(p, vp, be32toh(arch.offset), &hdr,
|
||||
sizeof(hdr))) != 0)
|
||||
goto bad;
|
||||
|
Loading…
Reference in New Issue
Block a user