Merge branch 'dev' into uc-py-next
This commit is contained in:
@@ -90,10 +90,10 @@ template = {
|
||||
'comment_close': '',
|
||||
},
|
||||
'dotnet': {
|
||||
'header': "// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT\n\nnamespace UnicornManaged.Const\n\nopen System\n\n[<AutoOpen>]\nmodule %s =\n",
|
||||
'header': "// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT\n\nnamespace UnicornEngine.Const\n\nopen System\n\n[<AutoOpen>]\nmodule %s =\n",
|
||||
'footer': "\n",
|
||||
'line_format': ' let UC_%s = %s\n',
|
||||
'out_file': os.path.join('dotnet', 'UnicornManaged', 'Const', '%s.fs'),
|
||||
'out_file': os.path.join('dotnet', 'UnicornEngine', 'Const', '%s.fs'),
|
||||
# prefixes for constant filenames of all archs - case sensitive
|
||||
'arm.h': 'Arm',
|
||||
'arm64.h': 'Arm64',
|
||||
|
||||
@@ -5,7 +5,7 @@ VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnicornSamples", "UnicornSamples\UnicornSamples.csproj", "{B80B5987-1E24-4309-8BF9-C4F91270F21C}"
|
||||
EndProject
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnicornManaged", "UnicornManaged\UnicornManaged.fsproj", "{0C21F1C1-2725-4A46-9022-1905F85822A5}"
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnicornEngine", "UnicornEngine\UnicornEngine.fsproj", "{0C21F1C1-2725-4A46-9022-1905F85822A5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged.Binding
|
||||
namespace UnicornEngine.Binding
|
||||
|
||||
|
||||
module BindingFactory =
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged.Binding
|
||||
namespace UnicornEngine.Binding
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged.Binding
|
||||
namespace UnicornEngine.Binding
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged.Binding
|
||||
namespace UnicornEngine.Binding
|
||||
|
||||
open System
|
||||
open System.Runtime.InteropServices
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -9,13 +9,13 @@ module Common =
|
||||
let UC_API_MAJOR = 2
|
||||
|
||||
let UC_API_MINOR = 0
|
||||
let UC_API_PATCH = 1
|
||||
let UC_API_EXTRA = 255
|
||||
let UC_API_PATCH = 2
|
||||
let UC_API_EXTRA = 1
|
||||
let UC_VERSION_MAJOR = 2
|
||||
|
||||
let UC_VERSION_MINOR = 0
|
||||
let UC_VERSION_PATCH = 1
|
||||
let UC_VERSION_EXTRA = 255
|
||||
let UC_VERSION_PATCH = 2
|
||||
let UC_VERSION_EXTRA = 1
|
||||
let UC_SECOND_SCALE = 1000000
|
||||
let UC_MILISECOND_SCALE = 1000
|
||||
let UC_ARCH_ARM = 1
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
||||
|
||||
namespace UnicornManaged.Const
|
||||
namespace UnicornEngine.Const
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged
|
||||
namespace UnicornEngine
|
||||
|
||||
open System
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged
|
||||
namespace UnicornEngine
|
||||
|
||||
open System
|
||||
open System.Runtime.InteropServices
|
||||
@@ -14,10 +14,10 @@ type internal BlockHookInternal = delegate of IntPtr * Int64 * Int32 * IntPtr ->
|
||||
type internal InterruptHookInternal = delegate of IntPtr * Int32 * IntPtr -> unit
|
||||
|
||||
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
|
||||
type internal MemReadHookInternal = delegate of IntPtr * Int64 * Int32 * IntPtr -> unit
|
||||
type internal MemReadHookInternal = delegate of IntPtr * Int32 * Int64 * Int32 * IntPtr -> unit
|
||||
|
||||
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
|
||||
type internal MemWriteHookInternal = delegate of IntPtr * Int64 * Int32 * Int64 * IntPtr -> unit
|
||||
type internal MemWriteHookInternal = delegate of IntPtr * Int32 * Int64 * Int32 * Int64 * IntPtr -> unit
|
||||
|
||||
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
|
||||
type internal EventMemHookInternal = delegate of IntPtr * Int32 * Int64 * Int32 * Int64 * IntPtr-> Boolean
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace UnicornManaged
|
||||
namespace UnicornEngine
|
||||
|
||||
open System
|
||||
open System.Collections.Generic
|
||||
open System.Runtime.InteropServices
|
||||
open System.Linq
|
||||
open UnicornManaged.Const
|
||||
open UnicornManaged.Binding
|
||||
open UnicornEngine.Const
|
||||
open UnicornEngine.Binding
|
||||
|
||||
// exported hooks
|
||||
type CodeHook = delegate of Unicorn * Int64 * Int32 * Object -> unit
|
||||
@@ -32,6 +32,7 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
let _outHooks = new List<(OutHook * Object)>()
|
||||
let _syscallHooks = new List<(SyscallHook * Object)>()
|
||||
let _disposablePointers = new List<nativeint>()
|
||||
let _hookInternals = new List<Object>();
|
||||
|
||||
let _eventMemMap =
|
||||
[
|
||||
@@ -153,7 +154,9 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, addr, size, userData))
|
||||
|
||||
if _codeHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new CodeHookInternal(trampoline))
|
||||
let codeHookInternal = new CodeHookInternal(trampoline)
|
||||
_hookInternals.Add(codeHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(codeHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_CODE, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
@@ -172,7 +175,9 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, addr, size, userData))
|
||||
|
||||
if _blockHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new BlockHookInternal(trampoline))
|
||||
let blockHookInternal = new BlockHookInternal(trampoline)
|
||||
_hookInternals.Add(blockHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(blockHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_BLOCK, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
@@ -188,7 +193,9 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, intNumber, userData))
|
||||
|
||||
if _interruptHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new InterruptHookInternal(trampoline))
|
||||
let interruptHookInternal = new InterruptHookInternal(trampoline)
|
||||
_hookInternals.Add(interruptHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(interruptHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_INTR, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, hookBegin, hookEnd) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
@@ -202,12 +209,14 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
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 trampoline(u: IntPtr) (_eventType: Int32) (addr: Int64) (size: Int32) (user: IntPtr) =
|
||||
_memReadHooks
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, addr, size, userData))
|
||||
|
||||
if _memReadHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new MemReadHookInternal(trampoline))
|
||||
let memReadHookInternal = new MemReadHookInternal(trampoline)
|
||||
_hookInternals.Add(memReadHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(memReadHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_MEM_READ, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
@@ -218,12 +227,14 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
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 trampoline(u: IntPtr) (_eventType: Int32) (addr: Int64) (size: Int32) (value: Int64) (user: IntPtr) =
|
||||
_memWriteHooks
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, addr, size, value, userData))
|
||||
|
||||
if _memWriteHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new MemWriteHookInternal(trampoline))
|
||||
let memWriteHookInternal = new MemWriteHookInternal(trampoline)
|
||||
_hookInternals.Add(memWriteHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(memWriteHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, Common.UC_HOOK_MEM_WRITE, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 beginAddr, uint64 endAddr) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
@@ -247,9 +258,11 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.filter(fun eventFlag -> (eventType &&& eventFlag) <> 0)
|
||||
|> Seq.filter(fun eventFlag -> _memEventHooks.[eventFlag] |> Seq.isEmpty)
|
||||
|> Seq.iter(fun eventFlag ->
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new EventMemHookInternal(trampoline))
|
||||
let memEventHookInternal = new EventMemHookInternal(trampoline)
|
||||
_hookInternals.Add(memEventHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(memEventHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddNoarg(_eng.[0], hh, eventFlag, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 0, uint64 0) |> this.CheckResult with
|
||||
match binding.HookAddNoarg(_eng.[0], hh, eventFlag, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 1, uint64 0) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
)
|
||||
|
||||
@@ -272,9 +285,11 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.last
|
||||
|
||||
if _inHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new InHookInternal(trampoline))
|
||||
let inHookInternal = new InHookInternal(trampoline)
|
||||
_hookInternals.Add(inHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(inHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 0, uint64 0, X86.UC_X86_INS_IN) |> this.CheckResult with
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 1, uint64 0, X86.UC_X86_INS_IN) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
|
||||
_inHooks.Add(callback, userData)
|
||||
@@ -288,9 +303,11 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, port, size, value, userData))
|
||||
|
||||
if _outHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new OutHookInternal(trampoline))
|
||||
let outHookInternal = new OutHookInternal(trampoline)
|
||||
_hookInternals.Add(outHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(outHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 0, uint64 0, X86.UC_X86_INS_OUT) |> this.CheckResult with
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 1, uint64 0, X86.UC_X86_INS_OUT) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
|
||||
_outHooks.Add(callback, userData)
|
||||
@@ -304,9 +321,11 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) =
|
||||
|> Seq.iter(fun (callback, userData) -> callback.Invoke(this, userData))
|
||||
|
||||
if _syscallHooks |> Seq.isEmpty then
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(new SyscallHookInternal(trampoline))
|
||||
let syscallHookInternal = new SyscallHookInternal(trampoline)
|
||||
_hookInternals.Add(syscallHookInternal)
|
||||
let funcPointer = Marshal.GetFunctionPointerForDelegate(syscallHookInternal)
|
||||
let hh = new UIntPtr(allocate(IntPtr.Size))
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 0, uint64 0, X86.UC_X86_INS_SYSCALL) |> this.CheckResult with
|
||||
match binding.HookAddArg0(_eng.[0], hh, Common.UC_HOOK_INSN, new UIntPtr(funcPointer.ToPointer()), IntPtr.Zero, uint64 1, uint64 0, X86.UC_X86_INS_SYSCALL) |> this.CheckResult with
|
||||
| Some e -> raise e | None -> ()
|
||||
|
||||
_syscallHooks.Add(callback, userData)
|
||||
@@ -1,11 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>UnicornManaged</RootNamespace>
|
||||
<AssemblyName>UnicornManaged</AssemblyName>
|
||||
<PackageId>UnicornEngine.Unicorn</PackageId>
|
||||
<Authors>UnicornEngine</Authors>
|
||||
<Copyright>Copyright © Antonio Parata 2016</Copyright>
|
||||
<RepositoryUrl>https://github.com/unicorn-engine/unicorn</RepositoryUrl>
|
||||
<Version>2.0.0</Version>
|
||||
<PackageDescription>.NET bindings for unicorn</PackageDescription>
|
||||
<VersionPrefix>2.0.2-rc1</VersionPrefix>
|
||||
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
|
||||
<ProjectGuid>0c21f1c1-2725-4a46-9022-1905f85822a5</ProjectGuid>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
@@ -15,6 +17,10 @@
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Const\Arm.fs" />
|
||||
<Compile Include="Const\Arm64.fs" />
|
||||
@@ -36,4 +42,8 @@
|
||||
<Compile Include="ConvertUtility.fs" />
|
||||
<Compile Include="Unicorn.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="runtimes\**" PackagePath="runtimes" Visible="false" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace UnicornManaged
|
||||
namespace UnicornEngine
|
||||
|
||||
open System
|
||||
|
||||
@@ -3,8 +3,8 @@ using Gee.External.Capstone.X86;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using UnicornManaged;
|
||||
using UnicornManaged.Const;
|
||||
using UnicornEngine;
|
||||
using UnicornEngine.Const;
|
||||
|
||||
namespace UnicornSamples
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<AssemblyName>UnicornSamples</AssemblyName>
|
||||
<Copyright>Copyright © Antonio Parata 2016</Copyright>
|
||||
<RepositoryUrl>https://github.com/unicorn-engine/unicorn</RepositoryUrl>
|
||||
<Version>2.0.0</Version>
|
||||
<Version>2.0.2-rc1</Version>
|
||||
<ProjectGuid>{B80B5987-1E24-4309-8BF9-C4F91270F21C}</ProjectGuid>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
@@ -17,9 +17,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UnicornManaged\UnicornManaged.fsproj">
|
||||
<ProjectReference Include="..\UnicornEngine\UnicornEngine.fsproj">
|
||||
<Project>{0c21f1c1-2725-4a46-9022-1905f85822a5}</Project>
|
||||
<Name>UnicornManaged</Name>
|
||||
<Name>UnicornEngine</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ using Gee.External.Capstone.X86;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using UnicornManaged;
|
||||
using UnicornManaged.Const;
|
||||
using UnicornEngine;
|
||||
using UnicornEngine.Const;
|
||||
|
||||
namespace UnicornSamples
|
||||
{
|
||||
|
||||
@@ -4,13 +4,13 @@ const (
|
||||
API_MAJOR = 2
|
||||
|
||||
API_MINOR = 0
|
||||
API_PATCH = 1
|
||||
API_EXTRA = 255
|
||||
API_PATCH = 2
|
||||
API_EXTRA = 1
|
||||
VERSION_MAJOR = 2
|
||||
|
||||
VERSION_MINOR = 0
|
||||
VERSION_PATCH = 1
|
||||
VERSION_EXTRA = 255
|
||||
VERSION_PATCH = 2
|
||||
VERSION_EXTRA = 1
|
||||
SECOND_SCALE = 1000000
|
||||
MILISECOND_SCALE = 1000
|
||||
ARCH_ARM = 1
|
||||
|
||||
@@ -6,13 +6,13 @@ public interface UnicornConst {
|
||||
public static final int UC_API_MAJOR = 2;
|
||||
|
||||
public static final int UC_API_MINOR = 0;
|
||||
public static final int UC_API_PATCH = 1;
|
||||
public static final int UC_API_EXTRA = 255;
|
||||
public static final int UC_API_PATCH = 2;
|
||||
public static final int UC_API_EXTRA = 1;
|
||||
public static final int UC_VERSION_MAJOR = 2;
|
||||
|
||||
public static final int UC_VERSION_MINOR = 0;
|
||||
public static final int UC_VERSION_PATCH = 1;
|
||||
public static final int UC_VERSION_EXTRA = 255;
|
||||
public static final int UC_VERSION_PATCH = 2;
|
||||
public static final int UC_VERSION_EXTRA = 1;
|
||||
public static final int UC_SECOND_SCALE = 1000000;
|
||||
public static final int UC_MILISECOND_SCALE = 1000;
|
||||
public static final int UC_ARCH_ARM = 1;
|
||||
|
||||
@@ -7,13 +7,13 @@ interface
|
||||
const UC_API_MAJOR = 2;
|
||||
|
||||
UC_API_MINOR = 0;
|
||||
UC_API_PATCH = 1;
|
||||
UC_API_EXTRA = 255;
|
||||
UC_API_PATCH = 2;
|
||||
UC_API_EXTRA = 1;
|
||||
UC_VERSION_MAJOR = 2;
|
||||
|
||||
UC_VERSION_MINOR = 0;
|
||||
UC_VERSION_PATCH = 1;
|
||||
UC_VERSION_EXTRA = 255;
|
||||
UC_VERSION_PATCH = 2;
|
||||
UC_VERSION_EXTRA = 1;
|
||||
UC_SECOND_SCALE = 1000000;
|
||||
UC_MILISECOND_SCALE = 1000;
|
||||
UC_ARCH_ARM = 1;
|
||||
|
||||
@@ -8,6 +8,7 @@ import subprocess
|
||||
import shutil
|
||||
import sys
|
||||
import platform
|
||||
import setuptools
|
||||
|
||||
from distutils import log
|
||||
from distutils.core import setup
|
||||
@@ -29,7 +30,7 @@ SRC_DIR = os.path.join(ROOT_DIR, 'src')
|
||||
UC_DIR = SRC_DIR if os.path.exists(SRC_DIR) else os.path.join(ROOT_DIR, '../..')
|
||||
BUILD_DIR = os.path.join(UC_DIR, 'build_python')
|
||||
|
||||
VERSION = "2.0.1.post1"
|
||||
VERSION = "2.0.2"
|
||||
|
||||
if SYSTEM == 'darwin':
|
||||
LIBRARY_FILE = "libunicorn.2.dylib"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
UC_API_MAJOR = 2
|
||||
|
||||
UC_API_MINOR = 0
|
||||
UC_API_PATCH = 1
|
||||
UC_API_EXTRA = 255
|
||||
UC_API_PATCH = 2
|
||||
UC_API_EXTRA = 1
|
||||
UC_VERSION_MAJOR = 2
|
||||
|
||||
UC_VERSION_MINOR = 0
|
||||
UC_VERSION_PATCH = 1
|
||||
UC_VERSION_EXTRA = 255
|
||||
UC_VERSION_PATCH = 2
|
||||
UC_VERSION_EXTRA = 1
|
||||
UC_SECOND_SCALE = 1000000
|
||||
UC_MILISECOND_SCALE = 1000
|
||||
UC_ARCH_ARM = 1
|
||||
|
||||
@@ -4,13 +4,13 @@ module UnicornEngine
|
||||
UC_API_MAJOR = 2
|
||||
|
||||
UC_API_MINOR = 0
|
||||
UC_API_PATCH = 1
|
||||
UC_API_EXTRA = 255
|
||||
UC_API_PATCH = 2
|
||||
UC_API_EXTRA = 1
|
||||
UC_VERSION_MAJOR = 2
|
||||
|
||||
UC_VERSION_MINOR = 0
|
||||
UC_VERSION_PATCH = 1
|
||||
UC_VERSION_EXTRA = 255
|
||||
UC_VERSION_PATCH = 2
|
||||
UC_VERSION_EXTRA = 1
|
||||
UC_SECOND_SCALE = 1000000
|
||||
UC_MILISECOND_SCALE = 1000
|
||||
UC_ARCH_ARM = 1
|
||||
|
||||
@@ -84,6 +84,43 @@ fn build_with_cmake() {
|
||||
config.generator("Ninja");
|
||||
}
|
||||
|
||||
let mut archs = String::new();
|
||||
|
||||
if std::env::var("CARGO_FEATURE_ARCH_X86").is_ok() {
|
||||
archs.push_str("x86;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_ARM").is_ok() {
|
||||
archs.push_str("arm;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_AARCH64").is_ok() {
|
||||
archs.push_str("aarch64;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_RISCV").is_ok() {
|
||||
archs.push_str("riscv;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_MIPS").is_ok() {
|
||||
archs.push_str("mips;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_SPARC").is_ok() {
|
||||
archs.push_str("sparc;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_M68K").is_ok() {
|
||||
archs.push_str("m68k;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_PPC").is_ok() {
|
||||
archs.push_str("ppc;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_S390X").is_ok() {
|
||||
archs.push_str("s390x;");
|
||||
}
|
||||
if std::env::var("CARGO_FEATURE_ARCH_TRICORE").is_ok() {
|
||||
archs.push_str("tricore;");
|
||||
}
|
||||
|
||||
if !archs.is_empty() {
|
||||
archs.pop();
|
||||
}
|
||||
|
||||
// need to clear build target and append "build" to the path because
|
||||
// unicorn's CMakeLists.txt doesn't properly support 'install', so we use
|
||||
// the build artifacts from the build directory, which cmake crate sets
|
||||
@@ -91,6 +128,7 @@ fn build_with_cmake() {
|
||||
let dst = config
|
||||
.define("UNICORN_BUILD_TESTS", "OFF")
|
||||
.define("UNICORN_INSTALL", "OFF")
|
||||
.define("UNICORN_ARCH", archs)
|
||||
.no_build_target(true)
|
||||
.build();
|
||||
println!(
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::Unicorn;
|
||||
use crate::{Unicorn, UnicornInner};
|
||||
|
||||
use super::unicorn_const::{uc_error, Arch, HookType, MemRegion, MemType, Mode, Query};
|
||||
use core::ffi::c_void;
|
||||
use alloc::rc::Weak;
|
||||
use core::{cell::UnsafeCell, ffi::c_void};
|
||||
use libc::{c_char, c_int};
|
||||
|
||||
pub type uc_handle = *mut c_void;
|
||||
@@ -89,7 +90,7 @@ extern "C" {
|
||||
|
||||
pub struct UcHook<'a, D: 'a, F: 'a> {
|
||||
pub callback: F,
|
||||
pub uc: Unicorn<'a, D>,
|
||||
pub uc: Weak<UnsafeCell<UnicornInner<'a, D>>>,
|
||||
}
|
||||
|
||||
pub trait IsUcHook<'a> {}
|
||||
@@ -106,8 +107,11 @@ where
|
||||
F: FnMut(&mut crate::Unicorn<D>, u64, usize) -> u64,
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, offset, size)
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, offset, size)
|
||||
}
|
||||
|
||||
pub extern "C" fn mmio_write_callback_proxy<D, F>(
|
||||
@@ -120,8 +124,11 @@ pub extern "C" fn mmio_write_callback_proxy<D, F>(
|
||||
F: FnMut(&mut crate::Unicorn<D>, u64, usize, u64),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, offset, size, value);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, offset, size, value);
|
||||
}
|
||||
|
||||
pub extern "C" fn code_hook_proxy<D, F>(
|
||||
@@ -133,8 +140,11 @@ pub extern "C" fn code_hook_proxy<D, F>(
|
||||
F: FnMut(&mut crate::Unicorn<D>, u64, u32),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, address, size);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, address, size);
|
||||
}
|
||||
|
||||
pub extern "C" fn block_hook_proxy<D, F>(
|
||||
@@ -146,8 +156,11 @@ pub extern "C" fn block_hook_proxy<D, F>(
|
||||
F: FnMut(&mut crate::Unicorn<D>, u64, u32),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, address, size);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, address, size);
|
||||
}
|
||||
|
||||
pub extern "C" fn mem_hook_proxy<D, F>(
|
||||
@@ -162,8 +175,11 @@ where
|
||||
F: FnMut(&mut crate::Unicorn<D>, MemType, u64, usize, i64) -> bool,
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, mem_type, address, size as usize, value)
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, mem_type, address, size as usize, value)
|
||||
}
|
||||
|
||||
pub extern "C" fn intr_hook_proxy<D, F>(uc: uc_handle, value: u32, user_data: *mut UcHook<D, F>)
|
||||
@@ -171,8 +187,11 @@ where
|
||||
F: FnMut(&mut crate::Unicorn<D>, u32),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, value);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, value);
|
||||
}
|
||||
|
||||
pub extern "C" fn insn_in_hook_proxy<D, F>(
|
||||
@@ -180,12 +199,16 @@ pub extern "C" fn insn_in_hook_proxy<D, F>(
|
||||
port: u32,
|
||||
size: usize,
|
||||
user_data: *mut UcHook<D, F>,
|
||||
) where
|
||||
) -> u32
|
||||
where
|
||||
F: FnMut(&mut crate::Unicorn<D>, u32, usize) -> u32,
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, port, size);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, port, size)
|
||||
}
|
||||
|
||||
pub extern "C" fn insn_invalid_hook_proxy<D, F>(uc: uc_handle, user_data: *mut UcHook<D, F>) -> bool
|
||||
@@ -193,8 +216,11 @@ where
|
||||
F: FnMut(&mut crate::Unicorn<D>) -> bool,
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc)
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc)
|
||||
}
|
||||
|
||||
pub extern "C" fn insn_out_hook_proxy<D, F>(
|
||||
@@ -207,8 +233,11 @@ pub extern "C" fn insn_out_hook_proxy<D, F>(
|
||||
F: FnMut(&mut crate::Unicorn<D>, u32, usize, u32),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc, port, size, value);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc, port, size, value);
|
||||
}
|
||||
|
||||
pub extern "C" fn insn_sys_hook_proxy<D, F>(uc: uc_handle, user_data: *mut UcHook<D, F>)
|
||||
@@ -216,6 +245,9 @@ where
|
||||
F: FnMut(&mut crate::Unicorn<D>),
|
||||
{
|
||||
let user_data = unsafe { &mut *user_data };
|
||||
debug_assert_eq!(uc, user_data.uc.get_handle());
|
||||
(user_data.callback)(&mut user_data.uc);
|
||||
let mut user_data_uc = Unicorn {
|
||||
inner: user_data.uc.upgrade().unwrap(),
|
||||
};
|
||||
debug_assert_eq!(uc, user_data_uc.get_handle());
|
||||
(user_data.callback)(&mut user_data_uc);
|
||||
}
|
||||
|
||||
@@ -369,17 +369,13 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut read_data = read_callback.map(|c| {
|
||||
Box::new(ffi::UcHook {
|
||||
callback: c,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
})
|
||||
});
|
||||
let mut write_data = write_callback.map(|c| {
|
||||
Box::new(ffi::UcHook {
|
||||
callback: c,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -388,12 +384,18 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
self.get_handle(),
|
||||
address,
|
||||
size,
|
||||
ffi::mmio_read_callback_proxy::<D, R> as _,
|
||||
match read_data {
|
||||
Some(_) => ffi::mmio_read_callback_proxy::<D, R> as _,
|
||||
None => ptr::null_mut(),
|
||||
},
|
||||
match read_data {
|
||||
Some(ref mut d) => d.as_mut() as *mut _ as _,
|
||||
None => ptr::null_mut(),
|
||||
},
|
||||
ffi::mmio_write_callback_proxy::<D, W> as _,
|
||||
match write_data {
|
||||
Some(_) => ffi::mmio_write_callback_proxy::<D, W> as _,
|
||||
None => ptr::null_mut(),
|
||||
},
|
||||
match write_data {
|
||||
Some(ref mut d) => d.as_mut() as *mut _ as _,
|
||||
None => ptr::null_mut(),
|
||||
@@ -586,7 +588,8 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
return Err(uc_error::ARCH);
|
||||
}
|
||||
|
||||
let err: uc_error = unsafe { ffi::uc_reg_read(self.get_handle(), curr_reg_id, value.as_mut_ptr() as _) };
|
||||
let err: uc_error =
|
||||
unsafe { ffi::uc_reg_read(self.get_handle(), curr_reg_id, value.as_mut_ptr() as _) };
|
||||
|
||||
if err == uc_error::OK {
|
||||
boxed = value.into_boxed_slice();
|
||||
@@ -622,9 +625,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -654,9 +655,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -697,9 +696,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -730,9 +727,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -763,9 +758,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -796,9 +789,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -830,9 +821,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
@@ -870,9 +859,7 @@ impl<'a, D> Unicorn<'a, D> {
|
||||
let mut hook_ptr = core::ptr::null_mut();
|
||||
let mut user_data = Box::new(ffi::UcHook {
|
||||
callback,
|
||||
uc: Unicorn {
|
||||
inner: self.inner.clone(),
|
||||
},
|
||||
uc: Rc::downgrade(&self.inner),
|
||||
});
|
||||
|
||||
let err = unsafe {
|
||||
|
||||
Reference in New Issue
Block a user