Interface to the
The goal at this level of wrapping is to provide the maximum feature-set from the underlying C library, with the minimum of C-related headaches. Therefore, this module's API is thoroughly imperative, but uses Haskellish types and automatic resource management.
For a higher-level,
IO-free API, see Hdis86.Pure.
This module is fully thread-safe: any number of threads
may manipulate one or several
objects at the same
time. The individual operations exported by this module
are guaranteed to be atomic.
- data UD
- newUD :: IO UD
- setInputBuffer :: UD -> ByteString -> IO ()
- type InputHook = IO (Maybe Word8)
- setInputHook :: UD -> InputHook -> IO ()
- unsetInput :: UD -> IO ()
- advance :: UD -> IO (Maybe Word)
- skip :: UD -> Word -> IO ()
- setIP :: UD -> Word64 -> IO ()
- run :: UD -> IO a -> IO [a]
- getInstruction :: UD -> IO Instruction
- getLength :: UD -> IO Word
- getOffset :: UD -> IO Word64
- getHex :: UD -> IO String
- getBytes :: UD -> IO ByteString
- getAssembly :: UD -> IO String
- getMetadata :: UD -> IO Metadata
- setConfig :: UD -> Config -> IO ()
- setVendor :: UD -> Vendor -> IO ()
- setCPUMode :: UD -> CPUMode -> IO ()
- setSyntax :: UD -> Syntax -> IO ()
- setCallback :: UD -> IO () -> IO ()
- unsafeSetInputPtr :: UD -> Ptr Word8 -> Word -> IO ()
- unsafeRunLazy :: UD -> IO a -> IO [a]
Create a new disassembler instance.
There is no
deleteUD. Associated resources will be freed automatically
value becomes unreachable.
A custom input source.
Each time this action is executed, it should return a single byte of
if there are no more bytes to read.
to provide machine code to disassemble.
Disassemble the next instruction and return its length in bytes, or
if there are no more instructions.
Set the instruction pointer, i.e. the disassembler's idea of where the current instruction would live in memory.
Inspecting the output
Get the offset of the current instruction. This value is set
and updated after each call to
Get the current instruction's machine code as a
The bytes are copied out of internal state.
Get the assembly syntax for the current instruction.
Get all metadata about the current instruction, along with the instruction itself.
Set the assembly syntax to be used by
This takes effect after the next call to
Set up the
instance to read directly from memory.
Given are a pointer to a memory region, and the length of that region.
This is an unsafe operation because the contents of the memory region might change, especially if it's part of the heap managed by GHC's garbage collector.
You are responsible for ensuring that the memory pointed to does not
change or become invalid until another input source is selected.
You cannot rely on garbage collection of the
finalization may be delayed arbitrarily long after the value becomes
It should be safe to use this on the static code segment of your process, which is useful when your Haskell program needs to disassemble itself.