Implemented uc_strerror and minor refactoring
This commit is contained in:
@ -1,51 +0,0 @@
|
||||
(*
|
||||
|
||||
.NET bindings for the UnicornEngine Emulator Engine
|
||||
|
||||
Copyright(c) 2015 Antonio Parata
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*)
|
||||
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
module UcError =
|
||||
|
||||
let toErrorDesc(err: Int32) =
|
||||
match err with
|
||||
| 0 -> "UC_ERR_OK"
|
||||
| 1 -> "UC_ERR_NOMEM"
|
||||
| 2 -> "UC_ERR_ARCH"
|
||||
| 3 -> "UC_ERR_HANDLE"
|
||||
| 4 -> "UC_ERR_MODE"
|
||||
| 5 -> "UC_ERR_VERSION"
|
||||
| 6 -> "UC_ERR_READ_INVALID"
|
||||
| 7 -> "UC_ERR_WRITE_INVALID"
|
||||
| 8 -> "UC_ERR_FETCH_INVALID"
|
||||
| 9 -> "UC_ERR_CODE_INVALID"
|
||||
| 10 -> "UC_ERR_HOOK"
|
||||
| 11 -> "UC_ERR_INSN_INVALID"
|
||||
| 12 -> "UC_ERR_MAP"
|
||||
| 13 -> "UC_ERR_WRITE_PROT"
|
||||
| 14 -> "UC_ERR_READ_PROT"
|
||||
| 15 -> "UC_ERR_FETCH_PROT"
|
||||
| 16 -> "UC_ERR_ARG"
|
||||
| 17 -> "UC_ERR_READ_UNALIGNED"
|
||||
| 18 -> "UC_ERR_WRITE_UNALIGNED"
|
||||
| 19 -> "UC_ERR_FETCH_UNALIGNED"
|
||||
| _ -> String.Empty
|
||||
|
@ -64,6 +64,9 @@ module NativeUnicornEngine =
|
||||
[<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)
|
||||
|
||||
@ -86,6 +89,7 @@ module NativeUnicornEngine =
|
||||
let mutable emu_stop = fun(eng) -> Imported.uc_emu_stop(eng)
|
||||
let mutable arch_supported = fun(arch) -> Imported.uc_arch_supported(arch)
|
||||
let mutable errno = fun(eng) -> Imported.uc_errno(eng)
|
||||
let mutable strerror = fun(err) -> Imported.uc_strerror(err)
|
||||
let mutable hook_add_noarg = fun(eng, hh, callbackType, callback, userData) -> Imported.uc_hook_add_noarg(eng, hh, callbackType, callback, userData)
|
||||
let mutable hook_add_arg0 = fun(eng, hh, callbackType, callback, userData, arg0) -> Imported.uc_hook_add_arg0(eng, hh, callbackType, callback, userData, arg0)
|
||||
let mutable hook_add_arg0_arg1 = fun(eng, hh, callbackType, callback, userData, arg0, arg1) -> Imported.uc_hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, arg0, arg1)
|
@ -55,7 +55,7 @@ and Unicorn(arch: Int32, mode: Int32) =
|
||||
let mutable _eng = [|UIntPtr.Zero|]
|
||||
|
||||
let checkResult(errCode: Int32, errMsg: String) =
|
||||
if errCode <> Common.UC_ERR_OK then raise(ApplicationException(errMsg + ". Error: " + UcError.toErrorDesc(errCode)))
|
||||
if errCode <> Common.UC_ERR_OK then raise(ApplicationException(String.Format("{0}. Error: {1}", errMsg, errCode)))
|
||||
|
||||
let getId =
|
||||
let counter = ref 0
|
||||
@ -103,9 +103,9 @@ and Unicorn(arch: Int32, mode: Int32) =
|
||||
member this.ErrNo() =
|
||||
NativeUnicornEngine.errno(_eng.[0])
|
||||
|
||||
member this.StrError() =
|
||||
// TODO: to be implemented
|
||||
raise(NotImplementedException())
|
||||
member this.StrError(errorNo: Int32) =
|
||||
let errorStringPointer = NativeUnicornEngine.strerror(errorNo)
|
||||
Marshal.PtrToStringAnsi(errorStringPointer)
|
||||
|
||||
member this.AddCodeHook(callback: CodeHook, userData: Object, beginAdd: UInt64, endAddr: UInt64) =
|
||||
let trampoline(u: IntPtr) (addr: UInt64) (size: Int32) (user: IntPtr) =
|
||||
|
@ -53,7 +53,7 @@ namespace UnicornTests
|
||||
{
|
||||
if (err != Common.UC_ERR_OK)
|
||||
{
|
||||
throw new ApplicationException("Operation failed, error: " + UcError.toErrorDesc(err));
|
||||
throw new ApplicationException("Operation failed, error: " + err);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user