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