Interface.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Ryujinx.Tests.Unicorn;
  4. namespace Ryujinx.Tests.Unicorn.Native
  5. {
  6. public class Interface
  7. {
  8. public static void Checked(UnicornError error)
  9. {
  10. if (error != UnicornError.UC_ERR_OK)
  11. {
  12. throw new UnicornException(error);
  13. }
  14. }
  15. public static void MarshalArrayOf<T>(IntPtr input, int length, out T[] output)
  16. {
  17. var size = Marshal.SizeOf(typeof(T));
  18. output = new T[length];
  19. for (int i = 0; i < length; i++)
  20. {
  21. IntPtr item = new IntPtr(input.ToInt64() + i * size);
  22. output[i] = Marshal.PtrToStructure<T>(item);
  23. }
  24. }
  25. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  26. public static extern uint uc_version(out uint major, out uint minor);
  27. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  28. public static extern UnicornError uc_open(uint arch, uint mode, out IntPtr uc);
  29. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  30. public static extern UnicornError uc_close(IntPtr uc);
  31. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  32. public static extern IntPtr uc_strerror(UnicornError err);
  33. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  34. public static extern UnicornError uc_reg_write(IntPtr uc, int regid, byte[] value);
  35. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  36. public static extern UnicornError uc_reg_read(IntPtr uc, int regid, byte[] value);
  37. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  38. public static extern UnicornError uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size);
  39. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  40. public static extern UnicornError uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size);
  41. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  42. public static extern UnicornError uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count);
  43. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  44. public static extern UnicornError uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms);
  45. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  46. public static extern UnicornError uc_mem_unmap(IntPtr uc, ulong address, ulong size);
  47. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  48. public static extern UnicornError uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms);
  49. [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
  50. public static extern UnicornError uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count);
  51. }
  52. }