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

Magic.Types

Description

The core types of the binding: the opaque Magic handle, the MagicException error type (both defined in Magic.Internal), and the MagicParam tunables. The flag bit-mask lives in Magic.Data.

Synopsis

Documentation

data Magic 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; there is no need to close them explicitly.

Thread safety. Operations on a single handle are serialised by an internal lock, so it is safe to share one handle across threads (concurrent calls simply take turns). For genuine parallelism, use one handle per thread; distinct handles are independent. Programs doing blocking work (loading databases, examining files) should use the threaded runtime (-threaded).

Instances

Instances details
Show Magic Source #

The handle is opaque; it shows as a fixed placeholder.

Instance details

Defined in Magic.Internal

Methods

showsPrec :: Int -> Magic -> ShowS

show :: Magic -> String

showList :: [Magic] -> ShowS

data MagicException Source #

The exception raised when a libmagic operation fails. Carries the name of the operation that failed and the message reported by libmagic.

Since: 2.0.0

Constructors

MagicException 

Fields

Instances

Instances details
NFData MagicException Source # 
Instance details

Defined in Magic.Internal

Methods

rnf :: MagicException -> ()

Exception MagicException Source # 
Instance details

Defined in Magic.Internal

Methods

toException :: MagicException -> SomeException

fromException :: SomeException -> Maybe MagicException

displayException :: MagicException -> String

backtraceDesired :: MagicException -> Bool

Generic MagicException Source # 
Instance details

Defined in Magic.Internal

Associated Types

type Rep MagicException 
Instance details

Defined in Magic.Internal

type Rep MagicException = D1 ('MetaData "MagicException" "Magic.Internal" "magic-2.0.0-A9TYcUdA1HUI3Y62VpQyfB" 'False) (C1 ('MetaCons "MagicException" 'PrefixI 'True) (S1 ('MetaSel ('Just "magicErrorContext") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "magicErrorMessage") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))
Show MagicException Source # 
Instance details

Defined in Magic.Internal

Methods

showsPrec :: Int -> MagicException -> ShowS

show :: MagicException -> String

showList :: [MagicException] -> ShowS

Eq MagicException Source # 
Instance details

Defined in Magic.Internal

type Rep MagicException Source # 
Instance details

Defined in Magic.Internal

type Rep MagicException = D1 ('MetaData "MagicException" "Magic.Internal" "magic-2.0.0-A9TYcUdA1HUI3Y62VpQyfB" 'False) (C1 ('MetaCons "MagicException" 'PrefixI 'True) (S1 ('MetaSel ('Just "magicErrorContext") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "magicErrorMessage") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))

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
NFData MagicParam Source # 
Instance details

Defined in Magic.Types

Methods

rnf :: MagicParam -> ()

Bounded MagicParam Source # 
Instance details

Defined in Magic.Types

Enum MagicParam Source # 
Instance details

Defined in Magic.Types

Generic MagicParam Source # 
Instance details

Defined in Magic.Types

Associated Types

type Rep MagicParam 
Instance details

Defined in Magic.Types

type Rep MagicParam = D1 ('MetaData "MagicParam" "Magic.Types" "magic-2.0.0-A9TYcUdA1HUI3Y62VpQyfB" 'False) (((C1 ('MetaCons "MagicParamIndirMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamNameMax" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MagicParamElfPhnumMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamElfShnumMax" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MagicParamElfNotesMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamRegexMax" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MagicParamBytesMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "MagicParamEncodingMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamElfShsizeMax" 'PrefixI 'False) (U1 :: Type -> Type)))))

Methods

from :: MagicParam -> Rep MagicParam x

to :: Rep MagicParam x -> MagicParam

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

type Rep MagicParam Source # 
Instance details

Defined in Magic.Types

type Rep MagicParam = D1 ('MetaData "MagicParam" "Magic.Types" "magic-2.0.0-A9TYcUdA1HUI3Y62VpQyfB" 'False) (((C1 ('MetaCons "MagicParamIndirMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamNameMax" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MagicParamElfPhnumMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamElfShnumMax" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MagicParamElfNotesMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamRegexMax" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MagicParamBytesMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "MagicParamEncodingMax" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MagicParamElfShsizeMax" 'PrefixI 'False) (U1 :: Type -> Type)))))