diff --git a/README.md b/README.md index 6db9c76..4538817 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,8 @@ assert_eq!(kind.extension(), "foo"); - **bc** - `application/llvm` - **mach** - `application/x-mach-binary` - **class** - `application/java` +- **dex** - `application/vnd.android.dex` +- **dey** - `application/vnd.android.dey` ## Known Issues diff --git a/src/map.rs b/src/map.rs index 908bca3..5aa4f73 100644 --- a/src/map.rs +++ b/src/map.rs @@ -68,6 +68,18 @@ matcher_map!( "mach", matchers::app::is_mach ), + ( + MatcherType::APP, + "application/vnd.android.dex", + "dex", + matchers::app::is_dex + ), + ( + MatcherType::APP, + "application/vnd.android.dey", + "dey", + matchers::app::is_dey + ), // Image ( MatcherType::IMAGE, diff --git a/src/matchers/app.rs b/src/matchers/app.rs index f59115a..ce33be9 100644 --- a/src/matchers/app.rs +++ b/src/matchers/app.rs @@ -69,3 +69,23 @@ pub fn is_mach(buf: &[u8]) -> bool { _ => false, } } + +/// Returns whether a buffer is a Dalvik Executable (DEX). +pub fn is_dex(buf: &[u8]) -> bool { + // https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic + + buf.len() > 36 + // magic + && buf[0] == 0x64 && buf[1] == 0x65 && buf[2] == 0x78 && buf[3] == 0x0A + // file sise + && buf[36] == 0x70 +} + +/// Returns whether a buffer is a Dey Optimized Dalvik Executable (ODEX). +pub fn is_dey(buf: &[u8]) -> bool { + buf.len() > 100 + // magic + && buf[0] == 0x64 && buf[1] == 0x65 && buf[2] == 0x79 && buf[3] == 0x0A + // file sise + && is_dex(&buf[40..100]) +} diff --git a/testdata/sample.dex b/testdata/sample.dex new file mode 100644 index 0000000..0ac7a7c Binary files /dev/null and b/testdata/sample.dex differ diff --git a/testdata/sample.dey b/testdata/sample.dey new file mode 100644 index 0000000..2263e37 Binary files /dev/null and b/testdata/sample.dey differ diff --git a/tests/app.rs b/tests/app.rs index 7ff477e..db00fd8 100644 --- a/tests/app.rs +++ b/tests/app.rs @@ -43,3 +43,7 @@ test_format!( ); test_format!(APP, "application/wasm", "wasm", wasm, "sample.wasm"); + +test_format!(APP, "application/vnd.android.dex", "dex", dex, "sample.dex"); + +test_format!(APP, "application/vnd.android.dey", "dey", dey, "sample.dey");