magic
CopyrightCopyright (C) 2005 John Goerzen
LicenseBSD-3-Clause
MaintainerPhilippe <philippedev101\@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Magic.Types

Description

The core types of the binding: the opaque Magic handle, the MagicFlag enumeration (re-exported from Magic.Data) and the MagicParam tunables.

Written by John Goerzen.

Synopsis

Documentation

type Magic = ForeignPtr CMagic Source #

The magic handle: an opaque cookie obtained from magicOpen and passed to the loading and querying functions.

Handles are closed (and their memory freed) automatically when they are garbage-collected by Haskell. There is no need to close them explicitly.

Thread safety. A single Magic handle is not safe for concurrent use: the underlying libmagic cookie keeps mutable state, so calling operations on the same handle from multiple threads at once is a data race. Use one handle per thread, or serialise access to a shared handle (e.g. behind an MVar). Distinct handles are independent and may be used concurrently. Programs doing blocking work (loading databases, examining files) should also be built with the threaded runtime (-threaded).

data CMagic Source #

Phantom type standing in for the C magic_t cookie. It appears only as the argument of a ForeignPtr (the Magic handle) and has no values of its own.

data MagicFlag Source #

Flags that control how libmagic examines a file and what it reports. Combine them in the list passed to magicOpen or magicSetFlags.

Constructors

MagicNone

No special handling; return a textual description (the default).

MagicDebug

Print debugging messages to stderr.

MagicSymlink

Follow symbolic links.

MagicCompress

Look inside compressed files.

MagicDevices

Look at the contents of block or character special devices.

MagicMimeType

Return a MIME type string instead of a textual description.

MagicMimeEncoding

Return the MIME encoding (character set) instead of a textual description.

MagicMime

Return both the MIME type and the encoding.

MagicContinue

Return all matches, not just the first.

MagicCheck

Check the magic database for consistency and report problems.

MagicPreserveAtime

Preserve the access time of examined files.

MagicRaw

Do not translate unprintable characters to octal escapes.

MagicError

Treat errors while examining a file as real errors instead of embedding them in the result.

MagicApple

Return the Apple creator and type.

MagicExtension

Return a slash-separated list of valid file extensions for the detected type.

MagicCompressTransp

Report on the compressed contents only, without mentioning the compression itself (transparent decompression).

MagicNoCompressFork

Do not allow decompression that requires forking a helper process.

MagicNodesc

Composite of MagicExtension, MagicMime and MagicApple: return identifiers rather than a textual description.

MagicNoCheckCompress

Do not look inside compressed files.

MagicNoCheckTar

Do not examine tar archives.

MagicNoCheckSoft

Do not consult the magic database entries (soft magic).

MagicNoCheckApptype

Do not check for an application type (e.g. EMX).

MagicNoCheckElf

Do not examine ELF details.

MagicNoCheckText

Do not examine text files.

MagicNoCheckCdf

Do not examine CDF (Microsoft Compound Document) files.

MagicNoCheckCsv

Do not examine CSV files.

MagicNoCheckTokens

Do not look for known text tokens.

MagicNoCheckEncoding

Do not check text encodings.

MagicNoCheckJson

Do not examine JSON files.

MagicNoCheckSimh

Do not examine SIMH tape files.

MagicNoCheckBuiltin

Disable all built-in tests; consult only the magic database.

UnknownMagicFlag Int

A flag value returned by libmagic that these bindings do not recognise, carrying its raw integer value.

Instances

Instances details
Enum MagicFlag Source # 
Instance details

Defined in Magic.Data

Show MagicFlag Source # 
Instance details

Defined in Magic.Data

Methods

showsPrec :: Int -> MagicFlag -> ShowS

show :: MagicFlag -> String

showList :: [MagicFlag] -> ShowS

Eq MagicFlag Source # 
Instance details

Defined in Magic.Data

Methods

(==) :: MagicFlag -> MagicFlag -> Bool

(/=) :: MagicFlag -> MagicFlag -> Bool

Ord MagicFlag Source # 
Instance details

Defined in Magic.Data

Methods

compare :: MagicFlag -> MagicFlag -> Ordering

(<) :: MagicFlag -> MagicFlag -> Bool

(<=) :: MagicFlag -> MagicFlag -> Bool

(>) :: MagicFlag -> MagicFlag -> Bool

(>=) :: MagicFlag -> MagicFlag -> Bool

max :: MagicFlag -> MagicFlag -> MagicFlag

min :: MagicFlag -> MagicFlag -> MagicFlag

data MagicParam Source #

Tunable limits that bound how hard libmagic works when examining data, read and written with magicGetParam and magicSetParam (see Magic.Operations). Lowering these (especially MagicParamBytesMax) is a way to cap the effort spent on untrusted input. Defaults below are those documented for libmagic 5.45.

Since: 1.1.2

Constructors

MagicParamIndirMax

Maximum number of levels of recursion when following indirect magic. (Default: 15.)

MagicParamNameMax

Maximum length of a name used by name/use magic. (Default: 30.)

MagicParamElfPhnumMax

Maximum number of ELF program header sections processed. (Default: 128.)

MagicParamElfShnumMax

Maximum number of ELF section header sections processed. (Default: 32768.)

MagicParamElfNotesMax

Maximum number of ELF notes processed. (Default: 256.)

MagicParamRegexMax

Maximum length of a regex search. (Default: 8192.)

MagicParamBytesMax

Maximum number of bytes read from a file before giving up. (Default: 1048576, i.e. 1 MiB.)

MagicParamEncodingMax

Maximum number of bytes scanned when guessing a text encoding.

MagicParamElfShsizeMax

Maximum size of an ELF section processed.

Instances

Instances details
Bounded MagicParam Source # 
Instance details

Defined in Magic.Types

Enum MagicParam Source # 
Instance details

Defined in Magic.Types

Show MagicParam Source # 
Instance details

Defined in Magic.Types

Methods

showsPrec :: Int -> MagicParam -> ShowS

show :: MagicParam -> String

showList :: [MagicParam] -> ShowS

Eq MagicParam Source # 
Instance details

Defined in Magic.Types

Methods

(==) :: MagicParam -> MagicParam -> Bool

(/=) :: MagicParam -> MagicParam -> Bool

Ord MagicParam Source # 
Instance details

Defined in Magic.Types