From ec8d4f3af5d951776ab9d494ca1c5cae7809c08f Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Thu, 9 Feb 2023 02:24:32 +0100 Subject: Replace unicorn bindings with Nuget package (#4378) * Replace unicorn bindings with Nuget package * Use nameof for ValueSource args * Remove redundant code from test projects * Fix wrong values for EmuStart() Add notes to address this later again * Improve formatting * Fix formatting/alignment issues --- Ryujinx.Tests.Unicorn/Native/Interface.cs | 101 ------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 Ryujinx.Tests.Unicorn/Native/Interface.cs (limited to 'Ryujinx.Tests.Unicorn/Native/Interface.cs') diff --git a/Ryujinx.Tests.Unicorn/Native/Interface.cs b/Ryujinx.Tests.Unicorn/Native/Interface.cs deleted file mode 100644 index 4e34ee8b..00000000 --- a/Ryujinx.Tests.Unicorn/Native/Interface.cs +++ /dev/null @@ -1,101 +0,0 @@ -using Ryujinx.Tests.Unicorn.Native.Const; -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Ryujinx.Tests.Unicorn.Native -{ - public static partial class Interface - { - public static bool IsUnicornAvailable { get; private set; } = true; - - private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) - { - if (libraryName == "unicorn") - { - string loadPath = $"{Path.GetDirectoryName(assembly.Location)}/"; - loadPath += OperatingSystem.IsWindows() ? $"{libraryName}.dll" : $"lib{libraryName}.so"; - - if (!NativeLibrary.TryLoad(loadPath, out IntPtr libraryPtr)) - { - IsUnicornAvailable = false; - Console.Error.WriteLine($"ERROR: Could not find unicorn at: {loadPath}"); - } - - return libraryPtr; - } - - // Otherwise, fallback to default import resolver. - return IntPtr.Zero; - } - - static Interface() - { - NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), ImportResolver); - } - - public static void Checked(Error error) - { - if (error != Error.OK) - { - throw new UnicornException(error); - } - } - - public static void MarshalArrayOf<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(IntPtr input, int length, out T[] output) - { - int size = Marshal.SizeOf(); - - output = new T[length]; - - for (int i = 0; i < length; i++) - { - IntPtr item = new IntPtr(input.ToInt64() + i * size); - - output[i] = Marshal.PtrToStructure(item); - } - } - - [LibraryImport("unicorn")] - public static partial uint uc_version(out uint major, out uint minor); - - [LibraryImport("unicorn")] - public static partial Error uc_open(Arch arch, Mode mode, out IntPtr uc); - - [LibraryImport("unicorn")] - public static partial Error uc_close(IntPtr uc); - - [LibraryImport("unicorn")] - public static partial IntPtr uc_strerror(Error err); - - [LibraryImport("unicorn")] - public static partial Error uc_reg_write(IntPtr uc, int regid, byte[] value); - - [LibraryImport("unicorn")] - public static partial Error uc_reg_read(IntPtr uc, int regid, byte[] value); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size); - - [LibraryImport("unicorn")] - public static partial Error uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_unmap(IntPtr uc, ulong address, ulong size); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms); - - [LibraryImport("unicorn")] - public static partial Error uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count); - } -} \ No newline at end of file -- cgit v1.2.3