cafebabe 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #------------------------------------------------------------------------------
  2. # $File: cafebabe,v 1.24 2018/10/01 23:33:15 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. >>4 belong 0x0033 (Java 1.7)
  31. >>4 belong 0x0034 (Java 1.8)
  32. 0 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. 0 belong 0xcafed00d JAR compressed with pack200,
  37. >5 byte x version %d.
  38. >4 byte x \b%d
  39. !:mime application/x-java-pack200
  40. ### JAVA END ###
  41. ### MACH-O START ###
  42. 0 name mach-o \b [
  43. >0 use mach-o-cpu \b
  44. >(8.L) indirect x \b:
  45. >0 belong x \b]
  46. 0 belong 0xcafebabe
  47. >4 belong 1 Mach-O universal binary with 1 architecture:
  48. !:mime application/x-mach-binary
  49. >>8 use mach-o \b
  50. >4 belong >1
  51. >>4 belong <20 Mach-O universal binary with %d architectures:
  52. !:mime application/x-mach-binary
  53. >>>8 use mach-o \b
  54. >>4 belong >1
  55. >>>28 use mach-o \b
  56. >>4 belong >2
  57. >>>48 use mach-o \b
  58. >>4 belong >3
  59. >>>68 use mach-o \b
  60. >>4 belong >4
  61. >>>88 use mach-o \b
  62. >>4 belong >5
  63. >>>108 use mach-o \b
  64. ### MACH-O END ###