cafebabe 1.9 KB

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