Small changes to align with hapstone (Haskell bindings for Capstone)

Enums now derive bounded and made use of Applicative in Utils module
This commit is contained in:
Adrian Herrera 2016-04-09 00:13:25 +10:00
parent 023e4375d0
commit 0a3f83a20c
10 changed files with 18 additions and 17 deletions

View file

@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
omit (UC_ARM_REG_INVALID,
UC_ARM_REG_ENDING)
with prefix="UC_ARM_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register

View file

@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
omit (UC_ARM64_REG_INVALID,
UC_ARM64_REG_ENDING)
with prefix="UC_ARM64_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register

View file

@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
omit (UC_M68K_REG_INVALID,
UC_M68K_REG_ENDING)
with prefix="UC_M68K_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register

View file

@ -56,6 +56,6 @@ import Unicorn.Internal.Core (Reg)
omit (UC_MIPS_REG_INVALID,
UC_MIPS_REG_ENDING)
with prefix="UC_MIPS_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register

View file

@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
omit (UC_SPARC_REG_INVALID,
UC_SPARC_REG_ENDING)
with prefix="UC_SPARC_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register

View file

@ -52,7 +52,7 @@ instance Storable Mmr where
omit (UC_X86_REG_INVALID,
UC_X86_REG_ENDING)
with prefix="UC_X86_REG_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
instance Reg Register
@ -62,4 +62,4 @@ instance Reg Register
omit (UC_X86_INS_INVALID,
UC_X86_INS_ENDING)
with prefix="UC_X86_INS_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}

View file

@ -42,7 +42,7 @@ mkEngine ptr =
{# enum uc_err as Error
{underscoreToCase}
with prefix = "UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | The emulator runs in the IO monad and allows for the handling of errors
-- "under the hood".

View file

@ -103,7 +103,7 @@ type Hook = {# type uc_hook #}
UC_HOOK_MEM_WRITE,
UC_HOOK_MEM_FETCH)
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | Memory hook types (for valid memory accesses).
{# enum uc_hook_type as MemoryHookType
@ -119,7 +119,7 @@ type Hook = {# type uc_hook #}
UC_HOOK_MEM_WRITE_PROT,
UC_HOOK_MEM_FETCH_PROT)
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | Memory event hook types (for invalid memory accesses).
{# enum uc_hook_type as MemoryEventHookType
@ -132,7 +132,7 @@ type Hook = {# type uc_hook #}
UC_HOOK_MEM_WRITE,
UC_HOOK_MEM_FETCH)
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | Unify the hook types with a type class
class Enum a => HookTypeC a
@ -145,7 +145,7 @@ instance HookTypeC MemoryEventHookType
{# enum uc_mem_type as MemoryAccess
{underscoreToCase}
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-------------------------------------------------------------------------------
-- Hook callbacks

View file

@ -61,19 +61,19 @@ import Unicorn.Internal.Util
{# enum uc_arch as Architecture
{underscoreToCase}
with prefix = "UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | CPU hardware mode.
{# enum uc_mode as Mode
{underscoreToCase}
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | Memory permissions.
{# enum uc_prot as MemoryPermission
{underscoreToCase}
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-- | Memory region mapped by 'memMap'. Retrieve the list of memory regions with
-- 'memRegions'.
@ -102,7 +102,7 @@ instance Storable MemoryRegion where
{# enum uc_query_type as QueryType
{underscoreToCase}
with prefix="UC_"
deriving (Show, Eq) #}
deriving (Show, Eq, Bounded) #}
-------------------------------------------------------------------------------
-- Emulator control

View file

@ -6,13 +6,14 @@ License : GPL-2
-}
module Unicorn.Internal.Util where
import Control.Applicative
import Data.Bits
import Foreign
-- | Combine a list of Enums by performing a bitwise-OR.
combineEnums :: (Enum a, Num b, Bits b) => [a] -> b
combineEnums =
foldr (\p -> (.|.) (enumToNum p)) 0
foldr ((.|.) <$> enumToNum) 0
-- | Cast a pointer and then peek inside it.
castPtrAndPeek :: Storable a => Ptr b -> IO a