pub enum FileType {
Show 18 variants
DOCFILE,
ELF,
ELF32,
ELF64,
ELF_LSB,
ELF_MSB,
ELF32_LSB,
ELF64_LSB,
ELF32_MSB,
ELF64_MSB,
EXE,
MachO,
PDF,
PE32,
PE32DotNet,
PE32Native,
RTF,
XCOFF,
// some variants omitted
}Expand description
Known file types for training malware models
Variants§
DOCFILE
Docfile, which could be: MS Office, Windows Update, Installer, Visio, or something else! For the purposes of making a malware model, each subtype needs to be identified, which is not yet implemented.
ELF
Linux, *BSD, Solaris, Haiku, Redox executables
ELF32
32-bit ELF executable
ELF64
64-bit ELF executable
ELF_LSB
Little Endian ELF executable (ARM, Intel, PowerPC, RISC-V, etc.)
ELF_MSB
Big Endian ELF executable (ARM, M64k, MIPS, PowerPC, SPARC, etc.)
ELF32_LSB
32-bit Little Endian ELF executable
ELF64_LSB
64-bit Little Endian ELF executable
ELF32_MSB
32-bit Big Endian ELF executable
ELF64_MSB
64-bit Big Endian ELF executable
EXE
Non-PE32 Windows executable (could be for MS-DOS, OS/2, Windows 3.1, etc.)
MachO
Macho-O for macOS, iOS (and derivatives), and NeXT
Portable Document Format
PE32
Portable Executables for Windows
PE32DotNet
Portable Executables for Windows based on the .NET Framework
PE32Native
Portable Executables for Windows explicitly excluding .NET
RTF
Rich Text Format
XCOFF
Extended Common Object Format for AIX
Implementations§
Source§impl FileType
impl FileType
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Try to match bytes to a known file type
- ELFs: the byte ordering has a higher precedence of importance. Plain ELF is the fallback if the byte ordering then pointer size isn’t determined.
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Option<Self>>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Option<Self>>
Try to match bytes to a known file type
§Errors
An error will result if the file can’t be read or is too small.
Sourcepub fn matches(&self, bytes: &[u8]) -> bool
pub fn matches(&self, bytes: &[u8]) -> bool
Check if the given bytes match the expected file type. This isn’t as easy as “make a new instance and use the equality operator” due to subtypes.
- A
FileType::PE32file is anFileType::EXE, but anFileType::EXEisn’t necessarily aFileType::PE32. - A
FileType::ELF_LSBfile is anFileType::ELF, but not necessarily the other way around. - ELFs: the byte ordering has a higher precedence of importance.
With subtypes, allow for training a model where you might want all ELFs, or only certain ELFs, so others would be disqualified.
Sourcepub fn matches_path<P: AsRef<Path>>(&self, path: P) -> Result<bool>
pub fn matches_path<P: AsRef<Path>>(&self, path: P) -> Result<bool>
Convenience function to read a few bytes of a file to see the file’s type matches this type.
§Errors
An error occurs if the file cannot be read.
Sourcepub fn downgrade(self, other: FileType) -> Result<FileType>
pub fn downgrade(self, other: FileType) -> Result<FileType>
When trying to find a file type for a collection of files, maybe we can pick a broader type from a specific type.
§Examples:
FileType::PE32DotNetorFileType::PE32Nativecan drop down toFileType::PE32- Any “PE32*” type can drop down to
FileType::EXE - “ELF*” of any subtype can drop down to
FileType::ELF.
§Errors
Any other type is an error.
For example, FileType::RTF cannot downgrade, so finding anything but an RTF file
is an error.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FileType
impl<'de> Deserialize<'de> for FileType
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for FileType
impl Eq for FileType
impl StructuralPartialEq for FileType
Auto Trait Implementations§
impl Freeze for FileType
impl RefUnwindSafe for FileType
impl Send for FileType
impl Sync for FileType
impl Unpin for FileType
impl UnsafeUnpin for FileType
impl UnwindSafe for FileType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more