Skip to content

Commit

Permalink
add uspport for obj, dll, and coff object file formats
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Mar 5, 2021
1 parent e46b47d commit 48ca43b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ assert_eq!(kind.extension(), "foo");
- **rpm** - `application/x-rpm`
- **dcm** - `application/dicom`
- **zst** - `application/zstd`
- **msi** - `application/x-ole-storage`

#### Book

Expand All @@ -196,17 +197,20 @@ assert_eq!(kind.extension(), "foo");

- **wasm** - `application/wasm`
- **exe** - `application/vnd.microsoft.portable-executable`
- **dll** - `application/vnd.microsoft.portable-executable`
- **elf** - `application/x-executable`
- **bc** - `application/llvm`
- **mach** - `application/x-mach-binary`
- **class** - `application/java`
- **dex** - `application/vnd.android.dex`
- **dey** - `application/vnd.android.dey`
- **der** - `application/x-x509-ca-cert`
- **obj** - `application/x-executable`

## Known Issues

- `doc`, `ppt`, `xls` all have the same magic number so it's not possible to tell which one just based on the binary data. `doc` is returned for all.
- `doc`, `ppt`, `xls`, `msi` all have the same magic number so it's not possible to tell which one just based on the binary data. `doc` is returned for all.
- `exe` and `dll` have the same magic number so it's not possible to tell which one just based on the binary data. `exe` is returned for all.

## License

Expand Down
30 changes: 30 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ matcher_map!(
"exe",
matchers::app::is_exe
),
(
MatcherType::APP,
"application/vnd.microsoft.portable-executable",
"dll",
matchers::app::is_dll
),
(
MatcherType::APP,
"application/java",
Expand Down Expand Up @@ -87,6 +93,24 @@ matcher_map!(
"der",
matchers::app::is_der
),
(
MatcherType::APP,
"application/x-executable",
"obj",
matchers::app::is_coff_i386
),
(
MatcherType::APP,
"application/x-executable",
"obj",
matchers::app::is_coff_x64
),
(
MatcherType::APP,
"application/x-executable",
"obj",
matchers::app::is_coff_ia64
),
// Book
(
MatcherType::BOOK,
Expand Down Expand Up @@ -490,6 +514,12 @@ matcher_map!(
"zst",
matchers::archive::is_zst
),
(
MatcherType::ARCHIVE,
"application/x-ole-storage",
"msi",
matchers::archive::is_msi
),
// Text
(
MatcherType::TEXT,
Expand Down
20 changes: 20 additions & 0 deletions src/matchers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ pub fn is_exe(buf: &[u8]) -> bool {
buf.len() > 1 && buf[0] == 0x4D && buf[1] == 0x5A
}

/// Returns whether a buffer is a DLL.
pub fn is_dll(buf: &[u8]) -> bool {
is_exe(buf)
}

/// Returns whether a buffer is an ELF.
pub fn is_elf(buf: &[u8]) -> bool {
buf.len() > 52 && buf[0] == 0x7F && buf[1] == 0x45 && buf[2] == 0x4C && buf[3] == 0x46
Expand Down Expand Up @@ -100,3 +105,18 @@ pub fn is_der(buf: &[u8]) -> bool {

buf.len() > 2 && buf[0] == 0x30 && buf[1] == 0x82
}

/// Returns whether a buffer is a Common Object File Format for i386 architecture.
pub fn is_coff_i386(buf: &[u8]) -> bool {
buf.len() > 2 && buf[0] == 0x4C && buf[1] == 0x01
}

/// Returns whether a buffer is a Common Object File Format for x64 architecture.
pub fn is_coff_x64(buf: &[u8]) -> bool {
buf.len() > 2 && buf[0] == 0x64 && buf[1] == 0x86
}

/// Returns whether a buffer is a Common Object File Format for Itanium architecture.
pub fn is_coff_ia64(buf: &[u8]) -> bool {
buf.len() > 2 && buf[0] == 0x00 && buf[1] == 0x02
}
13 changes: 13 additions & 0 deletions src/matchers/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,16 @@ pub fn is_dcm(buf: &[u8]) -> bool {
pub fn is_zst(buf: &[u8]) -> bool {
buf.len() > 3 && buf[0] == 0x28 && buf[1] == 0xB5 && buf[2] == 0x2F && buf[3] == 0xFD
}

/// Returns whether a buffer is a MSI Windows Installer archive.
pub fn is_msi(buf: &[u8]) -> bool {
buf.len() > 7
&& buf[0] == 0xD0
&& buf[1] == 0xCF
&& buf[2] == 0x11
&& buf[3] == 0xE0
&& buf[4] == 0xA1
&& buf[5] == 0xB1
&& buf[6] == 0x1A
&& buf[7] == 0xE1
}

0 comments on commit 48ca43b

Please sign in to comment.