Fixed typo and minor code refactoring
This commit is contained in:
30
bindings/dotnet/README.md
Normal file
30
bindings/dotnet/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
This documentation explains how to use the .NET binding for Unicorn
|
||||||
|
from source.
|
||||||
|
|
||||||
|
0. Install the core engine as a dependency
|
||||||
|
|
||||||
|
Follow README in the root directory to compile & install the core.
|
||||||
|
|
||||||
|
1. Compile the code
|
||||||
|
|
||||||
|
[Windows]
|
||||||
|
To compile the code open the UnicornSln.sln with Microsoft Visual
|
||||||
|
Studio 12 or with a newer version and just press Ctrl+Shift+B to build
|
||||||
|
the solution.
|
||||||
|
|
||||||
|
You need to have installed at least version 4.5 of the .NET framework.
|
||||||
|
|
||||||
|
[Linux]
|
||||||
|
TODO
|
||||||
|
|
||||||
|
2. Usage
|
||||||
|
|
||||||
|
The solution includes the testing project UnicornTests with examples
|
||||||
|
of usage.
|
||||||
|
|
||||||
|
In order to use the library in your project just add a reference to
|
||||||
|
the .NET library and be sure to copy the unmanaged unicorn.dll
|
||||||
|
library in the output directory.
|
||||||
|
|
||||||
|
The naming convention used is the Upper Camel Case, this mean that to
|
||||||
|
invoke the uc_mem_read method you have to search for the MemRead method.
|
@ -24,7 +24,7 @@ namespace UnicornEngine.Const
|
|||||||
open System
|
open System
|
||||||
|
|
||||||
[<AutoOpen>]
|
[<AutoOpen>]
|
||||||
module Spark =
|
module Sparc =
|
||||||
|
|
||||||
// SPARC registers
|
// SPARC registers
|
||||||
let UC_SPARC_REG_INVALID = 0
|
let UC_SPARC_REG_INVALID = 0
|
@ -49,7 +49,7 @@
|
|||||||
<Compile Include="Const\Common.fs" />
|
<Compile Include="Const\Common.fs" />
|
||||||
<Compile Include="Const\M68k.fs" />
|
<Compile Include="Const\M68k.fs" />
|
||||||
<Compile Include="Const\Mips.fs" />
|
<Compile Include="Const\Mips.fs" />
|
||||||
<Compile Include="Const\Spark.fs" />
|
<Compile Include="Const\Sparc.fs" />
|
||||||
<Compile Include="Const\X86.fs" />
|
<Compile Include="Const\X86.fs" />
|
||||||
<Compile Include="Const\UcError.fs" />
|
<Compile Include="Const\UcError.fs" />
|
||||||
<Compile Include="Hooks.fs" />
|
<Compile Include="Hooks.fs" />
|
||||||
|
@ -30,13 +30,13 @@ namespace UnicornTests
|
|||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
private const Int64 ADDRESS = 0x1000000;
|
private const Int64 ADDRESS = 0x1000000;
|
||||||
|
|
||||||
private static Int32[] X86_CODE32_SELF =
|
private static Byte[] X86_CODE32_SELF =
|
||||||
{
|
{
|
||||||
-21, 28, 90, -119, -42, -117, 2, 102, 61, -54, 125, 117, 6, 102, 5, 3, 3, -119, 2, -2, -62, 61, 65, 65,
|
0xeb, 0x19, 0x31, 0xc0, 0x31, 0xdb, 0x31, 0xd2, 0x31, 0xc9, 0xb0, 0x04, 0xb3, 0x01, 0x59, 0xb2, 0x05, 0xcd,
|
||||||
65, 65, 117, -23, -1, -26, -24, -33, -1, -1, -1, 49, -46, 106, 11, 88, -103, 82, 104, 47, 47, 115, 104,
|
0x80, 0x31, 0xc0, 0xb0, 0x01, 0x31, 0xdb, 0xcd, 0x80, 0xe8, 0xe2, 0xff, 0xff, 0xff, 0x68, 0x65, 0x6c, 0x6c,
|
||||||
104, 47, 98, 105, 110, -119, -29, 82, 83, -119, -31, -54, 125, 65, 65, 65, 65, 65, 65, 65, 65
|
0x6f
|
||||||
};
|
};
|
||||||
|
|
||||||
private static UInt64 ToInt(Byte[] val)
|
private static UInt64 ToInt(Byte[] val)
|
||||||
{
|
{
|
||||||
@ -49,7 +49,6 @@ namespace UnicornTests
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void CheckError(Int32 err)
|
private static void CheckError(Int32 err)
|
||||||
{
|
{
|
||||||
if (err != Common.UC_ERR_OK)
|
if (err != Common.UC_ERR_OK)
|
||||||
@ -69,17 +68,6 @@ namespace UnicornTests
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Byte[] ToBytes(IEnumerable<int> ints)
|
|
||||||
{
|
|
||||||
var bytes = new List<Byte>();
|
|
||||||
foreach (var i in ints)
|
|
||||||
{
|
|
||||||
var b = (Byte) i;
|
|
||||||
bytes.Add(b);
|
|
||||||
}
|
|
||||||
return bytes.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CodeHookCallback(Unicorn u, UInt64 addr, Int32 size, Object userData)
|
private static void CodeHookCallback(Unicorn u, UInt64 addr, Int32 size, Object userData)
|
||||||
{
|
{
|
||||||
Console.Write("Tracing >>> 0x{0} ", addr.ToString("X"));
|
Console.Write("Tracing >>> 0x{0} ", addr.ToString("X"));
|
||||||
@ -156,7 +144,7 @@ namespace UnicornTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsafe void Main(String[] args)
|
static void Main(String[] args)
|
||||||
{
|
{
|
||||||
var u = new Unicorn((UInt32)Common.UC_ARCH_X86, (UInt32)Common.UC_MODE_32);
|
var u = new Unicorn((UInt32)Common.UC_ARCH_X86, (UInt32)Common.UC_MODE_32);
|
||||||
Console.WriteLine("Unicorn version: {0}", u.Version());
|
Console.WriteLine("Unicorn version: {0}", u.Version());
|
||||||
@ -165,7 +153,7 @@ namespace UnicornTests
|
|||||||
CheckError(u.MemMap(ADDRESS, new UIntPtr(2 * 1024 * 1024), Common.UC_PROT_ALL));
|
CheckError(u.MemMap(ADDRESS, new UIntPtr(2 * 1024 * 1024), Common.UC_PROT_ALL));
|
||||||
|
|
||||||
// write machine code to be emulated to memory
|
// write machine code to be emulated to memory
|
||||||
CheckError(u.MemWrite(ADDRESS, ToBytes(X86_CODE32_SELF)));
|
CheckError(u.MemWrite(ADDRESS, X86_CODE32_SELF));
|
||||||
|
|
||||||
// initialize machine registers
|
// initialize machine registers
|
||||||
CheckError(u.RegWrite(X86.UC_X86_REG_ESP, Int64ToBytes(ADDRESS + 0x200000)));
|
CheckError(u.RegWrite(X86.UC_X86_REG_ESP, Int64ToBytes(ADDRESS + 0x200000)));
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
Reference in New Issue
Block a user