zydiskell: Haskell language binding for the Zydis library, a x86/x86-64 disassembler.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/nerded1337/zydiskell#readme


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.0.1, 0.1.1.0, 0.2.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <4.15), bytestring (>=0.10 && <0.11), storable-record (>=0.0.5 && <0.0.6), vector (>=0.12 && <0.13) [details]
License GPL-3.0-only
Copyright 2020 nerded
Author nerded
Maintainer nerded.nerded@gmail.com
Category System, Parsing, Disassembler
Home page https://github.com/nerded1337/zydiskell#readme
Bug tracker https://github.com/nerded1337/zydiskell/issues
Source repo head: git clone https://github.com/nerded1337/zydiskell
Uploaded by nerded at 2020-11-18T13:45:30Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for zydiskell-0.1.0.0

[back to package description]

Zydiskell

Haskell langage binding for the Zydis library, a fast and lightweight x86/x86-64 disassembler.

Building

Note: The Zydis library will be directly compiled by GHC.

Interface

We currently expose three functions:

import qualified Zydis as Z

Z.initialize :: MachineMode -> AddressWidth -> IO (Either ZyanStatus Decoder)

Z.decodeBuffer
  :: Decoder
  -> ByteString
  -> Offset
  -> Length
  -> IO (Either ZyanStatus DecodedInstruction)

Z. decodeFullBuffer
  :: Decoder -> ByteString -> IO (Either ZyanStatus (Vector DecodedInstruction))

Example

{-# LANGUAGE OverloadedStrings #-}

module Main where

import           Data.Bitraversable
import           Data.Bifoldable
import qualified Zydis                         as Z

main :: IO ()
main = test

test :: IO ()
test = bitraverse_ initFailure decode =<< initZydis
 where
  zyanError s = putStrLn . ((s <> ". ZyanStatus: ") <>) . show

  initFailure     = zyanError "Failed to initialize decoder"

  initZydis       = Z.initialize Z.MachineModeLong64 Z.AddressWidth64

  {-
     mov rax, 0xCAFEBABECAFEBABE
     push rax
     ret
  -}
  buffer          = "\x48\xB8\xBE\xBA\xFE\xCA\xBE\xBA\xFE\xCA\x50\xC3"

  decodingFailure = zyanError "Failed to decode buffer"

  {-
      Given the decoded buffer, should output: [MnemonicMov,MnemonicPush,MnemonicRet]
  -}
  printMnemonics  = print . fmap Z.decodedInstructionMnemonic

  decode decoder =
    bitraverse decodingFailure printMnemonics
      =<< Z.decodeFullBuffer decoder buffer