dissect.target.helpers.magic.magic¶
Module Contents¶
Classes¶
Magic is a helper class for identifying files to a file type by magic bytes. |
Functions¶
Detect file type from a |
|
Detect file type from a |
|
Detect file type from a file descriptor or handle. |
|
Detect file type from provided bytes or buffer of bytes. |
Attributes¶
- type dissect.target.helpers.magic.magic.MagicResult = str | None¶
- class dissect.target.helpers.magic.magic.Magic¶
Magic is a helper class for identifying files to a file type by magic bytes.
This class mimics
python-magicbehaviour, however this implementation does not depend on thelibmagicC-library system package. Instead a precompiled XML document of FreeDesktop’s shared-mime-info project is used to identify files.Falls back to file extensions (where applicable) if no magic header is detected in the provided buffer.
The underlying implementation currently does not support nested magic definitions and logical AND/OR matches, which somewhat limits the supported FreeDesktop XML magic signature set.
from dissect.target.helpers import magic >>> magic.from_buffer(b"SQLite format 3FILE DATAM<²¡") "SQLite3 database" >>> magic.from_file(target.fs.path("file.jpg"), mime=True) "image/jpg"Currently does not implement
python-magicMagicinvocation behaviour.- Resources:
- static detect(buf: BinaryIO, suffix: str | None = None, *, mime: bool = False) MagicResult¶
Searches
mimetypes.MAPfor the given bytes.
- dissect.target.helpers.magic.magic.from_file(path: pathlib.Path, *, mime: bool = False) MagicResult¶
Detect file type from a
Pathinstance.
- dissect.target.helpers.magic.magic.from_entry(entry: dissect.target.filesystem.FilesystemEntry, *, mime: bool = False) MagicResult¶
Detect file type from a
FilesystemEntryinstance.
- dissect.target.helpers.magic.magic.from_descriptor(fh: BinaryIO, suffix: str | None = None, *, mime: bool = False) MagicResult¶
Detect file type from a file descriptor or handle.
- dissect.target.helpers.magic.magic.from_fh¶