Skip to main content

classify

Function classify 

Source
pub fn classify(
    head: &[u8],
    read_at: &mut dyn FnMut(u64, usize) -> Result<Vec<u8>, i32>,
) -> FileKind
Expand description

Classifies a file from its leading bytes and, for ELF, its program headers.

Both ELF classes are read: the 64-bit layout (e_phoff at 32, Elf64_Phdr of 56 bytes) and the 32-bit one (e_phoff at 28, Elf32_Phdr of 32 bytes).

§Arguments

  • head - The first bytes of the file (at least 64 for ELF, up to a few KiB).
  • read_at - Reads len bytes at offset of the same file, for headers past head.

§Returns

The FileKind. An ELF whose program headers cannot be read is reported as Other so the kernel gives the final verdict.