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
|
use yaxpeax_x86::protected_mode::{InstDecoder, Operand, RegSpec};
use yaxpeax_x86::MemoryAccessSize;
#[test]
fn register_widths() {
assert_eq!(Operand::Register(RegSpec::esp()).width(), Some(4));
assert_eq!(Operand::Register(RegSpec::sp()).width(), Some(2));
assert_eq!(Operand::Register(RegSpec::cl()).width(), Some(1));
assert_eq!(Operand::Register(RegSpec::ch()).width(), Some(1));
assert_eq!(Operand::Register(RegSpec::gs()).width(), Some(2));
}
#[test]
fn memory_widths() {
// the register operand directly doesn't report a size - it comes from the `Instruction` for
// which this is an operand.
assert_eq!(Operand::RegDeref(RegSpec::esp()).width(), None);
fn mem_size_of(data: &[u8]) -> MemoryAccessSize {
let decoder = InstDecoder::default();
decoder.decode_slice(data).unwrap().mem_size().unwrap()
}
// and checking the memory size direcly reports correct names
assert_eq!(mem_size_of(&[0x32, 0x00]).size_name(), "byte");
assert_eq!(mem_size_of(&[0x66, 0x33, 0x00]).size_name(), "word");
assert_eq!(mem_size_of(&[0x33, 0x00]).size_name(), "dword");
}
#[test]
fn test_implied_memory_width() {
fn mem_size_of(data: &[u8]) -> Option<u8> {
let decoder = InstDecoder::default();
decoder.decode_slice(data).unwrap().mem_size().unwrap().bytes_size()
}
// test push, pop, call, and ret
assert_eq!(mem_size_of(&[0xc3]), Some(4));
assert_eq!(mem_size_of(&[0xe8, 0x11, 0x22, 0x33, 0x44]), Some(4));
assert_eq!(mem_size_of(&[0x50]), Some(4));
assert_eq!(mem_size_of(&[0x58]), Some(4));
assert_eq!(mem_size_of(&[0x66, 0x50]), Some(4));
assert_eq!(mem_size_of(&[0x66, 0x58]), Some(4));
assert_eq!(mem_size_of(&[0xff, 0xf0]), Some(4));
assert_eq!(mem_size_of(&[0x66, 0xff, 0xf0]), Some(2));
}
|