cafebabe 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #------------------------------------------------------------------------------
  2. # $File: cafebabe,v 1.28 2022/07/01 23:24:47 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. # Reference: http://en.wikipedia.org/wiki/Java_class_file
  18. # Update: Joerg Jenderek
  19. 0 belong 0xcafebabe
  20. >4 ubelong >30 compiled Java class data,
  21. !:mime application/x-java-applet
  22. #!:mime application/java-byte-code
  23. !:ext class
  24. >>6 ubeshort x version %d.
  25. >>4 ubeshort x \b%d
  26. # for debugging purpose version as hexadecimal to compare with Mach-O universal binary
  27. #>>4 ubelong x (%#8.8x)
  28. # Which is which?
  29. # https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html
  30. #>>4 belong 0x002b (Java 0.?)
  31. #>>4 belong 0x032d (Java 1.0)
  32. #>>4 belong 0x032d (Java 1.1)
  33. >>4 belong 0x002e (Java 1.2)
  34. >>4 belong 0x002f (Java 1.3)
  35. >>4 belong 0x0030 (Java 1.4)
  36. >>4 belong 0x0031 (Java 1.5)
  37. >>4 belong 0x0032 (Java 1.6)
  38. >>4 belong 0x0033 (Java 1.7)
  39. >>4 belong 0x0034 (Java 1.8)
  40. >>4 belong 0x0035 (Java SE 9)
  41. >>4 belong 0x0036 (Java SE 10)
  42. >>4 belong 0x0037 (Java SE 11)
  43. >>4 belong 0x0038 (Java SE 12)
  44. >>4 belong 0x0039 (Java SE 13)
  45. >>4 belong 0x003A (Java SE 14)
  46. >>4 belong 0x003B (Java SE 15)
  47. >>4 belong 0x003C (Java SE 16)
  48. >>4 belong 0x003D (Java SE 17)
  49. >>4 belong 0x003E (Java SE 18)
  50. >>4 belong 0x003F (Java SE 19)
  51. >>4 belong 0x0040 (Java SE 20)
  52. # pool count unequal zero
  53. #>>8 beshort x \b, pool count %#x
  54. # pool table
  55. #>>10 ubequad x \b, pool %#16.16llx...
  56. 0 belong 0xcafed00d JAR compressed with pack200,
  57. >5 byte x version %d.
  58. >4 byte x \b%d
  59. !:mime application/x-java-pack200
  60. 0 belong 0xcafed00d JAR compressed with pack200,
  61. >5 byte x version %d.
  62. >4 byte x \b%d
  63. !:mime application/x-java-pack200
  64. ### JAVA END ###
  65. ### MACH-O START ###
  66. # URL: https://en.wikipedia.org/wiki/Mach-O
  67. 0 name mach-o \b [
  68. # for debugging purpose CPU type as hexadecimal
  69. #>0 ubequad x CPU=%16.16llx
  70. # display CPU type as string like: i386 x86_64 ... armv7 armv7k ...
  71. >0 use mach-o-cpu \b
  72. # for debugging purpose print offset to 1st mach_header like:
  73. # 1000h 4000h seldom 2d000h 88000h 5b000h 10e000 h
  74. #>8 ubelong x at %#x offset
  75. >(8.L) indirect x \b:
  76. >0 belong x \b]
  77. # Reference: https://opensource.apple.com/source/cctools/cctools-949.0.1/
  78. # include/mach-o/fat.h
  79. # include/mach/machine.h
  80. 0 belong 0xcafebabe
  81. >4 belong 1 Mach-O universal binary with 1 architecture:
  82. !:mime application/x-mach-binary
  83. >>8 use mach-o \b
  84. # nfat_arch; number of CPU architectures; highest is 18 for CPU_TYPE_POWERPC in 2020
  85. >4 ubelong >1
  86. >>4 ubelong <20 Mach-O universal binary with %d architectures:
  87. !:mime application/x-mach-binary
  88. >>>8 use mach-o \b
  89. >>>4 ubelong >1
  90. >>>>28 use mach-o \b
  91. >>>4 ubelong >2
  92. >>>>48 use mach-o \b
  93. >>>4 ubelong >3
  94. >>>>68 use mach-o \b
  95. >>>4 ubelong >4
  96. >>>>88 use mach-o \b
  97. >>>4 ubelong >5
  98. >>>>108 use mach-o \b
  99. ### MACH-O END ###