-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to target .NET Standard 1.1 (#344)
* Refactor to target .NET Standard 1.1 * Added Nuget details to .csproj * Reviewed Engine methods and docs; added own Exception type. * Added migration guide for .NET bindings.
- Loading branch information
Showing
34 changed files
with
831 additions
and
962 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
bindings/csharp/Keystone.Net.Tests/Keystone.Net.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<RootNamespace>Keystone.Tests</RootNamespace> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Keystone.Net/Keystone.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
<PackageReference Include="NUnit" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" /> | ||
<PackageReference Include="Shouldly" Version="3.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace Keystone.Tests | ||
{ | ||
[TestFixture] | ||
public class ExecutionTests | ||
{ | ||
[OneTimeSetUp] | ||
public static void InitializeKeystone() | ||
{ | ||
// Ensures the lib could be loaded | ||
Engine.IsArchitectureSupported(Architecture.X86).ShouldBeTrue(); | ||
} | ||
|
||
[Test] | ||
public void ShouldEmitValidX86Data() | ||
{ | ||
using (Engine engine = new Engine(Architecture.X86, Mode.X32) { ThrowOnError = true }) | ||
{ | ||
engine.Assemble("nop", 0).Buffer.ShouldBe(new byte[] { 0x90 }); | ||
engine.Assemble("add eax, eax", 0).Buffer.ShouldBe(new byte[] { 0x01, 0xC0 }); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ShouldEmitValidARMData() | ||
{ | ||
using (Engine engine = new Engine(Architecture.ARM, Mode.ARM) { ThrowOnError = true }) | ||
{ | ||
engine.Assemble("mul r1, r0, r0", 0).Buffer.ShouldBe(new byte[] { 0x90, 0x00, 0x01, 0xE0 }); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ShouldThrowOnError() | ||
{ | ||
using (Engine engine = new Engine(Architecture.ARM, Mode.ARM) { ThrowOnError = false }) | ||
{ | ||
engine.Assemble("push eax, 0x42", 0).ShouldBeNull(); | ||
engine.Assemble("doesntexist", 0).ShouldBeNull(); | ||
} | ||
|
||
using (Engine engine = new Engine(Architecture.ARM, Mode.ARM) { ThrowOnError = true }) | ||
{ | ||
Should.Throw<KeystoneException>(() => engine.Assemble("push eax, 0x42", 0)); | ||
Should.Throw<KeystoneException>(() => engine.Assemble("doestexist", 0)); | ||
} | ||
} | ||
|
||
[Test, Ignore("Feature requires Keystone built after October 7th 2016.")] | ||
public void ShouldHaveValidExample() | ||
{ | ||
using (Engine keystone = new Engine(Architecture.X86, Mode.X32) { ThrowOnError = true }) | ||
{ | ||
ulong address = 0; | ||
|
||
keystone.ResolveSymbol += (string s, ref ulong w) => | ||
{ | ||
if (s == "_j1") | ||
{ | ||
w = 0x1234abcd; | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
EncodedData enc = keystone.Assemble("xor eax, eax; jmp _j1", address); | ||
|
||
enc.Buffer.ShouldBe(new byte[] { 0x00 }); | ||
enc.Address.ShouldBe(address); | ||
enc.StatementCount.ShouldBe(3); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27130.2036 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Keystone.Net", "Keystone.Net\Keystone.Net.csproj", "{E3579F77-600A-4146-9296-3834B81F16E2}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Keystone.Net.Tests", "Keystone.Net.Tests\Keystone.Net.Tests.csproj", "{377B6FDC-156F-4B8B-B693-2A5C7B604A97}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|x64.Build.0 = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Debug|x86.Build.0 = Debug|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|x64.ActiveCfg = Release|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|x64.Build.0 = Release|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|x86.ActiveCfg = Release|Any CPU | ||
{E3579F77-600A-4146-9296-3834B81F16E2}.Release|x86.Build.0 = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|x64.Build.0 = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Debug|x86.Build.0 = Debug|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|x64.ActiveCfg = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|x64.Build.0 = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|x86.ActiveCfg = Release|Any CPU | ||
{377B6FDC-156F-4B8B-B693-2A5C7B604A97}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {0DA5689F-C570-41D7-93A8-F33F20F4B618} | ||
EndGlobalSection | ||
EndGlobal |
2 changes: 1 addition & 1 deletion
2
...T/KeystoneNET/Constants/ARM64Constants.cs → .../Keystone.Net/Constants/ARM64Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...NET/KeystoneNET/Constants/ARMConstants.cs → ...rp/Keystone.Net/Constants/ARMConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...KeystoneNET/Constants/HexagonConstants.cs → ...eystone.Net/Constants/HexagonConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ET/KeystoneNET/Constants/MipsConstants.cs → ...p/Keystone.Net/Constants/MipsConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...NET/KeystoneNET/Constants/PPCConstants.cs → ...rp/Keystone.Net/Constants/PPCConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...T/KeystoneNET/Constants/SPARCConstants.cs → .../Keystone.Net/Constants/SPARCConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...KeystoneNET/Constants/SystemZConstants.cs → ...eystone.Net/Constants/SystemZConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...NET/KeystoneNET/Constants/X86Constants.cs → ...rp/Keystone.Net/Constants/X86Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Keystone | ||
{ | ||
/// <summary> | ||
/// Defines an encoded instruction or group of instructions. | ||
/// </summary> | ||
public sealed class EncodedData | ||
{ | ||
/// <summary> | ||
/// Constructs the encoded data. | ||
/// </summary> | ||
internal EncodedData(byte[] buffer, int statementCount, ulong address) | ||
{ | ||
Buffer = buffer; | ||
Address = address; | ||
StatementCount = statementCount; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the address of the first instruction for this operation. | ||
/// </summary> | ||
public ulong Address { get; } | ||
|
||
/// <summary> | ||
/// Gets the result of an assembly operation. | ||
/// </summary> | ||
public byte[] Buffer { get; } | ||
|
||
/// <summary> | ||
/// Gets the number of statements found. | ||
/// </summary> | ||
public int StatementCount { get; } | ||
} | ||
} |
Oops, something went wrong.