libunicorn_sys/unicorn_const.rs
1#![allow(non_camel_case_types)]
2use bitflags::bitflags;
3
4pub const SECOND_SCALE: u64 = 1000000;
5pub const MILISECOND_SCALE: u64 = 1000;
6
7// Architecture type
8#[repr(C)]
9#[derive(PartialEq, Debug, Clone, Copy)]
10pub enum Arch {
11 /// ARM architecture (including Thumb, Thumb-2)
12 ARM = 1,
13 /// ARM-64, also called AArch64
14 ARM64,
15 /// MIPS architecture
16 MIPS,
17 /// X86 architecture (including x86 & x86-64)
18 X86,
19 /// PowerPC architecture
20 PPC,
21 /// Sparc architecture
22 SPARC,
23 /// M68K architecture
24 M68K,
25}
26
27// Mode type
28#[repr(C)]
29#[derive(PartialEq, Debug, Clone, Copy)]
30pub enum Mode {
31 LITTLE_ENDIAN = 0, // little-endian mode (default mode)
32 // MODE_ARM = 0, // 32-bit ARM
33 MODE_16 = 1 << 1, // 16-bit mode (X86)
34 MODE_32 = 1 << 2, // 32-bit mode (X86)
35 MODE_64 = 1 << 3, // 64-bit mode (X86, PPC)
36 THUMB = 1 << 4, // ARM's Thumb mode, including Thumb-2
37 MCLASS = 1 << 5, // ARM's Cortex-M series
38 V8 = 1 << 6, // ARMv8 A32 encodings for ARM
39 // MICRO = 1 << 4, // MicroMips mode (MIPS)
40 // MIPS3 = 1 << 5, // Mips III ISA
41 // MIPS32R6 = 1 << 6, // Mips32r6 ISA
42 // V9 = 1 << 4, // SparcV9 mode (Sparc)
43 // QPX = 1 << 4, // Quad Processing eXtensions mode (PPC)
44 BIG_ENDIAN = 1 << 30, /* big-endian mode
45 * UC_MODE_MIPS32 = UC_MODE_32, // Mips32 ISA (Mips)
46 * UC_MODE_MIPS64 = UC_MODE_64, // Mips64 ISA (Mips) */
47}
48
49// All type of errors encountered by Unicorn API.
50// These are values returned by uc_errno()
51#[repr(C)]
52#[derive(PartialEq, Debug, Clone, Copy)]
53pub enum Error {
54 OK = 0, // No error: everything was fine
55 NOMEM, // Out-Of-Memory error: uc_open(), uc_emulate()
56 ARCH, // Unsupported architecture: uc_open()
57 HANDLE, // Invalid handle
58 MODE, // Invalid/unsupported mode: uc_open()
59 VERSION, // Unsupported version (bindings)
60 READ_UNMAPPED, // Quit emulation due to READ on unmapped memory: uc_emu_start()
61 WRITE_UNMAPPED, // Quit emulation due to WRITE on unmapped memory: uc_emu_start()
62 ETCH_UNMAPPED, // Quit emulation due to FETCH on unmapped memory: uc_emu_start()
63 HOOK, // Invalid hook type: uc_hook_add()
64 INSN_INVALID, // Quit emulation due to invalid instruction: uc_emu_start()
65 MAP, // Invalid memory mapping: uc_mem_map()
66 WRITE_PROT, // Quit emulation due to UC_MEM_WRITE_PROT violation: uc_emu_start()
67 READ_PROT, // Quit emulation due to UC_MEM_READ_PROT violation: uc_emu_start()
68 FETCH_PROT, // Quit emulation due to UC_MEM_FETCH_PROT violation: uc_emu_start()
69 ARG, // Inavalid argument provided to uc_xxx function (See specific function API)
70 READ_UNALIGNED, // Unaligned read
71 WRITE_UNALIGNED, // Unaligned write
72 FETCH_UNALIGNED, // Unaligned fetch
73 HOOK_EXIST, // hook for this event already existed
74 RESOURCE, // Insufficient resource: uc_emu_start()
75 EXCEPTION, // Unhandled CPU exception
76}
77
78
79bitflags! {
80#[repr(C)]
81pub struct Protection : u32 {
82 const NONE = 0;
83 const READ = 1;
84 const WRITE = 2;
85 const EXEC = 4;
86 const ALL = 7;
87 }
88}
89
90
91#[deprecated]
92/// Use Protection::NONE instead.
93pub const PROT_NONE: Protection = Protection::NONE;
94#[deprecated]
95/// Use Protection::READ instead.
96pub const PROT_READ: Protection = Protection::READ;
97#[deprecated]
98/// Use Protection::WRITE instead.
99pub const PROT_WRITE: Protection = Protection::WRITE;
100#[deprecated]
101/// Use Protection::EXEC instead.
102pub const PROT_EXEC: Protection = Protection::EXEC;
103#[deprecated]
104/// Use Protection::ALL instead.
105pub const PROT_ALL: Protection = Protection::ALL;
106
107#[repr(C)]
108#[derive(Debug, Clone)]
109pub struct MemRegion {
110 /// The start address of the region (inclusive).
111 pub begin: u64,
112 /// The end address of the region (inclusive).
113 pub end: u64,
114 /// The memory permissions of the region.
115 pub perms: Protection,
116}
117
118#[repr(C)]
119#[derive(PartialEq, Debug, Clone)]
120pub enum MemType {
121 READ = 16, // Memory is read from
122 WRITE, // Memory is written to
123 FETCH, // Memory is fetched
124 READ_UNMAPPED, // Unmapped memory is read from
125 WRITE_UNMAPPED, // Unmapped memory is written to
126 MEM_FETCH_UNMAPPED, // Unmapped memory is fetched
127 WRITE_PROT, // Write to write protected, but mapped, memory
128 READ_PROT, // Read from read protected, but mapped, memory
129 FETCH_PROT, // Fetch from non-executable, but mapped, memory
130}
131
132#[repr(C)]
133#[derive(PartialEq, Debug, Clone, Copy)]
134pub enum HookType {
135 INTR = 1 << 0, // Hook all interrupt/syscall events
136 INSN = 1 << 1, // Hook a particular instruction
137 CODE = 1 << 2, // Hook a range of code
138 BLOCK = 1 << 3, // Hook basic blocks
139 MEM_READ_UNMAPPED = 1 << 4, // Hook for memory read on unmapped memory
140 MEM_WRITE_UNMAPPED = 1 << 5, // Hook for invalid memory write events
141 MEM_FETCH_UNMAPPED = 1 << 6, // Hook for invalid memory fetch for execution events
142 MEM_READ_PROT = 1 << 7, // Hook for memory read on read-protected memory
143 MEM_WRITE_PROT = 1 << 8, // Hook for memory write on write-protected memory
144 MEM_FETCH_PROT = 1 << 9, // Hook for memory fetch on non-executable memory
145 MEM_READ = 1 << 10, // Hook memory read events.
146 MEM_WRITE = 1 << 11, // Hook memory write events.
147 MEM_FETCH = 1 << 12, // Hook memory fetch for execution events
148}
149
150#[repr(C)]
151#[derive(PartialEq, Debug, Clone, Copy)]
152pub enum CodeHookType {
153 CODE = 1 << 2, // Hook a range of code
154 BLOCK = 1 << 3, // Hook basic blocks
155}
156
157#[repr(C)]
158#[derive(PartialEq, Debug, Clone, Copy)]
159pub enum MemHookType {
160 MEM_READ_UNMAPPED = 1 << 4, // Hook for memory read on unmapped memory
161 MEM_WRITE_UNMAPPED = 1 << 5, // Hook for invalid memory write events
162 MEM_FETCH_UNMAPPED = 1 << 6, // Hook for invalid memory fetch for execution events
163 MEM_READ_PROT = 1 << 7, // Hook for memory read on read-protected memory
164 MEM_WRITE_PROT = 1 << 8, // Hook for memory write on write-protected memory
165 MEM_FETCH_PROT = 1 << 9, // Hook for memory fetch on non-executable memory
166 MEM_READ = 1 << 10, // Hook memory read events.
167 MEM_WRITE = 1 << 11, // Hook memory write events.
168 MEM_FETCH = 1 << 12, // Hook memory fetch for execution events
169 MEM_UNMAPPED = 0b111 << 4, // hook type for all events of unmapped memory access
170 MEM_PROT = 0b111 << 7, // hook type for all events of illegal protected memory access
171 MEM_READ_INVALID = (1 << 4) | (1 << 7), /* Hook type for all events of illegal read memory access */
172 MEM_WRITE_INVALID = (1 << 5) | (1 << 8), /* Hook type for all events of illegal write memory access/ */
173 MEM_FETCH_INVALID = (1 << 6) | (1 << 9), /* Hook type for all events of illegal fetch memory access */
174 MEM_INVALID = (0b111111 << 4), // Hook type for all events of illegal memory access
175 MEM_VALID = (0b111 << 10), // Hook type for all events of valid memory access
176 MEM_ALL = 0b111111111 << 4, // Hook type for all events.
177}
178
179#[repr(C)]
180#[derive(PartialEq, Debug, Clone, Copy)]
181pub enum Query {
182 /// The current hardware mode.
183 MODE = 1,
184 /// The page size used by the emulator
185 PAGE_SIZE,
186}
187
188pub const BINDINGS_MAJOR: u32 = 1;
189pub const BINDINGS_MINOR: u32 = 0;