1b6cee71dSXin LI 2b6cee71dSXin LI#------------------------------------------------------------------------------ 3*4460e5b0SXin LI# $File: cafebabe,v 1.17 2015/01/01 17:07:00 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) 31b6cee71dSXin LI 32b6cee71dSXin LI0 belong 0xcafed00d JAR compressed with pack200, 33b6cee71dSXin LI>5 byte x version %d. 34b6cee71dSXin LI>4 byte x \b%d 35b6cee71dSXin LI!:mime application/x-java-pack200 36b6cee71dSXin LI 37b6cee71dSXin LI 38b6cee71dSXin LI0 belong 0xcafed00d JAR compressed with pack200, 39b6cee71dSXin LI>5 byte x version %d. 40b6cee71dSXin LI>4 byte x \b%d 41b6cee71dSXin LI!:mime application/x-java-pack200 42b6cee71dSXin LI 43b6cee71dSXin LI### JAVA END ### 44b6cee71dSXin LI### MACH-O START ### 45b6cee71dSXin LI 46b6cee71dSXin LI0 name mach-o \b [ 47b6cee71dSXin LI>0 use mach-o-cpu \b 48*4460e5b0SXin LI>(8.L) indirect \b: 49b6cee71dSXin LI>0 belong x \b] 50b6cee71dSXin LI 51b6cee71dSXin LI0 belong 0xcafebabe 52b6cee71dSXin LI>4 belong 1 Mach-O universal binary with 1 architecture: 53b6cee71dSXin LI>>8 use mach-o \b 54b6cee71dSXin LI>4 belong >1 55b6cee71dSXin LI>>4 belong <20 Mach-O universal binary with %d architectures: 56b6cee71dSXin LI>>>8 use mach-o \b 57b6cee71dSXin LI>>>28 use mach-o \b 58b6cee71dSXin LI>>4 belong >2 59b6cee71dSXin LI>>>48 use mach-o \b 60b6cee71dSXin LI>>4 belong >3 61b6cee71dSXin LI>>>68 use mach-o \b 62b6cee71dSXin LI 63b6cee71dSXin LI### MACH-O END ### 64