1674058358.FILE5_44-24-gc4361a10.improve-detection-of-apk-files-if-we-find-a-manifest-file-at-least-say.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Subject: Improve detection of APK files; if we find a manifest file, at least say (...)
  2. Origin: FILE5_44-24-gc4361a10 <https://github.com/file/file/commit/FILE5_44-24-gc4361a10>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Jan 18 16:12:38 2023 +0000
  5. improve detection of APK files; if we find a manifest file, at least say
  6. that it is a jar file (FC Stegerman)
  7. --- a/magic/Magdir/archive
  8. +++ b/magic/Magdir/archive
  9. @@ -1511,66 +1511,70 @@
  10. # Starts with AndroidManifest.xml (file name length = 19)
  11. >26 uleshort 19
  12. >>30 string AndroidManifest.xml Android package (APK), with AndroidManifest.xml
  13. ->>>-22 string PK\005\006
  14. ->>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  15. !:mime application/vnd.android.package-archive
  16. !:ext apk
  17. +>>>-22 string PK\005\006
  18. +>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  19. # Starts with META-INF/com/android/build/gradle/app-metadata.properties
  20. >26 uleshort 57
  21. >>30 string META-INF/com/android/build/gradle/
  22. >>>&0 string app-metadata.properties Android package (APK), with gradle app-metadata.properties
  23. ->>>>-22 string PK\005\006
  24. ->>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  25. !:mime application/vnd.android.package-archive
  26. !:ext apk
  27. +>>>>-22 string PK\005\006
  28. +>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  29. # Starts with classes.dex (file name length = 11)
  30. >26 uleshort 11
  31. >>30 string classes.dex Android package (APK), with classes.dex
  32. ->>>-22 string PK\005\006
  33. ->>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  34. !:mime application/vnd.android.package-archive
  35. !:ext apk
  36. +>>>-22 string PK\005\006
  37. +>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  38. # Starts with META-INF/MANIFEST.MF (file name length = 20)
  39. # NB: checks for resources.arsc, classes.dex, etc. as well to avoid matching JAR files
  40. >26 uleshort 20
  41. >>30 string META-INF/MANIFEST.MF
  42. # Contains resources.arsc (near the end, in the central directory)
  43. >>>-512 search resources.arsc Android package (APK), with MANIFEST.MF and resources.arsc
  44. ->>>>-22 string PK\005\006
  45. ->>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  46. !:mime application/vnd.android.package-archive
  47. !:ext apk
  48. +>>>>-22 string PK\005\006
  49. +>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  50. >>>-512 default x
  51. # Contains classes.dex (near the end, in the central directory)
  52. >>>>-512 search classes.dex Android package (APK), with MANIFEST.MF and classes.dex
  53. ->>>>>-22 string PK\005\006
  54. ->>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  55. !:mime application/vnd.android.package-archive
  56. !:ext apk
  57. +>>>>>-22 string PK\005\006
  58. +>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  59. >>>>-512 default x
  60. # Contains lib/armeabi (near the end, in the central directory)
  61. >>>>>-512 search lib/armeabi Android package (APK), with MANIFEST.MF and armeabi lib
  62. ->>>>>>-22 string PK\005\006
  63. ->>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  64. !:mime application/vnd.android.package-archive
  65. !:ext apk
  66. +>>>>>>-22 string PK\005\006
  67. +>>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  68. >>>>>-512 default x
  69. # Contains drawables (near the end, in the central directory)
  70. >>>>>>-512 search res/drawable Android package (APK), with MANIFEST.MF and drawables
  71. ->>>>>>>-22 string PK\005\006
  72. ->>>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  73. !:mime application/vnd.android.package-archive
  74. !:ext apk
  75. +>>>>>>>-22 string PK\005\006
  76. +>>>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  77. +# It may or may not be an APK file, but it's definitely a Java JAR file
  78. +>>>>>>-512 default x Java archive data (JAR)
  79. +!:mime application/java-archive
  80. +!:ext jar
  81. # Starts with zipflinger virtual entry (28 + 104 = 132 bytes)
  82. # See https://github.com/obfusk/apksigcopier/blob/666f5b7/apksigcopier/__init__.py#L230
  83. >4 string \x00\x00\x00\x00\x00\x00
  84. >>&0 string \x21\x08\x21\x02
  85. >>>&0 string \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
  86. >>>>&0 string \x00\x00 Android package (APK), with zipflinger virtual entry
  87. ->>>>>-22 string PK\005\006
  88. ->>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  89. !:mime application/vnd.android.package-archive
  90. !:ext apk
  91. +>>>>>-22 string PK\005\006
  92. +>>>>>>(-6.l-16) string APK\x20Sig\x20Block\x2042 \b, with APK Signing Block
  93. # APK Signing Block
  94. >0 default x
  95. >>-22 string PK\005\006
  96. @@ -1795,9 +1799,10 @@
  97. >>>38 regex [!-OQ-~]+ Zip data (MIME type "%s"?)
  98. !:mime application/zip
  99. -# Java Jar files
  100. +# Java Jar files (see also APK files above)
  101. >(26.s+30) leshort 0xcafe Java archive data (JAR)
  102. !:mime application/java-archive
  103. +!:ext jar
  104. # iOS App
  105. >(26.s+30) leshort !0xcafe