cafebabe 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #------------------------------------------------------------------------------
  2. # $File: cafebabe,v 1.12 2013/01/11 16:45:23 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. !:mime application/x-java-applet
  19. >4 belong >30 compiled Java class data,
  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. # 16777216 = 0x01000000
  41. 0 name mach-o \b [
  42. >0 belong 0xffffffff \bAny
  43. >0 belong 1 \bVax
  44. >0 belong 6 \bMC680x0
  45. >0 belong 7 \bI386
  46. >0 belong 8 \bMIPS
  47. >0 belong 10 \bMC98000
  48. >0 belong 11 \bHPPA
  49. >0 belong 12 \bARM
  50. >0 belong 13 \bMC88000
  51. >0 belong 14 \bSPARC
  52. >0 belong 15 \bI860
  53. >0 belong 16 \bALPHA
  54. >0 belong 17 \bPOWERPC
  55. >0 belong 16777223 \bX86_64
  56. >0 belong 16777233 \bPOWERPC64
  57. >&(8.L) indirect :
  58. >0 belong x \b]
  59. 0 belong 0xcafebabe
  60. >4 belong 1 Mach-O universal binary with 1 architecture:
  61. >>8 use mach-o
  62. >4 belong >1
  63. >>4 belong <20 Mach-O universal binary with %ld architectures:
  64. >>>8 use mach-o
  65. >>>28 use mach-o
  66. >>>4 belong >2
  67. >>>>48 use mach-o
  68. >>>>>4 belong >3
  69. >>>>>68 use mach-o
  70. ### MACH-O END ###