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

[ disassembler, gpl, library, parsing, system ] [ Propose Tags ]
Versions [RSS] 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), fixed-vector (>=1.2 && <1.3), 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-18T17:56:51Z
Distributions
Downloads 549 total (18 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for zydiskell-0.1.0.1

[back to package description]

Zydiskell

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

Building

  • Recursively clone the project: git clone --recursive https://github.com/nerded1337/zydiskell
  • Either use Stack or Cabal: stack build | cabal v2-build

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