Interface.cs 2.9 KB

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