commit - 678ddfbff455990746fa07b65b0fcc1030a02ee4
commit + 4c34a12775cfbfa6d3dd0ff519e5e23e20c86526
blob - 22f9f08bda533c192adf9a30ea734608fde6bb04
blob + c074697f3cef1754abac8c3a31d5d60b18757689
--- dermob.c
+++ dermob.c
return(0);
}
+int
+determine_mo_arch(char *buffer)
+{
+ struct mach_header_magic mhh;
+ char *ptr = buffer;
+ int ret = -1;
+
+ memcpy(&mhh, ptr, sizeof(mhh));
+
+ if (mhh.magic == MH_MAGIC_64)
+ ret = 0;
+ else if (mhh.magic == MH_CIGAM_64)
+ ret = 1;
+ else if (mhh.magic == MH_MAGIC)
+ ret = 2;
+ else if (mhh.magic == MH_CIGAM)
+ ret = 3;
+
+ return ret;
+}
+
/*
* Parse the mach-o header, set the correct byte order ot the binary and
* determine the number of load commands.
{
struct mach_header *mh;
char *ptr;
+ int moa;
- mh = malloc(sizeof(*mh));
ptr = buffer;
-
if (offset > 0)
ptr += *offset;
- memcpy(mh, ptr, sizeof(*mh));
-
- /* No valid mach-o binary */
- if (mh->magic != MH_MAGIC && mh->magic != MH_CIGAM) {
- rmh = NULL;
- free(mh);
- return(-1);
+ moa = determine_mo_arch(buffer);
+ if (moa != 0 && moa != 1 && moa != 2 && moa != 3) {
+ printf("Cannot determine mach-o architecture\n");
+ return(1);
}
+ /*
+ * There is no need to differentiate between 32 and 64bit here, as the
+ * headers are identical (I ignore the reserved field).
+ */
+ mh = malloc(sizeof(*mh));
+ if (mh == NULL) {
+ printf("Cannot allocate memory\n");
+ return(1);
+ }
+ memcpy(mh, ptr, sizeof(*mh));
+
/* Determine the correct byte order */
- if (mh->magic == MH_MAGIC && bo_a == LE)
+ if ((mh->magic == MH_MAGIC && bo_a == LE) ||
+ (mh->magic == MH_MAGIC_64 && bo_a == LE))
bo_b = LE;
- else if (mh->magic == MH_CIGAM && bo_a == LE)
+ else if ((mh->magic == MH_CIGAM && bo_a == LE) ||
+ (mh->magic == MH_CIGAM_64 && bo_a == LE))
bo_b = BE;
- else if (mh->magic == MH_MAGIC && bo_a != LE)
+ else if ((mh->magic == MH_MAGIC && bo_a != LE) ||
+ (mh->magic == MH_MAGIC_64 && bo_a != LE))
bo_b = BE;
- else if (mh->magic == MH_CIGAM && bo_a != LE)
+ else if ((mh->magic == MH_CIGAM && bo_a != LE) ||
+ (mh->magic == MH_CIGAM_64 && bo_a != LE))
bo_b = LE;
offset_moh = *offset;
blob - 6273d27f293e809e76a2d2c89604382100441a31
blob + 1657bffcaf911246c6debd53dc76cf40928dcf19
--- util.c
+++ util.c
case CPU_TYPE_MC680x0:
mprintf("MC680x0"); break;
case CPU_TYPE_I386:
- mprintf("x86"); break;
+ mprintf("x86_32"); break;
+ case CPU_TYPE_X86_64:
+ mprintf("x86_64"); break;
case CPU_TYPE_POWERPC:
mprintf("PowerPC"); break;
case CPU_TYPE_HPPA:
void
mprintf(const char *fmt, ...)
{
- va_list ap;
+ va_list ap;
if (trigger == 1)
return;