aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-09-25 09:59:48 -0700
committerRob Landley <rob@landley.net>2017-09-25 13:24:58 -0500
commitb542295cd8d906647e013056ab049323ce11e910 (patch)
tree8f19984606efd895da508eb68fc6dbc2e04b6232 /toys
parenteb95221609892a20cf4d15d6ee5769a082ad8026 (diff)
downloadtoybox-b542295cd8d906647e013056ab049323ce11e910.tar.gz
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
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/file.c21
1 files changed, 20 insertions, 1 deletions
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;