diff --git a/bindings/dotnet/README.md b/bindings/dotnet/README.md new file mode 100644 index 00000000..77171645 --- /dev/null +++ b/bindings/dotnet/README.md @@ -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. diff --git a/bindings/dotnet/Unicorn/Const/Spark.fs b/bindings/dotnet/Unicorn/Const/Sparc.fs similarity index 99% rename from bindings/dotnet/Unicorn/Const/Spark.fs rename to bindings/dotnet/Unicorn/Const/Sparc.fs index 26e3ec00..a7f71bd7 100644 --- a/bindings/dotnet/Unicorn/Const/Spark.fs +++ b/bindings/dotnet/Unicorn/Const/Sparc.fs @@ -24,7 +24,7 @@ namespace UnicornEngine.Const open System [] -module Spark = +module Sparc = // SPARC registers let UC_SPARC_REG_INVALID = 0 diff --git a/bindings/dotnet/Unicorn/Unicorn.fsproj b/bindings/dotnet/Unicorn/Unicorn.fsproj index 9c67c348..adc80fff 100644 --- a/bindings/dotnet/Unicorn/Unicorn.fsproj +++ b/bindings/dotnet/Unicorn/Unicorn.fsproj @@ -49,7 +49,7 @@ - + diff --git a/bindings/dotnet/UnicornTests/Program.cs b/bindings/dotnet/UnicornTests/Program.cs index ac9eac99..89fa9687 100644 --- a/bindings/dotnet/UnicornTests/Program.cs +++ b/bindings/dotnet/UnicornTests/Program.cs @@ -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 ints) - { - var bytes = new List(); - 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))); diff --git a/bindings/dotnet/UnicornTests/UnicornTests.csproj b/bindings/dotnet/UnicornTests/UnicornTests.csproj index 3126ea8d..1d17dd61 100644 --- a/bindings/dotnet/UnicornTests/UnicornTests.csproj +++ b/bindings/dotnet/UnicornTests/UnicornTests.csproj @@ -31,7 +31,7 @@ TRACE prompt 4 - true + false