Skip to content

Commit

Permalink
Merge pull request #30 from bojand/dex_dey
Browse files Browse the repository at this point in the history
feat: add dex and dey support
  • Loading branch information
bojand committed Jan 2, 2021
2 parents a203379 + da16427 commit 0f63bc2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions src/matchers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Binary file added testdata/sample.dex
Binary file not shown.
Binary file added testdata/sample.dey
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit 0f63bc2

Please sign in to comment.