iced-x86 1.21.0

iced-x86 is a blazing fast and correct x86/x64 disassembler, assembler and instruction decoder written in Rust
Documentation
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// SPDX-License-Identifier: MIT
// Copyright (C) 2018-present iced project and contributors

macro_rules! write_op0_reg {
	($instruction:ident, $expr:expr) => {
		const _: () = assert!(OpKind::Register as u32 == 0);
		//instruction.set_op0_kind(OpKind::Register);
		debug_assert!($expr < IcedConstants::REGISTER_ENUM_COUNT as u32);
		$instruction.set_op0_register(unsafe { mem::transmute($expr as RegisterUnderlyingType) });
	};
}

macro_rules! write_op1_reg {
	($instruction:ident, $expr:expr) => {
		const _: () = assert!(OpKind::Register as u32 == 0);
		//instruction.set_op1_kind(OpKind::Register);
		debug_assert!($expr < IcedConstants::REGISTER_ENUM_COUNT as u32);
		$instruction.set_op1_register(unsafe { mem::transmute($expr as RegisterUnderlyingType) });
	};
}

macro_rules! write_op2_reg {
	($instruction:ident, $expr:expr) => {
		const _: () = assert!(OpKind::Register as u32 == 0);
		//instruction.set_op2_kind(OpKind::Register);
		debug_assert!($expr < IcedConstants::REGISTER_ENUM_COUNT as u32);
		$instruction.set_op2_register(unsafe { mem::transmute($expr as RegisterUnderlyingType) });
	};
}

#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop")))]
macro_rules! write_op3_reg {
	($instruction:ident, $expr:expr) => {
		const _: () = assert!(OpKind::Register as u32 == 0);
		//instruction.set_op3_kind(OpKind::Register);
		debug_assert!($expr < IcedConstants::REGISTER_ENUM_COUNT as u32);
		$instruction.set_op3_register(unsafe { mem::transmute($expr as RegisterUnderlyingType) });
	};
}

pub(super) mod d3now;
#[cfg(not(feature = "no_evex"))]
pub(super) mod evex;
pub(super) mod fpu;
pub(super) mod legacy;
#[cfg(feature = "mvex")]
pub(super) mod mvex;
pub(super) mod tables;
#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop")))]
pub(super) mod vex;

use crate::decoder::*;
use crate::*;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::convert::TryInto;

// SAFETY:
//	code: let this = unsafe { &*(self_ptr as *const Self) };
// The first arg (`self_ptr`) to decode() is always the handler itself, cast to a `*const OpCodeHandler`.
// All handlers are `#[repr(C)]` structs so the OpCodeHandler fields are always at the same offsets.

pub(super) type OpCodeHandlerDecodeFn = fn(*const OpCodeHandler, &mut Decoder<'_>, &mut Instruction);

#[allow(trivial_casts)]
#[must_use]
#[inline]
pub(super) fn is_null_instance_handler(handler: &OpCodeHandler) -> bool {
	handler as *const _ as *const u8 == &NULL_HANDLER as *const _ as *const u8
}

#[allow(trivial_casts)]
#[must_use]
#[inline]
pub(super) fn get_null_handler() -> (OpCodeHandlerDecodeFn, &'static OpCodeHandler) {
	// SAFETY: it's #[repr(C)] and the first part is an `OpCodeHandler`
	(OpCodeHandler_Invalid::decode, unsafe { &*(&NULL_HANDLER as *const _ as *const OpCodeHandler) })
}

#[allow(trivial_casts)]
#[must_use]
#[inline]
pub(super) fn get_invalid_handler() -> (OpCodeHandlerDecodeFn, &'static OpCodeHandler) {
	// SAFETY: it's #[repr(C)] and the first part is an `OpCodeHandler`
	(OpCodeHandler_Invalid::decode, unsafe { &*(&INVALID_HANDLER as *const _ as *const OpCodeHandler) })
}

#[allow(trivial_casts)]
#[must_use]
#[inline]
pub(super) fn get_invalid_no_modrm_handler() -> (OpCodeHandlerDecodeFn, &'static OpCodeHandler) {
	// SAFETY: it's #[repr(C)] and the first part is an `OpCodeHandler`
	(OpCodeHandler_Invalid::decode, unsafe { &*(&INVALID_NO_MODRM_HANDLER as *const _ as *const OpCodeHandler) })
}

#[rustfmt::skip]
pub(super) static NULL_HANDLER: OpCodeHandler_Invalid = OpCodeHandler_Invalid {
	has_modrm: true,
};
#[rustfmt::skip]
pub(super) static INVALID_HANDLER: OpCodeHandler_Invalid = OpCodeHandler_Invalid {
	has_modrm: true,
};
#[rustfmt::skip]
pub(super) static INVALID_NO_MODRM_HANDLER: OpCodeHandler_Invalid = OpCodeHandler_Invalid {
	has_modrm: false,
};

#[repr(C)]
pub(super) struct OpCodeHandler {
	pub(super) has_modrm: bool,
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Invalid {
	has_modrm: bool,
}

impl OpCodeHandler_Invalid {
	fn decode(_self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, _instruction: &mut Instruction) {
		decoder.set_invalid_instruction();
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Simple {
	has_modrm: bool,
	code: Code,
}

impl OpCodeHandler_Simple {
	#[inline]
	pub(super) fn new(code: Code) -> (OpCodeHandlerDecodeFn, Self) {
		(OpCodeHandler_Simple::decode, Self { has_modrm: false, code })
	}

	#[inline]
	pub(super) fn new_modrm(code: Code) -> (OpCodeHandlerDecodeFn, Self) {
		(OpCodeHandler_Simple::decode, Self { has_modrm: true, code })
	}

	fn decode(self_ptr: *const OpCodeHandler, _decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		instruction.set_code(this.code);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Int3 {
	has_modrm: bool,
}

impl OpCodeHandler_Int3 {
	#[inline]
	pub(super) fn new() -> (OpCodeHandlerDecodeFn, Self) {
		(OpCodeHandler_Int3::decode, Self { has_modrm: false })
	}

	fn decode(_self_ptr: *const OpCodeHandler, _decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		instruction.set_code(Code::Int3);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Group8x8 {
	has_modrm: bool,
	table_low: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 8]>,
	table_high: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 8]>,
}

impl OpCodeHandler_Group8x8 {
	#[inline]
	#[allow(clippy::unwrap_used)]
	pub(super) fn new(
		table_low: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>, table_high: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>,
	) -> (OpCodeHandlerDecodeFn, Self) {
		let table_low = table_low.into_boxed_slice().try_into().ok().unwrap();
		let table_high = table_high.into_boxed_slice().try_into().ok().unwrap();
		(OpCodeHandler_Group8x8::decode, Self { has_modrm: true, table_low, table_high })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		debug_assert!(decoder.state.reg <= 7);
		let (decode, handler) = if decoder.state.mod_ == 3 {
			// SAFETY: reg <= 7 and table_high.len() == 8 (see field type)
			unsafe { *this.table_high.get_unchecked(decoder.state.reg as usize) }
		} else {
			// SAFETY: reg <= 7 and table_low.len() == 8 (see field type)
			unsafe { *this.table_low.get_unchecked(decoder.state.reg as usize) }
		};
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Group8x64 {
	has_modrm: bool,
	table_low: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 8]>,
	table_high: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 0x40]>,
}

impl OpCodeHandler_Group8x64 {
	#[inline]
	#[allow(clippy::unwrap_used)]
	pub(super) fn new(
		table_low: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>, table_high: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>,
	) -> (OpCodeHandlerDecodeFn, Self) {
		let table_low = table_low.into_boxed_slice().try_into().ok().unwrap();
		let table_high = table_high.into_boxed_slice().try_into().ok().unwrap();
		(OpCodeHandler_Group8x64::decode, Self { has_modrm: true, table_low, table_high })
	}

	#[allow(trivial_casts)]
	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (decode, handler) = if decoder.state.mod_ == 3 {
			// SAFETY: table_high.len() == 0x40 (see field type) and index <= 0x3F due to masking `modrm`
			let (decode, handler) = unsafe { *this.table_high.get_unchecked((decoder.state.modrm & 0x3F) as usize) };
			if handler as *const _ as *const u8 == &NULL_HANDLER as *const _ as *const u8 {
				debug_assert!(decoder.state.reg <= 7);
				// SAFETY: reg <= 7 and table_low.len() == 8 (see field type)
				unsafe { *this.table_low.get_unchecked(decoder.state.reg as usize) }
			} else {
				(decode, handler)
			}
		} else {
			debug_assert!(decoder.state.reg <= 7);
			// SAFETY: reg <= 7 and table_low.len() == 8 (see field type)
			unsafe { *this.table_low.get_unchecked(decoder.state.reg as usize) }
		};
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Group {
	has_modrm: bool,
	group_handlers: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 8]>,
}

impl OpCodeHandler_Group {
	#[inline]
	#[allow(clippy::unwrap_used)]
	pub(super) fn new(group_handlers: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>) -> (OpCodeHandlerDecodeFn, Self) {
		let group_handlers = group_handlers.into_boxed_slice().try_into().ok().unwrap();
		(OpCodeHandler_Group::decode, Self { has_modrm: true, group_handlers })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		debug_assert!(decoder.state.reg <= 7);
		// SAFETY: group_handlers.len() == 8 (see field type) and reg <= 7
		let (decode, handler) = unsafe { *this.group_handlers.get_unchecked(decoder.state.reg as usize) };
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_AnotherTable {
	has_modrm: bool,
	handlers: Box<[(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 0x100]>,
}

impl OpCodeHandler_AnotherTable {
	#[allow(clippy::unwrap_used)]
	#[inline]
	pub(super) fn new(handlers: Vec<(OpCodeHandlerDecodeFn, &'static OpCodeHandler)>) -> (OpCodeHandlerDecodeFn, Self) {
		let handlers = handlers.into_boxed_slice().try_into().ok().unwrap();
		(OpCodeHandler_AnotherTable::decode, Self { has_modrm: false, handlers })
	}

	#[allow(clippy::never_loop)]
	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		loop {
			let b = read_u8_break!(decoder);
			let (decode, handler) = this.handlers[b];
			if handler.has_modrm {
				let m = read_u8_break!(decoder) as u32;
				decoder.state.modrm = m;
				decoder.state.reg = (m >> 3) & 7;
				decoder.state.mod_ = m >> 6;
				decoder.state.rm = m & 7;
				decoder.state.mem_index = (decoder.state.mod_ << 3) | decoder.state.rm;
			}
			(decode)(handler, decoder, instruction);
			return;
		}
		decoder.state.flags |= StateFlags::IS_INVALID | StateFlags::NO_MORE_BYTES;
	}
}

#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop"), not(feature = "no_evex"), feature = "mvex"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_MandatoryPrefix2 {
	has_modrm: bool,
	handlers: [(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 4],
}

#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop"), not(feature = "no_evex"), feature = "mvex"))]
impl OpCodeHandler_MandatoryPrefix2 {
	#[inline]
	pub(super) fn new(
		has_modrm: bool, handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler_66: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
		handler_f3: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler_f2: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	) -> (OpCodeHandlerDecodeFn, Self) {
		const _: () = assert!(DecoderMandatoryPrefix::PNP as u32 == 0);
		const _: () = assert!(DecoderMandatoryPrefix::P66 as u32 == 1);
		const _: () = assert!(DecoderMandatoryPrefix::PF3 as u32 == 2);
		const _: () = assert!(DecoderMandatoryPrefix::PF2 as u32 == 3);
		debug_assert!(!is_null_instance_handler(handler.1));
		debug_assert!(!is_null_instance_handler(handler_66.1));
		debug_assert!(!is_null_instance_handler(handler_f3.1));
		debug_assert!(!is_null_instance_handler(handler_f2.1));
		let handlers = [handler, handler_66, handler_f3, handler_f2];
		debug_assert_eq!(handlers[0].1.has_modrm, has_modrm);
		debug_assert_eq!(handlers[1].1.has_modrm, has_modrm);
		debug_assert_eq!(handlers[2].1.has_modrm, has_modrm);
		debug_assert_eq!(handlers[3].1.has_modrm, has_modrm);
		(OpCodeHandler_MandatoryPrefix2::decode, Self { has_modrm, handlers })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		debug_assert!(
			decoder.state.encoding() == EncodingKind::VEX as u32
				|| decoder.state.encoding() == EncodingKind::EVEX as u32
				|| decoder.state.encoding() == EncodingKind::XOP as u32
				|| decoder.state.encoding() == EncodingKind::MVEX as u32
		);
		let (decode, handler) = this.handlers[decoder.state.mandatory_prefix as usize];
		(decode)(handler, decoder, instruction);
	}
}

#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop"), not(feature = "no_evex"), feature = "mvex"))]
#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_W {
	has_modrm: bool,
	handlers: [(OpCodeHandlerDecodeFn, &'static OpCodeHandler); 2],
}

#[cfg(any(not(feature = "no_vex"), not(feature = "no_xop"), not(feature = "no_evex"), feature = "mvex"))]
impl OpCodeHandler_W {
	#[inline]
	pub(super) fn new(
		handler_w0: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler_w1: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(handler_w0.1));
		debug_assert!(!is_null_instance_handler(handler_w1.1));
		(OpCodeHandler_W::decode, Self { has_modrm: true, handlers: [handler_w0, handler_w1] })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		debug_assert!(
			decoder.state.encoding() == EncodingKind::VEX as u32
				|| decoder.state.encoding() == EncodingKind::EVEX as u32
				|| decoder.state.encoding() == EncodingKind::XOP as u32
				|| decoder.state.encoding() == EncodingKind::MVEX as u32
		);
		let (decode, handler) = this.handlers[((decoder.state.flags & StateFlags::W) != 0) as usize];
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Bitness {
	has_modrm: bool,
	handler1632: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	handler64: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
}

impl OpCodeHandler_Bitness {
	#[inline]
	pub(super) fn new(
		handler1632: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler64: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(handler1632.1));
		debug_assert!(!is_null_instance_handler(handler64.1));
		(OpCodeHandler_Bitness::decode, Self { has_modrm: false, handler1632, handler64 })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (decode, handler) = if decoder.is64b_mode { this.handler64 } else { this.handler1632 };
		if handler.has_modrm {
			decoder.read_modrm();
		}
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Bitness_DontReadModRM {
	has_modrm: bool,
	handler1632: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	handler64: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
}

impl OpCodeHandler_Bitness_DontReadModRM {
	#[inline]
	pub(super) fn new(
		handler1632: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler64: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(handler1632.1));
		debug_assert!(!is_null_instance_handler(handler64.1));
		(OpCodeHandler_Bitness_DontReadModRM::decode, Self { has_modrm: true, handler1632, handler64 })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (decode, handler) = if decoder.is64b_mode { this.handler64 } else { this.handler1632 };
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_RM {
	has_modrm: bool,
	reg: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	mem: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
}

impl OpCodeHandler_RM {
	#[inline]
	pub(super) fn new(
		reg: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), mem: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(reg.1));
		debug_assert!(!is_null_instance_handler(mem.1));
		(OpCodeHandler_RM::decode, Self { has_modrm: true, reg, mem })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (decode, handler) = if decoder.state.mod_ == 3 { this.reg } else { this.mem };
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Options1632 {
	has_modrm: bool,
	default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	infos: [(OpCodeHandlerDecodeFn, &'static OpCodeHandler, u32); 2],
	info_options: u32,
}

impl OpCodeHandler_Options1632 {
	#[allow(trivial_casts)]
	#[inline]
	pub(super) fn new(
		default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler1: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options1: u32,
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(default_handler.1));
		debug_assert!(!is_null_instance_handler(handler1.1));
		(
			OpCodeHandler_Options1632::decode,
			Self {
				has_modrm: false,
				default_handler,
				infos: [(handler1.0, handler1.1, options1), (get_invalid_no_modrm_handler().0, get_invalid_no_modrm_handler().1, 0)],
				info_options: options1,
			},
		)
	}

	#[inline]
	pub(super) fn new2(
		default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler1: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options1: u32,
		handler2: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options2: u32,
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(default_handler.1));
		debug_assert!(!is_null_instance_handler(handler1.1));
		debug_assert!(!is_null_instance_handler(handler2.1));
		(
			OpCodeHandler_Options1632::decode,
			Self {
				has_modrm: false,
				default_handler,
				infos: [(handler1.0, handler1.1, options1), (handler2.0, handler2.1, options2)],
				info_options: options1 | options2,
			},
		)
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (mut decode, mut handler) = this.default_handler;
		let options = decoder.options;
		if !decoder.is64b_mode && (decoder.options & this.info_options) != 0 {
			for info in &this.infos {
				if (options & info.2) != 0 {
					decode = info.0;
					handler = info.1;
					break;
				}
			}
		}
		if handler.has_modrm {
			decoder.read_modrm();
		}
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Options {
	has_modrm: bool,
	default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	infos: [(OpCodeHandlerDecodeFn, &'static OpCodeHandler, u32); 2],
	info_options: u32,
}

impl OpCodeHandler_Options {
	#[allow(trivial_casts)]
	#[inline]
	pub(super) fn new(
		default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler1: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options1: u32,
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(default_handler.1));
		debug_assert!(!is_null_instance_handler(handler1.1));
		(
			OpCodeHandler_Options::decode,
			Self {
				has_modrm: false,
				default_handler,
				infos: [(handler1.0, handler1.1, options1), (get_invalid_no_modrm_handler().0, get_invalid_no_modrm_handler().1, 0)],
				info_options: options1,
			},
		)
	}

	#[inline]
	pub(super) fn new2(
		default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), handler1: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options1: u32,
		handler2: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), options2: u32,
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(default_handler.1));
		debug_assert!(!is_null_instance_handler(handler1.1));
		debug_assert!(!is_null_instance_handler(handler2.1));
		(
			OpCodeHandler_Options::decode,
			Self {
				has_modrm: false,
				default_handler,
				infos: [(handler1.0, handler1.1, options1), (handler2.0, handler2.1, options2)],
				info_options: options1 | options2,
			},
		)
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (mut decode, mut handler) = this.default_handler;
		let options = decoder.options;
		if (decoder.options & this.info_options) != 0 {
			for info in &this.infos {
				if (options & info.2) != 0 {
					decode = info.0;
					handler = info.1;
					break;
				}
			}
		}
		if handler.has_modrm {
			decoder.read_modrm();
		}
		(decode)(handler, decoder, instruction);
	}
}

#[allow(non_camel_case_types)]
#[repr(C)]
pub(super) struct OpCodeHandler_Options_DontReadModRM {
	has_modrm: bool,
	default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	opt_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler),
	flags: u32,
}

impl OpCodeHandler_Options_DontReadModRM {
	#[inline]
	pub(super) fn new(
		default_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), opt_handler: (OpCodeHandlerDecodeFn, &'static OpCodeHandler), flags: u32,
	) -> (OpCodeHandlerDecodeFn, Self) {
		debug_assert!(!is_null_instance_handler(default_handler.1));
		debug_assert!(!is_null_instance_handler(opt_handler.1));
		(OpCodeHandler_Options_DontReadModRM::decode, Self { has_modrm: true, default_handler, opt_handler, flags })
	}

	fn decode(self_ptr: *const OpCodeHandler, decoder: &mut Decoder<'_>, instruction: &mut Instruction) {
		let this = unsafe { &*(self_ptr as *const Self) };
		let (mut decode, mut handler) = this.default_handler;
		let options = decoder.options;
		if (options & this.flags) != 0 {
			decode = this.opt_handler.0;
			handler = this.opt_handler.1;
		}
		(decode)(handler, decoder, instruction);
	}
}