Skip to content

Commit 66d56c2

Browse files
Add support for APK; close #345 (#624)
1 parent 8278245 commit 66d56c2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

internal/magic/zip.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,22 @@ func zipContains(raw, sig []byte, msoCheck bool) bool {
110110
}
111111
return false
112112
}
113+
114+
// APK matches an Android Package Archive.
115+
// The source of signatures is https://github.com/file/file/blob/1778642b8ba3d947a779a36fcd81f8e807220a19/magic/Magdir/archive#L1820-L1887
116+
func APK(raw []byte, _ uint32) bool {
117+
apkSignatures := [][]byte{
118+
[]byte("AndroidManifest.xml"),
119+
[]byte("META-INF/com/android/build/gradle/app-metadata.properties"),
120+
[]byte("classes.dex"),
121+
[]byte("resources.arsc"),
122+
[]byte("res/drawable"),
123+
}
124+
for _, sig := range apkSignatures {
125+
if zipContains(raw, sig, false) {
126+
return true
127+
}
128+
}
129+
130+
return false
131+
}

supported_mimes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 177 Supported MIME types
1+
## 178 Supported MIME types
22
This file is automatically generated when running tests. Do not edit manually.
33

44
Extension | MIME type | Aliases
@@ -11,6 +11,7 @@ Extension | MIME type | Aliases
1111
**.docx** | application/vnd.openxmlformats-officedocument.wordprocessingml.document | -
1212
**.pptx** | application/vnd.openxmlformats-officedocument.presentationml.presentation | -
1313
**.epub** | application/epub+zip | -
14+
**.apk** | application/vnd.android.package-archive | -
1415
**.jar** | application/jar | -
1516
**.odt** | application/vnd.oasis.opendocument.text | application/x-vnd.oasis.opendocument.text
1617
**.ott** | application/vnd.oasis.opendocument.text-template | application/x-vnd.oasis.opendocument.text-template

tree.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ var (
4444
"application/gzip-compressed", "application/x-gzip-compressed",
4545
"gzip/document")
4646
sevenZ = newMIME("application/x-7z-compressed", ".7z", magic.SevenZ)
47-
zip = newMIME("application/zip", ".zip", magic.Zip, xlsx, docx, pptx, epub, jar, odt, ods, odp, odg, odf, odc, sxc).
47+
// APK must be checked before JAR because APK is a subset of JAR.
48+
// This means APK should be a child of JAR detector, but in practice,
49+
// the decisive signature for JAR might be located at the end of the file
50+
// and not reachable because of library readLimit.
51+
zip = newMIME("application/zip", ".zip", magic.Zip, xlsx, docx, pptx, epub, apk, jar, odt, ods, odp, odg, odf, odc, sxc).
4852
alias("application/x-zip", "application/x-zip-compressed")
4953
tar = newMIME("application/x-tar", ".tar", magic.Tar)
5054
xar = newMIME("application/x-xar", ".xar", magic.Xar)
@@ -57,6 +61,7 @@ var (
5761
pptx = newMIME("application/vnd.openxmlformats-officedocument.presentationml.presentation", ".pptx", magic.Pptx)
5862
epub = newMIME("application/epub+zip", ".epub", magic.Epub)
5963
jar = newMIME("application/jar", ".jar", magic.Jar)
64+
apk = newMIME("application/vnd.android.package-archive", ".apk", magic.APK)
6065
ole = newMIME("application/x-ole-storage", "", magic.Ole, msi, aaf, msg, xls, pub, ppt, doc)
6166
msi = newMIME("application/x-ms-installer", ".msi", magic.Msi).
6267
alias("application/x-windows-installer", "application/x-msi")

0 commit comments

Comments
 (0)