From b542295cd8d906647e013056ab049323ce11e910 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 25 Sep 2017 09:59:48 -0700 Subject: Basic Mach-O support in file(1). The Nexus Player build was subtly broken in that it assumed that the host was using ELF. No-one noticed until a Mac user tried to flash their build, which contained a Mach-O x86 binary instead of an ELF x86 binary. Hilarity ensued. (On the same day, file(1) was able to explain a mixup with an ELF hexagon binary. Next time we see a Mach-O binary on an Android device, we'll be ready!) Bug: http://b/66741960 --- toys/posix/file.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'toys') diff --git a/toys/posix/file.c b/toys/posix/file.c index 9958d044..2f1e95ba 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -251,7 +251,26 @@ static void do_regular_file(int fd, char *name, struct stat *sb) } else if (len>4 && strstart(&s, "BZh") && isdigit(*s)) xprintf("bzip2 compressed data, block size = %c00k\n", *s); else if (len>10 && strstart(&s, "\x1f\x8b")) xputs("gzip compressed data"); - else { + else if (len>32 && !memcmp(s+1, "\xfa\xed\xfe", 3)) { + int bit = s[0]=='\xce'?32:64; + char *what; + + xprintf("Mach-O %d-bit ", bit); + + if (s[4] == 7) what = (bit==32)?"x86":"x86-"; + else if (s[4] == 12) what = "arm"; + else if (s[4] == 18) what = "ppc"; + else what = NULL; + if (what) xprintf("%s%s ", what, (bit==32)?"":"64"); + else xprintf("(bad arch %d) ", s[4]); + + if (s[12] == 1) what = "object"; + else if (s[12] == 2) what = "executable"; + else if (s[12] == 6) what = "shared library"; + else what = NULL; + if (what) xprintf("%s\n", what); + else xprintf("(bad type %d)\n", s[9]); + } else { char *what = 0; int i, bytes; -- cgit v1.2.3