refactored code and minor bug fixing

This commit is contained in:
enkomio
2016-01-04 11:30:11 +01:00
parent 232cff02d2
commit 5d3aac30e6
39 changed files with 3176 additions and 2847 deletions

View File

@@ -0,0 +1,41 @@
namespace UnicornManaged.AssemblyInfo
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("UnicornManaged")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("UnicornManaged")>]
[<assembly: AssemblyCopyright("Copyright © Antonio Parata 2016")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("0c21f1c1-2725-4a46-9022-1905f85822a5")>]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [<assembly: AssemblyVersion("1.0.*")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
()

View File

@@ -0,0 +1,13 @@
namespace UnicornManaged.Binding
open System
module BindingFactory =
let mutable _instance = NativeBinding.instance
let setDefaultBinding(binding: IBinding) =
_instance <- binding
let getDefault() =
_instance

View File

@@ -0,0 +1,28 @@
namespace UnicornManaged.Binding
open System
type IBinding =
interface
abstract Version : UIntPtr * UIntPtr -> Int32
abstract ArchSupported : Int32 -> Boolean
abstract UcOpen : UInt32 * UInt32 * UIntPtr array -> Int32
abstract Close : UIntPtr -> Int32
abstract Strerror : Int32 -> IntPtr
abstract Errono : UIntPtr -> Int32
abstract RegRead : UIntPtr * Int32 * Byte array -> Int32
abstract RegWrite : UIntPtr * Int32 * Byte array -> Int32
abstract MemRead : UIntPtr * UInt64 * Byte array * UIntPtr -> Int32
abstract MemWrite : UIntPtr * UInt64 * Byte array * UIntPtr -> Int32
abstract EmuStart : UIntPtr * UInt64 * UInt64 * UInt64 * UInt64 -> Int32
abstract EmuStop : UIntPtr -> Int32
abstract HookDel : UIntPtr * UIntPtr -> Int32
abstract MemMap : UIntPtr * UInt64 * UIntPtr * UInt32 -> Int32
abstract MemMapPtr : UIntPtr * UInt64 * UIntPtr * UInt32 * UIntPtr -> Int32
abstract MemUnmap : UIntPtr * UInt64 * UIntPtr -> Int32
abstract MemProtect : UIntPtr * UInt64 * UIntPtr * UInt32 -> Int32
abstract HookAddNoarg : UIntPtr * UIntPtr * Int32 * UIntPtr * IntPtr -> Int32
abstract HookAddArg0 : UIntPtr * UIntPtr * Int32 * UIntPtr * IntPtr * IntPtr -> Int32
abstract HookAddArg0Arg1 : UIntPtr * UIntPtr * Int32 * UIntPtr * IntPtr * UInt64 * UInt64 -> Int32
end

View File

@@ -0,0 +1,51 @@
namespace UnicornManaged.Binding
open System
module internal MockBinding =
// by using a mutables variables it is easier to create testing code
let mutable version = fun(major, minor) -> 0
let mutable uc_open = fun(arch, mode, uc) -> 0
let mutable close = fun(eng) -> 0
let mutable mem_map = fun(eng, adress, size, perm) -> 0
let mutable mem_map_ptr = fun(eng, address, size, perms, ptr) -> 0
let mutable mem_unmap = fun(eng, address, size) -> 0
let mutable mem_protect = fun(eng, address, size, perms) -> 0
let mutable mem_write = fun(eng, adress, value, size) -> 0
let mutable mem_read = fun(eng, adress, value, size) -> 0
let mutable reg_write = fun(eng, regId, value) -> 0
let mutable reg_read = fun(eng, regId, value) -> 0
let mutable emu_start = fun(eng, beginAddr, untilAddr, timeout, count) -> 0
let mutable emu_stop = fun(eng) -> 0
let mutable hook_del = fun(eng, hook) -> 0
let mutable arch_supported = fun(arch) -> true
let mutable errno = fun(eng) -> 0
let mutable strerror = fun(err) -> new nativeint(0)
let mutable hook_add_noarg = fun(eng, hh, callbackType, callback, userData) -> 0
let mutable hook_add_arg0 = fun(eng, hh, callbackType, callback, userData, arg0) -> 0
let mutable hook_add_arg0_arg1 = fun(eng, hh, callbackType, callback, userData, arg0, arg1) -> 0
let instance =
{new IBinding with
member thi.Version(major, minor) = version(major, minor)
member thi.UcOpen(arch, mode, uc) = uc_open(arch, mode, uc)
member thi.Close(eng) = close(eng)
member thi.MemMap(eng, adress, size, perm) = mem_map(eng, adress, size, perm)
member thi.MemWrite(eng, adress, value, size) = mem_write(eng, adress, value, size)
member thi.MemRead(eng, adress, value, size) = mem_read(eng, adress, value, size)
member thi.RegWrite(eng, regId, value) = reg_write(eng, regId, value)
member thi.RegRead(eng, regId, value) = reg_read(eng, regId, value)
member thi.EmuStart(eng, beginAddr, untilAddr, timeout, count) = emu_start(eng, beginAddr, untilAddr, timeout, count)
member thi.EmuStop(eng) = emu_stop(eng)
member this.HookDel(eng, hook) = hook_del(eng, hook)
member thi.ArchSupported(arch) = arch_supported(arch)
member thi.Errono(eng) = errno(eng)
member thi.Strerror(err) = strerror(err)
member this.MemMapPtr(eng, address, size, perms, ptr) = mem_map_ptr(eng, address, size, perms, ptr)
member this.MemUnmap(eng, address, size) = mem_unmap(eng, address, size)
member this.MemProtect(eng, address, size, perms) = mem_protect(eng, address, size, perms)
member thi.HookAddNoarg(eng, hh, callbackType, callback, userData) = hook_add_noarg(eng, hh, callbackType, callback, userData)
member thi.HookAddArg0(eng, hh, callbackType, callback, userData, arg0) = hook_add_arg0(eng, hh, callbackType, callback, userData, arg0)
member thi.HookAddArg0Arg1(eng, hh, callbackType, callback, userData, arg0, arg1) = hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, arg0, arg1)
}

View File

@@ -0,0 +1,93 @@
namespace UnicornManaged.Binding
open System
open System.Runtime.InteropServices
module NativeBinding =
[<AutoOpen>]
module private Imported =
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_version(UIntPtr major, UIntPtr minor)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_open(UInt32 arch, UInt32 mode, UIntPtr[] engine)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_close(UIntPtr eng)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_map(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perm)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_map_ptr(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perm, UIntPtr ptr)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_unmap(UIntPtr eng, UInt64 address, UIntPtr size)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_protect(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perms)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_write(UIntPtr eng, UInt64 address, Byte[] value, UIntPtr size)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_mem_read(UIntPtr eng, UInt64 address, Byte[] value, UIntPtr size)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_reg_write(UIntPtr eng, Int32 regId, Byte[] value)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_reg_read(UIntPtr eng, Int32 regId, Byte[] value)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_emu_start(UIntPtr eng, UInt64 beginAddr, UInt64 untilAddr, UInt64 timeout, UInt64 count)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_emu_stop(UIntPtr eng)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_hook_del(UIntPtr eng, UIntPtr hook)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Boolean uc_arch_supported(Int32 arch)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern Int32 uc_errno(UIntPtr eng)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>]
extern IntPtr uc_strerror(Int32 err)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uc_hook_add")>]
extern Int32 uc_hook_add_noarg(UIntPtr eng, UIntPtr hh, Int32 callbackType, UIntPtr callback, IntPtr userData)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uc_hook_add")>]
extern Int32 uc_hook_add_arg0(UIntPtr eng, UIntPtr hh, Int32 callbackType, UIntPtr callback, IntPtr userData, IntPtr arg0)
[<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl, EntryPoint = "uc_hook_add")>]
extern Int32 uc_hook_add_arg0_arg1(UIntPtr eng, UIntPtr hh, Int32 callbackType, UIntPtr callback, IntPtr userData, UInt64 arg0, UInt64 arg1)
let instance =
{new IBinding with
member thi.Version(major, minor) = uc_version(major, minor)
member thi.UcOpen(arch, mode, uc) = uc_open(arch, mode, uc)
member thi.Close(eng) = uc_close(eng)
member thi.MemMap(eng, adress, size, perm) = uc_mem_map(eng, adress, size, perm)
member thi.MemWrite(eng, adress, value, size) = uc_mem_write(eng, adress, value, size)
member thi.MemRead(eng, adress, value, size) = uc_mem_read(eng, adress, value, size)
member thi.RegWrite(eng, regId, value) = uc_reg_write(eng, regId, value)
member thi.RegRead(eng, regId, value) = uc_reg_read(eng, regId, value)
member thi.EmuStart(eng, beginAddr, untilAddr, timeout, count) = uc_emu_start(eng, beginAddr, untilAddr, timeout, count)
member thi.EmuStop(eng) = uc_emu_stop(eng)
member this.HookDel(eng, hook) = uc_hook_del(eng, hook)
member thi.ArchSupported(arch) = uc_arch_supported(arch)
member thi.Errono(eng) = uc_errno(eng)
member thi.Strerror(err) = uc_strerror(err)
member this.MemMapPtr(eng, address, size, perms, ptr) = uc_mem_map_ptr(eng, address, size, perms, ptr)
member this.MemUnmap(eng, address, size) = uc_mem_unmap(eng, address, size)
member this.MemProtect(eng, address, size, perms) = uc_mem_protect(eng, address, size, perms)
member thi.HookAddNoarg(eng, hh, callbackType, callback, userData) = uc_hook_add_noarg(eng, hh, callbackType, callback, userData)
member thi.HookAddArg0(eng, hh, callbackType, callback, userData, arg0) = uc_hook_add_arg0(eng, hh, callbackType, callback, userData, arg0)
member thi.HookAddArg0Arg1(eng, hh, callbackType, callback, userData, arg0, arg1) = uc_hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, arg0, arg1)
}

View File

@@ -0,0 +1,133 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module Arm =
// ARM registers
let UC_ARM_REG_INVALID = 0
let UC_ARM_REG_APSR = 1
let UC_ARM_REG_APSR_NZCV = 2
let UC_ARM_REG_CPSR = 3
let UC_ARM_REG_FPEXC = 4
let UC_ARM_REG_FPINST = 5
let UC_ARM_REG_FPSCR = 6
let UC_ARM_REG_FPSCR_NZCV = 7
let UC_ARM_REG_FPSID = 8
let UC_ARM_REG_ITSTATE = 9
let UC_ARM_REG_LR = 10
let UC_ARM_REG_PC = 11
let UC_ARM_REG_SP = 12
let UC_ARM_REG_SPSR = 13
let UC_ARM_REG_D0 = 14
let UC_ARM_REG_D1 = 15
let UC_ARM_REG_D2 = 16
let UC_ARM_REG_D3 = 17
let UC_ARM_REG_D4 = 18
let UC_ARM_REG_D5 = 19
let UC_ARM_REG_D6 = 20
let UC_ARM_REG_D7 = 21
let UC_ARM_REG_D8 = 22
let UC_ARM_REG_D9 = 23
let UC_ARM_REG_D10 = 24
let UC_ARM_REG_D11 = 25
let UC_ARM_REG_D12 = 26
let UC_ARM_REG_D13 = 27
let UC_ARM_REG_D14 = 28
let UC_ARM_REG_D15 = 29
let UC_ARM_REG_D16 = 30
let UC_ARM_REG_D17 = 31
let UC_ARM_REG_D18 = 32
let UC_ARM_REG_D19 = 33
let UC_ARM_REG_D20 = 34
let UC_ARM_REG_D21 = 35
let UC_ARM_REG_D22 = 36
let UC_ARM_REG_D23 = 37
let UC_ARM_REG_D24 = 38
let UC_ARM_REG_D25 = 39
let UC_ARM_REG_D26 = 40
let UC_ARM_REG_D27 = 41
let UC_ARM_REG_D28 = 42
let UC_ARM_REG_D29 = 43
let UC_ARM_REG_D30 = 44
let UC_ARM_REG_D31 = 45
let UC_ARM_REG_FPINST2 = 46
let UC_ARM_REG_MVFR0 = 47
let UC_ARM_REG_MVFR1 = 48
let UC_ARM_REG_MVFR2 = 49
let UC_ARM_REG_Q0 = 50
let UC_ARM_REG_Q1 = 51
let UC_ARM_REG_Q2 = 52
let UC_ARM_REG_Q3 = 53
let UC_ARM_REG_Q4 = 54
let UC_ARM_REG_Q5 = 55
let UC_ARM_REG_Q6 = 56
let UC_ARM_REG_Q7 = 57
let UC_ARM_REG_Q8 = 58
let UC_ARM_REG_Q9 = 59
let UC_ARM_REG_Q10 = 60
let UC_ARM_REG_Q11 = 61
let UC_ARM_REG_Q12 = 62
let UC_ARM_REG_Q13 = 63
let UC_ARM_REG_Q14 = 64
let UC_ARM_REG_Q15 = 65
let UC_ARM_REG_R0 = 66
let UC_ARM_REG_R1 = 67
let UC_ARM_REG_R2 = 68
let UC_ARM_REG_R3 = 69
let UC_ARM_REG_R4 = 70
let UC_ARM_REG_R5 = 71
let UC_ARM_REG_R6 = 72
let UC_ARM_REG_R7 = 73
let UC_ARM_REG_R8 = 74
let UC_ARM_REG_R9 = 75
let UC_ARM_REG_R10 = 76
let UC_ARM_REG_R11 = 77
let UC_ARM_REG_R12 = 78
let UC_ARM_REG_S0 = 79
let UC_ARM_REG_S1 = 80
let UC_ARM_REG_S2 = 81
let UC_ARM_REG_S3 = 82
let UC_ARM_REG_S4 = 83
let UC_ARM_REG_S5 = 84
let UC_ARM_REG_S6 = 85
let UC_ARM_REG_S7 = 86
let UC_ARM_REG_S8 = 87
let UC_ARM_REG_S9 = 88
let UC_ARM_REG_S10 = 89
let UC_ARM_REG_S11 = 90
let UC_ARM_REG_S12 = 91
let UC_ARM_REG_S13 = 92
let UC_ARM_REG_S14 = 93
let UC_ARM_REG_S15 = 94
let UC_ARM_REG_S16 = 95
let UC_ARM_REG_S17 = 96
let UC_ARM_REG_S18 = 97
let UC_ARM_REG_S19 = 98
let UC_ARM_REG_S20 = 99
let UC_ARM_REG_S21 = 100
let UC_ARM_REG_S22 = 101
let UC_ARM_REG_S23 = 102
let UC_ARM_REG_S24 = 103
let UC_ARM_REG_S25 = 104
let UC_ARM_REG_S26 = 105
let UC_ARM_REG_S27 = 106
let UC_ARM_REG_S28 = 107
let UC_ARM_REG_S29 = 108
let UC_ARM_REG_S30 = 109
let UC_ARM_REG_S31 = 110
let UC_ARM_REG_ENDING = 111
// alias registers
let UC_ARM_REG_R13 = 12
let UC_ARM_REG_R14 = 10
let UC_ARM_REG_R15 = 11
let UC_ARM_REG_SB = 75
let UC_ARM_REG_SL = 76
let UC_ARM_REG_FP = 77
let UC_ARM_REG_IP = 78

View File

@@ -0,0 +1,282 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module Arm64 =
// ARM64 registers
let UC_ARM64_REG_INVALID = 0
let UC_ARM64_REG_X29 = 1
let UC_ARM64_REG_X30 = 2
let UC_ARM64_REG_NZCV = 3
let UC_ARM64_REG_SP = 4
let UC_ARM64_REG_WSP = 5
let UC_ARM64_REG_WZR = 6
let UC_ARM64_REG_XZR = 7
let UC_ARM64_REG_B0 = 8
let UC_ARM64_REG_B1 = 9
let UC_ARM64_REG_B2 = 10
let UC_ARM64_REG_B3 = 11
let UC_ARM64_REG_B4 = 12
let UC_ARM64_REG_B5 = 13
let UC_ARM64_REG_B6 = 14
let UC_ARM64_REG_B7 = 15
let UC_ARM64_REG_B8 = 16
let UC_ARM64_REG_B9 = 17
let UC_ARM64_REG_B10 = 18
let UC_ARM64_REG_B11 = 19
let UC_ARM64_REG_B12 = 20
let UC_ARM64_REG_B13 = 21
let UC_ARM64_REG_B14 = 22
let UC_ARM64_REG_B15 = 23
let UC_ARM64_REG_B16 = 24
let UC_ARM64_REG_B17 = 25
let UC_ARM64_REG_B18 = 26
let UC_ARM64_REG_B19 = 27
let UC_ARM64_REG_B20 = 28
let UC_ARM64_REG_B21 = 29
let UC_ARM64_REG_B22 = 30
let UC_ARM64_REG_B23 = 31
let UC_ARM64_REG_B24 = 32
let UC_ARM64_REG_B25 = 33
let UC_ARM64_REG_B26 = 34
let UC_ARM64_REG_B27 = 35
let UC_ARM64_REG_B28 = 36
let UC_ARM64_REG_B29 = 37
let UC_ARM64_REG_B30 = 38
let UC_ARM64_REG_B31 = 39
let UC_ARM64_REG_D0 = 40
let UC_ARM64_REG_D1 = 41
let UC_ARM64_REG_D2 = 42
let UC_ARM64_REG_D3 = 43
let UC_ARM64_REG_D4 = 44
let UC_ARM64_REG_D5 = 45
let UC_ARM64_REG_D6 = 46
let UC_ARM64_REG_D7 = 47
let UC_ARM64_REG_D8 = 48
let UC_ARM64_REG_D9 = 49
let UC_ARM64_REG_D10 = 50
let UC_ARM64_REG_D11 = 51
let UC_ARM64_REG_D12 = 52
let UC_ARM64_REG_D13 = 53
let UC_ARM64_REG_D14 = 54
let UC_ARM64_REG_D15 = 55
let UC_ARM64_REG_D16 = 56
let UC_ARM64_REG_D17 = 57
let UC_ARM64_REG_D18 = 58
let UC_ARM64_REG_D19 = 59
let UC_ARM64_REG_D20 = 60
let UC_ARM64_REG_D21 = 61
let UC_ARM64_REG_D22 = 62
let UC_ARM64_REG_D23 = 63
let UC_ARM64_REG_D24 = 64
let UC_ARM64_REG_D25 = 65
let UC_ARM64_REG_D26 = 66
let UC_ARM64_REG_D27 = 67
let UC_ARM64_REG_D28 = 68
let UC_ARM64_REG_D29 = 69
let UC_ARM64_REG_D30 = 70
let UC_ARM64_REG_D31 = 71
let UC_ARM64_REG_H0 = 72
let UC_ARM64_REG_H1 = 73
let UC_ARM64_REG_H2 = 74
let UC_ARM64_REG_H3 = 75
let UC_ARM64_REG_H4 = 76
let UC_ARM64_REG_H5 = 77
let UC_ARM64_REG_H6 = 78
let UC_ARM64_REG_H7 = 79
let UC_ARM64_REG_H8 = 80
let UC_ARM64_REG_H9 = 81
let UC_ARM64_REG_H10 = 82
let UC_ARM64_REG_H11 = 83
let UC_ARM64_REG_H12 = 84
let UC_ARM64_REG_H13 = 85
let UC_ARM64_REG_H14 = 86
let UC_ARM64_REG_H15 = 87
let UC_ARM64_REG_H16 = 88
let UC_ARM64_REG_H17 = 89
let UC_ARM64_REG_H18 = 90
let UC_ARM64_REG_H19 = 91
let UC_ARM64_REG_H20 = 92
let UC_ARM64_REG_H21 = 93
let UC_ARM64_REG_H22 = 94
let UC_ARM64_REG_H23 = 95
let UC_ARM64_REG_H24 = 96
let UC_ARM64_REG_H25 = 97
let UC_ARM64_REG_H26 = 98
let UC_ARM64_REG_H27 = 99
let UC_ARM64_REG_H28 = 100
let UC_ARM64_REG_H29 = 101
let UC_ARM64_REG_H30 = 102
let UC_ARM64_REG_H31 = 103
let UC_ARM64_REG_Q0 = 104
let UC_ARM64_REG_Q1 = 105
let UC_ARM64_REG_Q2 = 106
let UC_ARM64_REG_Q3 = 107
let UC_ARM64_REG_Q4 = 108
let UC_ARM64_REG_Q5 = 109
let UC_ARM64_REG_Q6 = 110
let UC_ARM64_REG_Q7 = 111
let UC_ARM64_REG_Q8 = 112
let UC_ARM64_REG_Q9 = 113
let UC_ARM64_REG_Q10 = 114
let UC_ARM64_REG_Q11 = 115
let UC_ARM64_REG_Q12 = 116
let UC_ARM64_REG_Q13 = 117
let UC_ARM64_REG_Q14 = 118
let UC_ARM64_REG_Q15 = 119
let UC_ARM64_REG_Q16 = 120
let UC_ARM64_REG_Q17 = 121
let UC_ARM64_REG_Q18 = 122
let UC_ARM64_REG_Q19 = 123
let UC_ARM64_REG_Q20 = 124
let UC_ARM64_REG_Q21 = 125
let UC_ARM64_REG_Q22 = 126
let UC_ARM64_REG_Q23 = 127
let UC_ARM64_REG_Q24 = 128
let UC_ARM64_REG_Q25 = 129
let UC_ARM64_REG_Q26 = 130
let UC_ARM64_REG_Q27 = 131
let UC_ARM64_REG_Q28 = 132
let UC_ARM64_REG_Q29 = 133
let UC_ARM64_REG_Q30 = 134
let UC_ARM64_REG_Q31 = 135
let UC_ARM64_REG_S0 = 136
let UC_ARM64_REG_S1 = 137
let UC_ARM64_REG_S2 = 138
let UC_ARM64_REG_S3 = 139
let UC_ARM64_REG_S4 = 140
let UC_ARM64_REG_S5 = 141
let UC_ARM64_REG_S6 = 142
let UC_ARM64_REG_S7 = 143
let UC_ARM64_REG_S8 = 144
let UC_ARM64_REG_S9 = 145
let UC_ARM64_REG_S10 = 146
let UC_ARM64_REG_S11 = 147
let UC_ARM64_REG_S12 = 148
let UC_ARM64_REG_S13 = 149
let UC_ARM64_REG_S14 = 150
let UC_ARM64_REG_S15 = 151
let UC_ARM64_REG_S16 = 152
let UC_ARM64_REG_S17 = 153
let UC_ARM64_REG_S18 = 154
let UC_ARM64_REG_S19 = 155
let UC_ARM64_REG_S20 = 156
let UC_ARM64_REG_S21 = 157
let UC_ARM64_REG_S22 = 158
let UC_ARM64_REG_S23 = 159
let UC_ARM64_REG_S24 = 160
let UC_ARM64_REG_S25 = 161
let UC_ARM64_REG_S26 = 162
let UC_ARM64_REG_S27 = 163
let UC_ARM64_REG_S28 = 164
let UC_ARM64_REG_S29 = 165
let UC_ARM64_REG_S30 = 166
let UC_ARM64_REG_S31 = 167
let UC_ARM64_REG_W0 = 168
let UC_ARM64_REG_W1 = 169
let UC_ARM64_REG_W2 = 170
let UC_ARM64_REG_W3 = 171
let UC_ARM64_REG_W4 = 172
let UC_ARM64_REG_W5 = 173
let UC_ARM64_REG_W6 = 174
let UC_ARM64_REG_W7 = 175
let UC_ARM64_REG_W8 = 176
let UC_ARM64_REG_W9 = 177
let UC_ARM64_REG_W10 = 178
let UC_ARM64_REG_W11 = 179
let UC_ARM64_REG_W12 = 180
let UC_ARM64_REG_W13 = 181
let UC_ARM64_REG_W14 = 182
let UC_ARM64_REG_W15 = 183
let UC_ARM64_REG_W16 = 184
let UC_ARM64_REG_W17 = 185
let UC_ARM64_REG_W18 = 186
let UC_ARM64_REG_W19 = 187
let UC_ARM64_REG_W20 = 188
let UC_ARM64_REG_W21 = 189
let UC_ARM64_REG_W22 = 190
let UC_ARM64_REG_W23 = 191
let UC_ARM64_REG_W24 = 192
let UC_ARM64_REG_W25 = 193
let UC_ARM64_REG_W26 = 194
let UC_ARM64_REG_W27 = 195
let UC_ARM64_REG_W28 = 196
let UC_ARM64_REG_W29 = 197
let UC_ARM64_REG_W30 = 198
let UC_ARM64_REG_X0 = 199
let UC_ARM64_REG_X1 = 200
let UC_ARM64_REG_X2 = 201
let UC_ARM64_REG_X3 = 202
let UC_ARM64_REG_X4 = 203
let UC_ARM64_REG_X5 = 204
let UC_ARM64_REG_X6 = 205
let UC_ARM64_REG_X7 = 206
let UC_ARM64_REG_X8 = 207
let UC_ARM64_REG_X9 = 208
let UC_ARM64_REG_X10 = 209
let UC_ARM64_REG_X11 = 210
let UC_ARM64_REG_X12 = 211
let UC_ARM64_REG_X13 = 212
let UC_ARM64_REG_X14 = 213
let UC_ARM64_REG_X15 = 214
let UC_ARM64_REG_X16 = 215
let UC_ARM64_REG_X17 = 216
let UC_ARM64_REG_X18 = 217
let UC_ARM64_REG_X19 = 218
let UC_ARM64_REG_X20 = 219
let UC_ARM64_REG_X21 = 220
let UC_ARM64_REG_X22 = 221
let UC_ARM64_REG_X23 = 222
let UC_ARM64_REG_X24 = 223
let UC_ARM64_REG_X25 = 224
let UC_ARM64_REG_X26 = 225
let UC_ARM64_REG_X27 = 226
let UC_ARM64_REG_X28 = 227
let UC_ARM64_REG_V0 = 228
let UC_ARM64_REG_V1 = 229
let UC_ARM64_REG_V2 = 230
let UC_ARM64_REG_V3 = 231
let UC_ARM64_REG_V4 = 232
let UC_ARM64_REG_V5 = 233
let UC_ARM64_REG_V6 = 234
let UC_ARM64_REG_V7 = 235
let UC_ARM64_REG_V8 = 236
let UC_ARM64_REG_V9 = 237
let UC_ARM64_REG_V10 = 238
let UC_ARM64_REG_V11 = 239
let UC_ARM64_REG_V12 = 240
let UC_ARM64_REG_V13 = 241
let UC_ARM64_REG_V14 = 242
let UC_ARM64_REG_V15 = 243
let UC_ARM64_REG_V16 = 244
let UC_ARM64_REG_V17 = 245
let UC_ARM64_REG_V18 = 246
let UC_ARM64_REG_V19 = 247
let UC_ARM64_REG_V20 = 248
let UC_ARM64_REG_V21 = 249
let UC_ARM64_REG_V22 = 250
let UC_ARM64_REG_V23 = 251
let UC_ARM64_REG_V24 = 252
let UC_ARM64_REG_V25 = 253
let UC_ARM64_REG_V26 = 254
let UC_ARM64_REG_V27 = 255
let UC_ARM64_REG_V28 = 256
let UC_ARM64_REG_V29 = 257
let UC_ARM64_REG_V30 = 258
let UC_ARM64_REG_V31 = 259
// pseudo registers
let UC_ARM64_REG_PC = 260
let UC_ARM64_REG_ENDING = 261
// alias registers
let UC_ARM64_REG_IP1 = 215
let UC_ARM64_REG_IP0 = 216
let UC_ARM64_REG_FP = 1
let UC_ARM64_REG_LR = 2

View File

@@ -0,0 +1,96 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module Common =
let UC_API_MAJOR = 0
let UC_API_MINOR = 9
let UC_SECOND_SCALE = 1000000
let UC_MILISECOND_SCALE = 1000
let UC_ARCH_ARM = 1
let UC_ARCH_ARM64 = 2
let UC_ARCH_MIPS = 3
let UC_ARCH_X86 = 4
let UC_ARCH_PPC = 5
let UC_ARCH_SPARC = 6
let UC_ARCH_M68K = 7
let UC_ARCH_MAX = 8
let UC_MODE_LITTLE_ENDIAN = 0
let UC_MODE_ARM = 0
let UC_MODE_16 = 2
let UC_MODE_32 = 4
let UC_MODE_64 = 8
let UC_MODE_THUMB = 16
let UC_MODE_MCLASS = 32
let UC_MODE_V8 = 64
let UC_MODE_MICRO = 16
let UC_MODE_MIPS3 = 32
let UC_MODE_MIPS32R6 = 64
let UC_MODE_V9 = 16
let UC_MODE_QPX = 16
let UC_MODE_BIG_ENDIAN = 1073741824
let UC_MODE_MIPS32 = 4
let UC_MODE_MIPS64 = 8
let UC_ERR_OK = 0
let UC_ERR_NOMEM = 1
let UC_ERR_ARCH = 2
let UC_ERR_HANDLE = 3
let UC_ERR_MODE = 4
let UC_ERR_VERSION = 5
let UC_ERR_READ_UNMAPPED = 6
let UC_ERR_WRITE_UNMAPPED = 7
let UC_ERR_FETCH_UNMAPPED = 8
let UC_ERR_HOOK = 9
let UC_ERR_INSN_INVALID = 10
let UC_ERR_MAP = 11
let UC_ERR_WRITE_PROT = 12
let UC_ERR_READ_PROT = 13
let UC_ERR_FETCH_PROT = 14
let UC_ERR_ARG = 15
let UC_ERR_READ_UNALIGNED = 16
let UC_ERR_WRITE_UNALIGNED = 17
let UC_ERR_FETCH_UNALIGNED = 18
let UC_ERR_HOOK_EXIST = 19
let UC_ERR_RESOURCE = 20
let UC_MEM_READ = 16
let UC_MEM_WRITE = 17
let UC_MEM_FETCH = 18
let UC_MEM_READ_UNMAPPED = 19
let UC_MEM_WRITE_UNMAPPED = 20
let UC_MEM_FETCH_UNMAPPED = 21
let UC_MEM_WRITE_PROT = 22
let UC_MEM_READ_PROT = 23
let UC_MEM_FETCH_PROT = 24
let UC_HOOK_INTR = 1
let UC_HOOK_INSN = 2
let UC_HOOK_CODE = 4
let UC_HOOK_BLOCK = 8
let UC_HOOK_MEM_READ_UNMAPPED = 16
let UC_HOOK_MEM_WRITE_UNMAPPED = 32
let UC_HOOK_MEM_FETCH_UNMAPPED = 64
let UC_HOOK_MEM_READ_PROT = 128
let UC_HOOK_MEM_WRITE_PROT = 256
let UC_HOOK_MEM_FETCH_PROT = 512
let UC_HOOK_MEM_READ = 1024
let UC_HOOK_MEM_WRITE = 2048
let UC_HOOK_MEM_FETCH = 4096
let UC_HOOK_MEM_UNMAPPED = 112
let UC_HOOK_MEM_PROT = 896
let UC_HOOK_MEM_READ_INVALID = 144
let UC_HOOK_MEM_WRITE_INVALID = 288
let UC_HOOK_MEM_FETCH_INVALID = 576
let UC_HOOK_MEM_INVALID = 1008
let UC_PROT_NONE = 0
let UC_PROT_READ = 1
let UC_PROT_WRITE = 2
let UC_PROT_EXEC = 4
let UC_PROT_ALL = 7

View File

@@ -0,0 +1,32 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module M68k =
// M68K registers
let UC_M68K_REG_INVALID = 0
let UC_M68K_REG_A0 = 1
let UC_M68K_REG_A1 = 2
let UC_M68K_REG_A2 = 3
let UC_M68K_REG_A3 = 4
let UC_M68K_REG_A4 = 5
let UC_M68K_REG_A5 = 6
let UC_M68K_REG_A6 = 7
let UC_M68K_REG_A7 = 8
let UC_M68K_REG_D0 = 9
let UC_M68K_REG_D1 = 10
let UC_M68K_REG_D2 = 11
let UC_M68K_REG_D3 = 12
let UC_M68K_REG_D4 = 13
let UC_M68K_REG_D5 = 14
let UC_M68K_REG_D6 = 15
let UC_M68K_REG_D7 = 16
let UC_M68K_REG_SR = 17
let UC_M68K_REG_PC = 18
let UC_M68K_REG_ENDING = 19

View File

@@ -0,0 +1,203 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module Mips =
// MIPS registers
let UC_MIPS_REG_INVALID = 0
// General purpose registers
let UC_MIPS_REG_PC = 1
let UC_MIPS_REG_0 = 2
let UC_MIPS_REG_1 = 3
let UC_MIPS_REG_2 = 4
let UC_MIPS_REG_3 = 5
let UC_MIPS_REG_4 = 6
let UC_MIPS_REG_5 = 7
let UC_MIPS_REG_6 = 8
let UC_MIPS_REG_7 = 9
let UC_MIPS_REG_8 = 10
let UC_MIPS_REG_9 = 11
let UC_MIPS_REG_10 = 12
let UC_MIPS_REG_11 = 13
let UC_MIPS_REG_12 = 14
let UC_MIPS_REG_13 = 15
let UC_MIPS_REG_14 = 16
let UC_MIPS_REG_15 = 17
let UC_MIPS_REG_16 = 18
let UC_MIPS_REG_17 = 19
let UC_MIPS_REG_18 = 20
let UC_MIPS_REG_19 = 21
let UC_MIPS_REG_20 = 22
let UC_MIPS_REG_21 = 23
let UC_MIPS_REG_22 = 24
let UC_MIPS_REG_23 = 25
let UC_MIPS_REG_24 = 26
let UC_MIPS_REG_25 = 27
let UC_MIPS_REG_26 = 28
let UC_MIPS_REG_27 = 29
let UC_MIPS_REG_28 = 30
let UC_MIPS_REG_29 = 31
let UC_MIPS_REG_30 = 32
let UC_MIPS_REG_31 = 33
// DSP registers
let UC_MIPS_REG_DSPCCOND = 34
let UC_MIPS_REG_DSPCARRY = 35
let UC_MIPS_REG_DSPEFI = 36
let UC_MIPS_REG_DSPOUTFLAG = 37
let UC_MIPS_REG_DSPOUTFLAG16_19 = 38
let UC_MIPS_REG_DSPOUTFLAG20 = 39
let UC_MIPS_REG_DSPOUTFLAG21 = 40
let UC_MIPS_REG_DSPOUTFLAG22 = 41
let UC_MIPS_REG_DSPOUTFLAG23 = 42
let UC_MIPS_REG_DSPPOS = 43
let UC_MIPS_REG_DSPSCOUNT = 44
// ACC registers
let UC_MIPS_REG_AC0 = 45
let UC_MIPS_REG_AC1 = 46
let UC_MIPS_REG_AC2 = 47
let UC_MIPS_REG_AC3 = 48
// COP registers
let UC_MIPS_REG_CC0 = 49
let UC_MIPS_REG_CC1 = 50
let UC_MIPS_REG_CC2 = 51
let UC_MIPS_REG_CC3 = 52
let UC_MIPS_REG_CC4 = 53
let UC_MIPS_REG_CC5 = 54
let UC_MIPS_REG_CC6 = 55
let UC_MIPS_REG_CC7 = 56
// FPU registers
let UC_MIPS_REG_F0 = 57
let UC_MIPS_REG_F1 = 58
let UC_MIPS_REG_F2 = 59
let UC_MIPS_REG_F3 = 60
let UC_MIPS_REG_F4 = 61
let UC_MIPS_REG_F5 = 62
let UC_MIPS_REG_F6 = 63
let UC_MIPS_REG_F7 = 64
let UC_MIPS_REG_F8 = 65
let UC_MIPS_REG_F9 = 66
let UC_MIPS_REG_F10 = 67
let UC_MIPS_REG_F11 = 68
let UC_MIPS_REG_F12 = 69
let UC_MIPS_REG_F13 = 70
let UC_MIPS_REG_F14 = 71
let UC_MIPS_REG_F15 = 72
let UC_MIPS_REG_F16 = 73
let UC_MIPS_REG_F17 = 74
let UC_MIPS_REG_F18 = 75
let UC_MIPS_REG_F19 = 76
let UC_MIPS_REG_F20 = 77
let UC_MIPS_REG_F21 = 78
let UC_MIPS_REG_F22 = 79
let UC_MIPS_REG_F23 = 80
let UC_MIPS_REG_F24 = 81
let UC_MIPS_REG_F25 = 82
let UC_MIPS_REG_F26 = 83
let UC_MIPS_REG_F27 = 84
let UC_MIPS_REG_F28 = 85
let UC_MIPS_REG_F29 = 86
let UC_MIPS_REG_F30 = 87
let UC_MIPS_REG_F31 = 88
let UC_MIPS_REG_FCC0 = 89
let UC_MIPS_REG_FCC1 = 90
let UC_MIPS_REG_FCC2 = 91
let UC_MIPS_REG_FCC3 = 92
let UC_MIPS_REG_FCC4 = 93
let UC_MIPS_REG_FCC5 = 94
let UC_MIPS_REG_FCC6 = 95
let UC_MIPS_REG_FCC7 = 96
// AFPR128
let UC_MIPS_REG_W0 = 97
let UC_MIPS_REG_W1 = 98
let UC_MIPS_REG_W2 = 99
let UC_MIPS_REG_W3 = 100
let UC_MIPS_REG_W4 = 101
let UC_MIPS_REG_W5 = 102
let UC_MIPS_REG_W6 = 103
let UC_MIPS_REG_W7 = 104
let UC_MIPS_REG_W8 = 105
let UC_MIPS_REG_W9 = 106
let UC_MIPS_REG_W10 = 107
let UC_MIPS_REG_W11 = 108
let UC_MIPS_REG_W12 = 109
let UC_MIPS_REG_W13 = 110
let UC_MIPS_REG_W14 = 111
let UC_MIPS_REG_W15 = 112
let UC_MIPS_REG_W16 = 113
let UC_MIPS_REG_W17 = 114
let UC_MIPS_REG_W18 = 115
let UC_MIPS_REG_W19 = 116
let UC_MIPS_REG_W20 = 117
let UC_MIPS_REG_W21 = 118
let UC_MIPS_REG_W22 = 119
let UC_MIPS_REG_W23 = 120
let UC_MIPS_REG_W24 = 121
let UC_MIPS_REG_W25 = 122
let UC_MIPS_REG_W26 = 123
let UC_MIPS_REG_W27 = 124
let UC_MIPS_REG_W28 = 125
let UC_MIPS_REG_W29 = 126
let UC_MIPS_REG_W30 = 127
let UC_MIPS_REG_W31 = 128
let UC_MIPS_REG_HI = 129
let UC_MIPS_REG_LO = 130
let UC_MIPS_REG_P0 = 131
let UC_MIPS_REG_P1 = 132
let UC_MIPS_REG_P2 = 133
let UC_MIPS_REG_MPL0 = 134
let UC_MIPS_REG_MPL1 = 135
let UC_MIPS_REG_MPL2 = 136
let UC_MIPS_REG_ENDING = 137
let UC_MIPS_REG_ZERO = 2
let UC_MIPS_REG_AT = 3
let UC_MIPS_REG_V0 = 4
let UC_MIPS_REG_V1 = 5
let UC_MIPS_REG_A0 = 6
let UC_MIPS_REG_A1 = 7
let UC_MIPS_REG_A2 = 8
let UC_MIPS_REG_A3 = 9
let UC_MIPS_REG_T0 = 10
let UC_MIPS_REG_T1 = 11
let UC_MIPS_REG_T2 = 12
let UC_MIPS_REG_T3 = 13
let UC_MIPS_REG_T4 = 14
let UC_MIPS_REG_T5 = 15
let UC_MIPS_REG_T6 = 16
let UC_MIPS_REG_T7 = 17
let UC_MIPS_REG_S0 = 18
let UC_MIPS_REG_S1 = 19
let UC_MIPS_REG_S2 = 20
let UC_MIPS_REG_S3 = 21
let UC_MIPS_REG_S4 = 22
let UC_MIPS_REG_S5 = 23
let UC_MIPS_REG_S6 = 24
let UC_MIPS_REG_S7 = 25
let UC_MIPS_REG_T8 = 26
let UC_MIPS_REG_T9 = 27
let UC_MIPS_REG_K0 = 28
let UC_MIPS_REG_K1 = 29
let UC_MIPS_REG_GP = 30
let UC_MIPS_REG_SP = 31
let UC_MIPS_REG_FP = 32
let UC_MIPS_REG_S8 = 32
let UC_MIPS_REG_RA = 33
let UC_MIPS_REG_HI0 = 45
let UC_MIPS_REG_HI1 = 46
let UC_MIPS_REG_HI2 = 47
let UC_MIPS_REG_HI3 = 48
let UC_MIPS_REG_LO0 = 45
let UC_MIPS_REG_LO1 = 46
let UC_MIPS_REG_LO2 = 47
let UC_MIPS_REG_LO3 = 48

View File

@@ -0,0 +1,104 @@
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
namespace UnicornManaged.Const
open System
[<AutoOpen>]
module Sparc =
// SPARC registers
let UC_SPARC_REG_INVALID = 0
let UC_SPARC_REG_F0 = 1
let UC_SPARC_REG_F1 = 2
let UC_SPARC_REG_F2 = 3
let UC_SPARC_REG_F3 = 4
let UC_SPARC_REG_F4 = 5
let UC_SPARC_REG_F5 = 6
let UC_SPARC_REG_F6 = 7
let UC_SPARC_REG_F7 = 8
let UC_SPARC_REG_F8 = 9
let UC_SPARC_REG_F9 = 10
let UC_SPARC_REG_F10 = 11
let UC_SPARC_REG_F11 = 12
let UC_SPARC_REG_F12 = 13
let UC_SPARC_REG_F13 = 14
let UC_SPARC_REG_F14 = 15
let UC_SPARC_REG_F15 = 16
let UC_SPARC_REG_F16 = 17
let UC_SPARC_REG_F17 = 18
let UC_SPARC_REG_F18 = 19
let UC_SPARC_REG_F19 = 20
let UC_SPARC_REG_F20 = 21
let UC_SPARC_REG_F21 = 22
let UC_SPARC_REG_F22 = 23
let UC_SPARC_REG_F23 = 24
let UC_SPARC_REG_F24 = 25
let UC_SPARC_REG_F25 = 26
let UC_SPARC_REG_F26 = 27
let UC_SPARC_REG_F27 = 28
let UC_SPARC_REG_F28 = 29
let UC_SPARC_REG_F29 = 30
let UC_SPARC_REG_F30 = 31
let UC_SPARC_REG_F31 = 32
let UC_SPARC_REG_F32 = 33
let UC_SPARC_REG_F34 = 34
let UC_SPARC_REG_F36 = 35
let UC_SPARC_REG_F38 = 36
let UC_SPARC_REG_F40 = 37
let UC_SPARC_REG_F42 = 38
let UC_SPARC_REG_F44 = 39
let UC_SPARC_REG_F46 = 40
let UC_SPARC_REG_F48 = 41
let UC_SPARC_REG_F50 = 42
let UC_SPARC_REG_F52 = 43
let UC_SPARC_REG_F54 = 44
let UC_SPARC_REG_F56 = 45
let UC_SPARC_REG_F58 = 46
let UC_SPARC_REG_F60 = 47
let UC_SPARC_REG_F62 = 48
let UC_SPARC_REG_FCC0 = 49
let UC_SPARC_REG_FCC1 = 50
let UC_SPARC_REG_FCC2 = 51
let UC_SPARC_REG_FCC3 = 52
let UC_SPARC_REG_G0 = 53
let UC_SPARC_REG_G1 = 54
let UC_SPARC_REG_G2 = 55
let UC_SPARC_REG_G3 = 56
let UC_SPARC_REG_G4 = 57
let UC_SPARC_REG_G5 = 58
let UC_SPARC_REG_G6 = 59
let UC_SPARC_REG_G7 = 60
let UC_SPARC_REG_I0 = 61
let UC_SPARC_REG_I1 = 62
let UC_SPARC_REG_I2 = 63
let UC_SPARC_REG_I3 = 64
let UC_SPARC_REG_I4 = 65
let UC_SPARC_REG_I5 = 66
let UC_SPARC_REG_FP = 67
let UC_SPARC_REG_I7 = 68
let UC_SPARC_REG_ICC = 69
let UC_SPARC_REG_L0 = 70
let UC_SPARC_REG_L1 = 71
let UC_SPARC_REG_L2 = 72
let UC_SPARC_REG_L3 = 73
let UC_SPARC_REG_L4 = 74
let UC_SPARC_REG_L5 = 75
let UC_SPARC_REG_L6 = 76
let UC_SPARC_REG_L7 = 77
let UC_SPARC_REG_O0 = 78
let UC_SPARC_REG_O1 = 79
let UC_SPARC_REG_O2 = 80
let UC_SPARC_REG_O3 = 81
let UC_SPARC_REG_O4 = 82
let UC_SPARC_REG_O5 = 83
let UC_SPARC_REG_SP = 84
let UC_SPARC_REG_O7 = 85
let UC_SPARC_REG_Y = 86
let UC_SPARC_REG_XCC = 87
let UC_SPARC_REG_PC = 88
let UC_SPARC_REG_ENDING = 89
let UC_SPARC_REG_O6 = 84
let UC_SPARC_REG_I6 = 67

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
namespace UnicornManaged
open System
open System.Runtime.InteropServices
// internal hooks to be passed to native Unicorn library
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal CodeHookInternal = delegate of IntPtr * Int64 * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal BlockHookInternal = delegate of IntPtr * Int64 * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal InterruptHookInternal = delegate of IntPtr * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal MemReadHookInternal = delegate of IntPtr * Int64 * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal MemWriteHookInternal = delegate of IntPtr * Int64 * Int32 * Int64 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal EventMemHookInternal = delegate of IntPtr * Int64 * Int32 * Int64 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal InHookInternal = delegate of IntPtr * Int32 * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal OutHookInternal = delegate of IntPtr * Int32 * Int32 * Int32 * IntPtr -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type internal SyscallHookInternal = delegate of IntPtr * IntPtr -> unit

View File

@@ -0,0 +1,313 @@
namespace UnicornManaged
open System
open System.Threading
open System.Collections.Generic
open System.Runtime.InteropServices
open UnicornManaged.Const
open UnicornManaged.Binding
// exported hooks
type CodeHook = delegate of Unicorn * Int64 * Int32 * Object -> unit
and BlockHook = delegate of Unicorn * Int64 * Int32 * Object -> unit
and InterruptHook = delegate of Unicorn * Int32 * Object -> unit
and MemReadHook = delegate of Unicorn * Int64 * Int32 * Object -> unit
and MemWriteHook = delegate of Unicorn * Int64 * Int32 * Int64 * Object -> unit
and EventMemHook = delegate of Unicorn * Int64 * Int32 * Int64 * Object -> unit
and InHook = delegate of Unicorn * Int32 * Int32 * Object -> unit
and OutHook = delegate of Unicorn * Int32 * Int32 * Int32 * Object -> unit
and SyscallHook = delegate of Unicorn * Object -> unit
// the managed unicorn engine
and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
// hook callback list
let _codeHooks = new Dictionary<IntPtr, (CodeHook * Object)>()
let _blockHooks = new Dictionary<IntPtr, (BlockHook * Object)>()
let _interruptHooks = new Dictionary<IntPtr, (InterruptHook * Object)>()
let _memReadHooks = new Dictionary<IntPtr, (MemReadHook * Object)>()
let _memWriteHooks = new Dictionary<IntPtr, (MemWriteHook * Object)>()
let _memEventHooks = new Dictionary<IntPtr, (EventMemHook * Object)>()
let _inHooks = new Dictionary<IntPtr, (InHook * Object)>()
let _outHooks = new Dictionary<IntPtr, (OutHook * Object)>()
let _syscallHooks = new Dictionary<IntPtr, (SyscallHook * Object)>()
let _disposablePointers = new List<nativeint>()
let mutable _eng = [|UIntPtr.Zero|]
let checkResult(errCode: Int32, errMsg: String) =
if errCode <> Common.UC_ERR_OK then raise(ApplicationException(String.Format("{0}. Error: {1}", errMsg, errCode)))
let getId =
let counter = ref 0
fun () -> new IntPtr(Interlocked.Increment(counter))
let hookDel(callbacks: Dictionary<IntPtr, 'a * Object>) (callback: 'a)=
// TODO: invoke the native function in order to not call the trampoline anymore
callbacks.Keys
|> Seq.tryFind(fun k -> match callbacks.[k] with | (c, _) -> c = callback)
|> (fun k -> if k.IsSome then callbacks.Remove(k.Value) |> ignore)
let allocate(size: Int32) =
let mem = Marshal.AllocHGlobal(size)
_disposablePointers.Add(mem)
mem.ToPointer()
do
_eng <- [|new UIntPtr(allocate(IntPtr.Size))|]
let err = binding.UcOpen(uint32 arch, uint32 mode, _eng)
checkResult(err, "Unable to open the Unicorn Engine")
new(arch, mode) = new Unicorn(arch, mode, BindingFactory.getDefault())
member private this.CheckResult(errorCode: Int32) =
// return the exception instead of raising it in order to have a more meaningful stack trace
if errorCode <> Common.UC_ERR_OK then
let errorMessage = this.StrError(errorCode)
Some <| UnicornEngineException(errorCode, errorMessage)
else None
member this.MemMap(address: Int64, size: Int64, perm: Int32) =
let size = new UIntPtr(uint64 size)
match binding.MemMap(_eng.[0], uint64 address, size, uint32 perm) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.MemMapPtr(address: Int64, size: Int64, perm: Int32, ptr: IntPtr) =
let size = new UIntPtr(uint64 size)
let ptr = new UIntPtr(ptr.ToPointer())
match binding.MemMapPtr(_eng.[0], uint64 address, size, uint32 perm, ptr) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.MemUnmap(address: Int64, size: Int64) =
let size = new UIntPtr(uint64 size)
match binding.MemUnmap(_eng.[0], uint64 address, size) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.MemProtect(address: Int64, size: Int64, ?perm: Int32) =
let size = new UIntPtr(uint64 size)
let perm = defaultArg perm Common.UC_PROT_ALL
match binding.MemProtect(_eng.[0], uint64 address, size, uint32 perm) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.MemWrite(address: Int64, value: Byte array) =
match binding.MemWrite(_eng.[0], uint64 address, value, new UIntPtr(uint32 value.Length)) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.MemRead(address: Int64, memValue: Byte array) =
match binding.MemRead(_eng.[0], uint64 address, memValue, new UIntPtr(uint32 memValue.Length)) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.RegWrite(regId: Int32, value: Byte array) =
match binding.RegWrite(_eng.[0], regId, value) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.RegRead(regId: Int32, regValue: Byte array) =
match binding.RegRead(_eng.[0], regId, regValue) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.EmuStart(beginAddr: Int64, untilAddr: Int64, timeout: Int64, count: Int64) =
match binding.EmuStart(_eng.[0], uint64 beginAddr, uint64 untilAddr, uint64 timeout, uint64 count) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.EmuStop() =
match binding.EmuStop(_eng.[0]) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.Close() =
match binding.Close(_eng.[0]) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.ArchSupported(arch: Int32) =
binding.ArchSupported(arch)
member this.ErrNo() =
binding.Errono(_eng.[0])
member this.StrError(errorNo: Int32) =
let errorStringPointer = binding.Strerror(errorNo)
Marshal.PtrToStringAnsi(errorStringPointer)
member this.AddCodeHook(callback: CodeHook, userData: Object, beginAddr: Int64, endAddr: Int64) =
let trampoline(u: IntPtr) (addr: Int64) (size: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _codeHooks.TryGetValue(user)
if exist then callback.Invoke(this, addr, size, userData)
let id = getId()
_codeHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new CodeHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0Arg1(_eng.[0], hh, Common.UC_HOOK_CODE, new UIntPtr(funcPointer.ToPointer()), id, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.AddCodeHook(callback: CodeHook, beginAddr: Int64, endAddr: Int64) =
this.AddCodeHook(callback, null, beginAddr, endAddr)
member this.HookDel(callback: CodeHook) =
hookDel _codeHooks callback
member this.AddBlockHook(callback: BlockHook, userData: Object, beginAddr: Int64, endAddr: Int64) =
let trampoline(u: IntPtr) (addr: Int64) (size: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _blockHooks.TryGetValue(user)
if exist then callback.Invoke(this, addr, size, userData)
let id = getId()
_blockHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new BlockHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0Arg1(_eng.[0], hh, Common.UC_HOOK_BLOCK, new UIntPtr(funcPointer.ToPointer()), id, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.HookDel(callback: BlockHook) =
hookDel _blockHooks callback
member this.AddInterruptHook(callback: InterruptHook, userData: Object) =
let trampoline(u: IntPtr) (intNumber: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _interruptHooks.TryGetValue(user)
if exist then callback.Invoke(this, intNumber, userData)
let id = getId()
_interruptHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new InterruptHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_INTR, new UIntPtr(funcPointer.ToPointer()), id) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.AddInterruptHook(callback: InterruptHook) =
this.AddInterruptHook(callback, null)
member this.HookDel(callback: InterruptHook) =
hookDel _interruptHooks callback
member this.AddMemReadHook(callback: MemReadHook, userData: Object, beginAddr: Int64, endAddr: Int64) =
let trampoline(u: IntPtr) (addr: Int64) (size: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _memReadHooks.TryGetValue(user)
if exist then callback.Invoke(this, addr, size, userData)
let id = getId()
_memReadHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new MemReadHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0Arg1(_eng.[0], hh, Common.UC_HOOK_MEM_READ, new UIntPtr(funcPointer.ToPointer()), id, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.HookDel(callback: MemReadHook) =
hookDel _memReadHooks callback
member this.AddMemWriteHook(callback: MemWriteHook, userData: Object, beginAddr: Int64, endAddr: Int64) =
let trampoline(u: IntPtr) (addr: Int64) (size: Int32) (value: Int64) (user: IntPtr) =
let (exist, (callback, userData)) = _memWriteHooks.TryGetValue(user)
if exist then callback.Invoke(this, addr, size, value, userData)
let id = getId()
_memWriteHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new MemWriteHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0Arg1(_eng.[0], hh, Common.UC_HOOK_MEM_WRITE, new UIntPtr(funcPointer.ToPointer()), id, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.HookDel(callback: MemWriteHook) =
hookDel _memWriteHooks callback
member this.AddEventMemHook(callback: EventMemHook, eventType: Int32, userData: Object) =
let trampoline(u: IntPtr) (addr: Int64) (size: Int32) (value: Int64) (user: IntPtr) =
let (exist, (callback, userData)) = _memEventHooks.TryGetValue(user)
if exist then callback.Invoke(this, addr, size, value, userData)
let registEventMemHook(check: Int32) =
let id = getId()
_memEventHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new EventMemHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddNoarg(_eng.[0], hh, check, new UIntPtr(funcPointer.ToPointer()), id) |> this.CheckResult with
| Some e -> raise e | None -> ()
// test all the events types agains the input eventType
[
Common.UC_HOOK_MEM_READ_UNMAPPED
Common.UC_HOOK_MEM_WRITE_UNMAPPED
Common.UC_HOOK_MEM_FETCH_UNMAPPED
Common.UC_HOOK_MEM_READ_PROT
Common.UC_HOOK_MEM_WRITE_PROT
Common.UC_HOOK_MEM_FETCH_PROT
]
|> List.filter(fun eventFlag -> eventType &&& eventFlag <> 0)
|> List.map registEventMemHook
|> List.rev |> List.head
member this.HookDel(callback: EventMemHook) =
hookDel _memEventHooks callback
member this.AddInHook(callback: InHook, userData: Object) =
let trampoline(u: IntPtr) (port: Int32) (size: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _inHooks.TryGetValue(user)
if exist then callback.Invoke(this, port, size, userData)
let id = getId()
_inHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new InHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), id, new IntPtr(X86.UC_X86_INS_IN)) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.AddOutHook(callback: OutHook, userData: Object) =
let trampoline(u: IntPtr) (port: Int32) (size: Int32) (value: Int32) (user: IntPtr) =
let (exist, (callback, userData)) = _outHooks.TryGetValue(user)
if exist then callback.Invoke(this, port, size, value, userData)
let id = getId()
_outHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new OutHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), id, new IntPtr(X86.UC_X86_INS_OUT)) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.AddSyscallHook(callback: SyscallHook, userData: Object) =
let trampoline(u: IntPtr) (user: IntPtr) =
let (exist, (callback, userData)) = _syscallHooks.TryGetValue(user)
if exist then callback.Invoke(this, userData)
let id = getId()
_syscallHooks.Add(id, (callback, userData))
let funcPointer = Marshal.GetFunctionPointerForDelegate(new SyscallHookInternal(trampoline))
let hh = new UIntPtr(allocate(IntPtr.Size))
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), id, new IntPtr(X86.UC_X86_INS_SYSCALL)) |> this.CheckResult with
| Some e -> raise e | None -> ()
member this.AddSyscallHook(callback: SyscallHook) =
this.AddSyscallHook(callback, null)
member this.Version() =
let (major, minor) = (new UIntPtr(), new UIntPtr())
let combined = binding.Version(major, minor)
(major.ToUInt32(), minor.ToUInt32(), combined)
abstract Dispose : Boolean -> unit
default this.Dispose(disposing: Boolean) =
if (disposing) then
// free managed resources, this is the default dispose implementation pattern
()
_disposablePointers
|> Seq.filter(fun pointer -> pointer <> IntPtr.Zero)
|> Seq.iter Marshal.FreeHGlobal
_disposablePointers.Clear()
member this.Dispose() =
this.Dispose(true)
GC.SuppressFinalize(this)
override this.Finalize() =
this.Dispose(false)
interface IDisposable with
member this.Dispose() =
this.Dispose()

View File

@@ -0,0 +1,9 @@
namespace UnicornManaged
open System
type UnicornEngineException(errNo: Int32, msg: String) =
inherit ApplicationException(msg)
member this.ErrorNo = errNo

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>0c21f1c1-2725-4a46-9022-1905f85822a5</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UnicornManaged</RootNamespace>
<AssemblyName>UnicornManaged</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>UnicornManaged</Name>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\UnicornManaged.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\UnicornManaged.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Const\Arm.fs" />
<Compile Include="Const\Arm64.fs" />
<Compile Include="Const\Common.fs" />
<Compile Include="Const\M68k.fs" />
<Compile Include="Const\Mips.fs" />
<Compile Include="Const\Sparc.fs" />
<Compile Include="Const\X86.fs" />
<Compile Include="Binding\IBinding.fs" />
<Compile Include="Binding\MockBinding.fs" />
<Compile Include="Binding\NativeBinding.fs" />
<Compile Include="Binding\BindingFactory.fs" />
<Compile Include="UnicornEngineException.fs" />
<Compile Include="Hooks.fs" />
<Compile Include="Unicorn.fs" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>