| Copyright | (c) Inokentiy Babushkin 2016 |
|---|---|
| License | BSD3 |
| Maintainer | Inokentiy Babushkin <inokentiy.babushkin@googlemail.com> |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Hapstone.Internal.Capstone
Description
This module contains capstone's public API, with the necessary datatypes and functions, and some boilerplate to make it usable. Thus, it exposes an IO-based interface to capstone, which is a rough 1:1 translation of the capstone C header to Haskell. Obviously, it isn't very ideomatic to use, so a higher-level API is present in Hapstone.Capstone. The approach there is to wrap all necessary cleanup and initialization and expose an ideomatic (but heavily abstracted) interface to capstone.
This module, on the other hand, is intended to be used when performance is more critical or greater versatility is needed. This means that the abstractions introduced in the C version of the library are still present, but their use has been restricted to provide more reasonable levels of safety.
Synopsis
- type Csh = CSize
- data CsArch
- data CsSupport
- data CsMode
- = CsModeLittleEndian
- | CsModeArm
- | CsMode16
- | CsModeM68k000
- | CsModeM680x6301
- | CsMode32
- | CsModeM68k010
- | CsModeMips32
- | CsModeM680x6309
- | CsMode64
- | CsModeM68k020
- | CsModeMips64
- | CsModeM680x6800
- | CsModeThumb
- | CsModeMicro
- | CsModeV9
- | CsModeQpx
- | CsModeM68k030
- | CsModeM680x6801
- | CsModeMclass
- | CsModeMips3
- | CsModeM68k040
- | CsModeM680x6805
- | CsModeV8
- | CsModeMips32r6
- | CsModeM68k060
- | CsModeM680x6808
- | CsModeMips2
- | CsModeM680x6809
- | CsModeM680x6811
- | CsModeM680xCpu12
- | CsModeM680xHcs08
- | CsModeBigEndian
- data CsOption
- data CsOptionState
- data CsOperand
- = CsOpInvalid
- | CsOpReg
- | CsOpImm
- | CsOpMem
- | CsOpFp
- data CsGroup
- type CsSkipdataCallback = FunPtr (Ptr Word8 -> CSize -> CSize -> Ptr () -> IO CSize)
- data CsSkipdataStruct = CsSkipdataStruct String CsSkipdataCallback (Ptr ())
- csSetSkipdata :: Csh -> Maybe CsSkipdataStruct -> IO CsErr
- data ArchInfo
- data CsDetail = CsDetail {}
- peekDetail :: CsArch -> Ptr CsDetail -> IO CsDetail
- data CsInsn = CsInsn {}
- peekArch :: CsArch -> Ptr CsInsn -> IO CsInsn
- peekArrayArch :: CsArch -> Int -> Ptr CsInsn -> IO [CsInsn]
- csInsnOffset :: Ptr CsInsn -> Int -> Int
- data CsErr
- csSupport :: Enum a => a -> Bool
- csOpen :: CsArch -> [CsMode] -> IO (CsErr, Csh)
- csClose :: Csh -> IO CsErr
- csOption :: Enum a => Csh -> CsOption -> a -> IO CsErr
- csErrno :: Csh -> IO CsErr
- csStrerror :: CsErr -> String
- csDisasm :: CsArch -> Csh -> [Word8] -> Word64 -> Int -> IO [CsInsn]
- csDisasmIter :: Csh -> [Word8] -> Word64 -> IO ([Word8], Word64, Either CsErr CsInsn)
- csFree :: Ptr CsInsn -> Int -> IO ()
- csMalloc :: Csh -> IO (Ptr CsInsn)
- csRegName :: Enum e => Csh -> e -> Maybe String
- csInsnName :: Enum e => Csh -> e -> Maybe String
- csGroupName :: Enum e => Csh -> e -> Maybe String
- csInsnGroup :: Csh -> CsInsn -> Bool
- csRegRead :: Csh -> CsInsn -> Int -> Bool
- csRegWrite :: Csh -> CsInsn -> Int -> Bool
- csOpCount :: Csh -> CsInsn -> Int -> Int
- csOpIndex :: Csh -> CsInsn -> Int -> Int -> Int
Datatypes
supported architectures
Constructors
| CsArchArm | |
| CsArchArm64 | |
| CsArchMips | |
| CsArchX86 | |
| CsArchPpc | |
| CsArchSparc | |
| CsArchSysz | |
| CsArchXcore | |
| CsArchM68k | |
| CsArchTms320c64x | |
| CsArchM680x | |
| CsArchEvm | |
| CsArchMax | |
| CsArchAll |
support constants
Constructors
| CsSupportDiet | |
| CsSupportX86Reduce |
Instances
| Bounded CsSupport Source # | |
| Enum CsSupport Source # | |
Defined in Hapstone.Internal.Capstone Methods succ :: CsSupport -> CsSupport # pred :: CsSupport -> CsSupport # fromEnum :: CsSupport -> Int # enumFrom :: CsSupport -> [CsSupport] # enumFromThen :: CsSupport -> CsSupport -> [CsSupport] # enumFromTo :: CsSupport -> CsSupport -> [CsSupport] # enumFromThenTo :: CsSupport -> CsSupport -> CsSupport -> [CsSupport] # | |
| Eq CsSupport Source # | |
| Show CsSupport Source # | |
working modes
Constructors
options are, interestingly, represented by different types: an option
Constructors
| CsOptInvalid | |
| CsOptSyntax | |
| CsOptDetail | |
| CsOptMode | |
| CsOptMem | |
| CsOptSkipdata | |
| CsOptSkipdataSetup | |
| CsOptMnemonic | |
| CsOptUnsigned |
Instances
| Bounded CsOption Source # | |
| Enum CsOption Source # | |
Defined in Hapstone.Internal.Capstone | |
| Eq CsOption Source # | |
| Show CsOption Source # | |
data CsOptionState Source #
... and a state of an option
Constructors
| CsOptOff | |
| CsOptSyntaxDefault | |
| CsOptSyntaxIntel | |
| CsOptSyntaxAtt | |
| CsOptOn | |
| CsOptSyntaxNoregname | |
| CsOptSyntaxMasm |
Instances
| Bounded CsOptionState Source # | |
Defined in Hapstone.Internal.Capstone | |
| Enum CsOptionState Source # | |
Defined in Hapstone.Internal.Capstone Methods succ :: CsOptionState -> CsOptionState # pred :: CsOptionState -> CsOptionState # toEnum :: Int -> CsOptionState # fromEnum :: CsOptionState -> Int # enumFrom :: CsOptionState -> [CsOptionState] # enumFromThen :: CsOptionState -> CsOptionState -> [CsOptionState] # enumFromTo :: CsOptionState -> CsOptionState -> [CsOptionState] # enumFromThenTo :: CsOptionState -> CsOptionState -> CsOptionState -> [CsOptionState] # | |
| Eq CsOptionState Source # | |
Defined in Hapstone.Internal.Capstone Methods (==) :: CsOptionState -> CsOptionState -> Bool # (/=) :: CsOptionState -> CsOptionState -> Bool # | |
| Show CsOptionState Source # | |
Defined in Hapstone.Internal.Capstone Methods showsPrec :: Int -> CsOptionState -> ShowS # show :: CsOptionState -> String # showList :: [CsOptionState] -> ShowS # | |
arch-uniting operand type
Constructors
| CsOpInvalid | |
| CsOpReg | |
| CsOpImm | |
| CsOpMem | |
| CsOpFp |
Instances
| Bounded CsOperand Source # | |
| Enum CsOperand Source # | |
Defined in Hapstone.Internal.Capstone Methods succ :: CsOperand -> CsOperand # pred :: CsOperand -> CsOperand # fromEnum :: CsOperand -> Int # enumFrom :: CsOperand -> [CsOperand] # enumFromThen :: CsOperand -> CsOperand -> [CsOperand] # enumFromTo :: CsOperand -> CsOperand -> [CsOperand] # enumFromThenTo :: CsOperand -> CsOperand -> CsOperand -> [CsOperand] # | |
| Eq CsOperand Source # | |
| Show CsOperand Source # | |
arch-uniting instruction group type
Constructors
| CsGrpInvalid | |
| CsGrpJump | |
| CsGrpCall | |
| CsGrpRet | |
| CsGrpInt | |
| CsGrpIret | |
| CsGrpPrivilege | |
| CsGrpBranchRelative |
Instances
| Bounded CsGroup Source # | |
| Enum CsGroup Source # | |
| Eq CsGroup Source # | |
| Show CsGroup Source # | |
Skipdata setup
SKIPDATA is an option supported by the capstone disassembly engine, that allows to skip data which can't be disassembled and to represent it in form of pseudo-instructions. The types and functions given here attempt to mirror capstone's setup of this option, and a more high-level interface is available in Hapstone.Capstone.
type CsSkipdataCallback = FunPtr (Ptr Word8 -> CSize -> CSize -> Ptr () -> IO CSize) Source #
callback type for user-defined SKIPDATA work
data CsSkipdataStruct Source #
user-defined SKIPDATA setup
Constructors
| CsSkipdataStruct String CsSkipdataCallback (Ptr ()) |
Instances
| Eq CsSkipdataStruct Source # | |
Defined in Hapstone.Internal.Capstone Methods (==) :: CsSkipdataStruct -> CsSkipdataStruct -> Bool # (/=) :: CsSkipdataStruct -> CsSkipdataStruct -> Bool # | |
| Show CsSkipdataStruct Source # | |
Defined in Hapstone.Internal.Capstone Methods showsPrec :: Int -> CsSkipdataStruct -> ShowS # show :: CsSkipdataStruct -> String # showList :: [CsSkipdataStruct] -> ShowS # | |
| Storable CsSkipdataStruct Source # | |
Defined in Hapstone.Internal.Capstone Methods sizeOf :: CsSkipdataStruct -> Int # alignment :: CsSkipdataStruct -> Int # peekElemOff :: Ptr CsSkipdataStruct -> Int -> IO CsSkipdataStruct # pokeElemOff :: Ptr CsSkipdataStruct -> Int -> CsSkipdataStruct -> IO () # peekByteOff :: Ptr b -> Int -> IO CsSkipdataStruct # pokeByteOff :: Ptr b -> Int -> CsSkipdataStruct -> IO () # peek :: Ptr CsSkipdataStruct -> IO CsSkipdataStruct # poke :: Ptr CsSkipdataStruct -> CsSkipdataStruct -> IO () # | |
csSetSkipdata :: Csh -> Maybe CsSkipdataStruct -> IO CsErr Source #
safely set SKIPDATA options (reset on Nothing)
Instruction representation
architecture specific information
Constructors
| X86 CsX86 | x86 architecture |
| Arm64 CsArm64 | ARM64 architecture |
| Arm CsArm | ARM architecture |
| Mips CsMips | MIPS architecture |
| Ppc CsPpc | PPC architecture |
| Sparc CsSparc | SPARC architecture |
| SysZ CsSysZ | SystemZ architecture |
| XCore CsXCore | XCore architecture |
The union holding architecture-specific info is not tagged. Thus, we have no way to determine what kind of data is stored in it without resorting to some kind of context lookup, as the corresponding C code would do. Thus, the peek implementation does not get architecture information, use peekDetail for that.
instruction information
Constructors
| CsDetail | |
Instances
| Eq CsDetail Source # | |
| Show CsDetail Source # | |
| Storable CsDetail Source # | |
Defined in Hapstone.Internal.Capstone | |
instructions
Constructors
| CsInsn | |
Instances
| Eq CsInsn Source # | |
| Show CsInsn Source # | |
| Storable CsInsn Source # | |
peekArrayArch :: CsArch -> Int -> Ptr CsInsn -> IO [CsInsn] Source #
an arch-sensitive peekArray for cs_insn
Capstone API
possible error conditions
Constructors
| CsErrOk | |
| CsErrMem | |
| CsErrArch | |
| CsErrHandle | |
| CsErrCsh | |
| CsErrMode | |
| CsErrOption | |
| CsErrDetail | |
| CsErrMemsetup | |
| CsErrVersion | |
| CsErrDiet | |
| CsErrSkipdata | |
| CsErrX86Att | |
| CsErrX86Intel | |
| CsErrX86Masm |
csStrerror :: CsErr -> String Source #
get the description of an error
csDisasmIter :: Csh -> [Word8] -> Word64 -> IO ([Word8], Word64, Either CsErr CsInsn) Source #
disassemble one instruction at a time
csRegRead :: Csh -> CsInsn -> Int -> Bool Source #
check whether an instruction reads from a register
csRegWrite :: Csh -> CsInsn -> Int -> Bool Source #
check whether an instruction writes to a register