Fixed typo and minor code refactoring

This commit is contained in:
Antonio Parata 2015-10-14 15:05:18 +02:00
parent 7a105c495b
commit c1423332d4
5 changed files with 42 additions and 24 deletions

30
bindings/dotnet/README.md Normal file
View 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.

View file

@ -24,7 +24,7 @@ namespace UnicornEngine.Const
open System
[<AutoOpen>]
module Spark =
module Sparc =
// SPARC registers
let UC_SPARC_REG_INVALID = 0

View file

@ -49,7 +49,7 @@
<Compile Include="Const\Common.fs" />
<Compile Include="Const\M68k.fs" />
<Compile Include="Const\Mips.fs" />
<Compile Include="Const\Spark.fs" />
<Compile Include="Const\Sparc.fs" />
<Compile Include="Const\X86.fs" />
<Compile Include="Const\UcError.fs" />
<Compile Include="Hooks.fs" />

View file

@ -30,13 +30,13 @@ namespace UnicornTests
class Program
{
private const Int64 ADDRESS = 0x1000000;
private static Int32[] 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,
65, 65, 117, -23, -1, -26, -24, -33, -1, -1, -1, 49, -46, 106, 11, 88, -103, 82, 104, 47, 47, 115, 104,
104, 47, 98, 105, 110, -119, -29, 82, 83, -119, -31, -54, 125, 65, 65, 65, 65, 65, 65, 65, 65
};
private static Byte[] X86_CODE32_SELF =
{
0xeb, 0x19, 0x31, 0xc0, 0x31, 0xdb, 0x31, 0xd2, 0x31, 0xc9, 0xb0, 0x04, 0xb3, 0x01, 0x59, 0xb2, 0x05, 0xcd,
0x80, 0x31, 0xc0, 0xb0, 0x01, 0x31, 0xdb, 0xcd, 0x80, 0xe8, 0xe2, 0xff, 0xff, 0xff, 0x68, 0x65, 0x6c, 0x6c,
0x6f
};
private static UInt64 ToInt(Byte[] val)
{
@ -49,7 +49,6 @@ namespace UnicornTests
return res;
}
private static void CheckError(Int32 err)
{
if (err != Common.UC_ERR_OK)
@ -69,17 +68,6 @@ namespace UnicornTests
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)
{
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);
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));
// 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
CheckError(u.RegWrite(X86.UC_X86_REG_ESP, Int64ToBytes(ADDRESS + 0x200000)));

View file

@ -31,7 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />