1b6cee71dSXin LI 2b6cee71dSXin LI#------------------------------------------------------------------------------ 3*5f0216bdSXin LI# $File: cafebabe,v 1.20 2015/05/29 14:21:58 christos Exp $ 4b6cee71dSXin LI# Cafe Babes unite! 5b6cee71dSXin LI# 6b6cee71dSXin LI# Since Java bytecode and Mach-O universal binaries have the same magic number, 7b6cee71dSXin LI# the test must be performed in the same "magic" sequence to get both right. 8b6cee71dSXin LI# The long at offset 4 in a Mach-O universal binary tells the number of 9b6cee71dSXin LI# architectures; the short at offset 4 in a Java bytecode file is the JVM minor 10b6cee71dSXin LI# version and the short at offset 6 is the JVM major version. Since there are only 11b6cee71dSXin LI# only 18 labeled Mach-O architectures at current, and the first released 12b6cee71dSXin LI# Java class format was version 43.0, we can safely choose any number 13b6cee71dSXin LI# between 18 and 39 to test the number of architectures against 14b6cee71dSXin LI# (and use as a hack). Let's not use 18, because the Mach-O people 15b6cee71dSXin LI# might add another one or two as time goes by... 16b6cee71dSXin LI# 17b6cee71dSXin LI### JAVA START ### 18b6cee71dSXin LI0 belong 0xcafebabe 19b6cee71dSXin LI>4 belong >30 compiled Java class data, 20b6cee71dSXin LI!:mime application/x-java-applet 21b6cee71dSXin LI>>6 beshort x version %d. 22b6cee71dSXin LI>>4 beshort x \b%d 23b6cee71dSXin LI# Which is which? 24b6cee71dSXin LI#>>4 belong 0x032d (Java 1.0) 25b6cee71dSXin LI#>>4 belong 0x032d (Java 1.1) 26b6cee71dSXin LI>>4 belong 0x002e (Java 1.2) 27b6cee71dSXin LI>>4 belong 0x002f (Java 1.3) 28b6cee71dSXin LI>>4 belong 0x0030 (Java 1.4) 29b6cee71dSXin LI>>4 belong 0x0031 (Java 1.5) 30b6cee71dSXin LI>>4 belong 0x0032 (Java 1.6) 31*5f0216bdSXin LI>>4 belong 0x0033 (Java 1.7) 32*5f0216bdSXin LI>>4 belong 0x0034 (Java 1.8) 33b6cee71dSXin LI 34b6cee71dSXin LI0 belong 0xcafed00d JAR compressed with pack200, 35b6cee71dSXin LI>5 byte x version %d. 36b6cee71dSXin LI>4 byte x \b%d 37b6cee71dSXin LI!:mime application/x-java-pack200 38b6cee71dSXin LI 39b6cee71dSXin LI 40b6cee71dSXin LI0 belong 0xcafed00d JAR compressed with pack200, 41b6cee71dSXin LI>5 byte x version %d. 42b6cee71dSXin LI>4 byte x \b%d 43b6cee71dSXin LI!:mime application/x-java-pack200 44b6cee71dSXin LI 45b6cee71dSXin LI### JAVA END ### 46b6cee71dSXin LI### MACH-O START ### 47b6cee71dSXin LI 48b6cee71dSXin LI0 name mach-o \b [ 49b6cee71dSXin LI>0 use mach-o-cpu \b 504460e5b0SXin LI>(8.L) indirect \b: 51b6cee71dSXin LI>0 belong x \b] 52b6cee71dSXin LI 53b6cee71dSXin LI0 belong 0xcafebabe 54b6cee71dSXin LI>4 belong 1 Mach-O universal binary with 1 architecture: 55*5f0216bdSXin LI!:mime application/x-mach-binary 56b6cee71dSXin LI>>8 use mach-o \b 57b6cee71dSXin LI>4 belong >1 58b6cee71dSXin LI>>4 belong <20 Mach-O universal binary with %d architectures: 59*5f0216bdSXin LI!:mime application/x-mach-binary 60b6cee71dSXin LI>>>8 use mach-o \b 61b6cee71dSXin LI>>>28 use mach-o \b 62*5f0216bdSXin LI>>4 belong 2 63b6cee71dSXin LI>>>48 use mach-o \b 64*5f0216bdSXin LI>>4 belong 3 65b6cee71dSXin LI>>>68 use mach-o \b 66*5f0216bdSXin LI>>4 belong 4 67*5f0216bdSXin LI>>>88 use mach-o \b 68b6cee71dSXin LI 69b6cee71dSXin LI### MACH-O END ### 70