aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Tests.Unicorn/Native/Interface.cs
blob: 59b1da079233d4552278d3bfb211630f63629ca5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Runtime.InteropServices;

namespace Ryujinx.Tests.Unicorn.Native
{
    public class Interface
    {
        public static void Checked(UnicornError error)
        {
            if (error != UnicornError.UC_ERR_OK)
            {
                throw new UnicornException(error);
            }
        }

        public static void MarshalArrayOf<T>(IntPtr input, int length, out T[] output)
        {
            int size = Marshal.SizeOf(typeof(T));

            output = new T[length];

            for (int i = 0; i < length; i++)
            {
                IntPtr item = new IntPtr(input.ToInt64() + i * size);

                output[i] = Marshal.PtrToStructure<T>(item);
            }
        }

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint uc_version(out uint major, out uint minor);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_open(UnicornArch arch, UnicornMode mode, out IntPtr uc);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_close(IntPtr uc);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr uc_strerror(UnicornError err);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_reg_write(IntPtr uc, int regid, byte[] value);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_reg_read(IntPtr uc, int regid, byte[] value);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_unmap(IntPtr uc, ulong address, ulong size);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms);

        [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
        public static extern UnicornError uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count);
    }
}