aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-08-21 12:13:01 -0700
committeriximeow <me@iximeow.net>2021-08-21 12:13:01 -0700
commitcef4feeaf9c64e03a6728f267750ac2fb32eb9ff (patch)
treedcfc974ad5d1beffe629138aebdfa92fbf7f90a5 /test
parent4612215ddc98dabaffedc36f6fe402bb9f04119a (diff)
report memory sizes for push, pop, call, ret
these instructions had memory sizes reported for the operand, if it was a memory operand, but for versions with non-memory operands the decoded `Instruction` would imply that non memory access would happen at all. now, decoded instructions in these cases will report a more useful memory size.
Diffstat (limited to 'test')
-rw-r--r--test/long_mode/operand.rs18
-rw-r--r--test/protected_mode/operand.rs18
-rw-r--r--test/real_mode/mod.rs3
-rw-r--r--test/real_mode/operand.rs20
4 files changed, 59 insertions, 0 deletions
diff --git a/test/long_mode/operand.rs b/test/long_mode/operand.rs
index 7be8d82..4cdaf35 100644
--- a/test/long_mode/operand.rs
+++ b/test/long_mode/operand.rs
@@ -28,3 +28,21 @@ fn memory_widths() {
assert_eq!(mem_size_of(&[0x33, 0x00]).size_name(), "dword");
assert_eq!(mem_size_of(&[0x48, 0x33, 0x00]).size_name(), "qword");
}
+
+#[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(8));
+ assert_eq!(mem_size_of(&[0xe8, 0x11, 0x22, 0x33, 0x44]), Some(8));
+ assert_eq!(mem_size_of(&[0x50]), Some(8));
+ assert_eq!(mem_size_of(&[0x58]), Some(8));
+ assert_eq!(mem_size_of(&[0x66, 0x50]), Some(8));
+ assert_eq!(mem_size_of(&[0x66, 0x58]), Some(8));
+ assert_eq!(mem_size_of(&[0xff, 0xf0]), Some(8));
+ assert_eq!(mem_size_of(&[0x66, 0xff, 0xf0]), Some(2));
+}
diff --git a/test/protected_mode/operand.rs b/test/protected_mode/operand.rs
index fd850da..a114e69 100644
--- a/test/protected_mode/operand.rs
+++ b/test/protected_mode/operand.rs
@@ -26,3 +26,21 @@ fn memory_widths() {
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));
+}
diff --git a/test/real_mode/mod.rs b/test/real_mode/mod.rs
index 6005f07..8543fae 100644
--- a/test/real_mode/mod.rs
+++ b/test/real_mode/mod.rs
@@ -1,3 +1,5 @@
+mod operand;
+
use std::fmt::Write;
use yaxpeax_arch::{AddressBase, Decoder, U8Reader, LengthedInstruction};
@@ -17892,6 +17894,7 @@ fn test_real_mode() {
test_display(&[0xff, 0x08], "dec word [bx + si]");
test_display(&[0xff, 0x15], "call word [di]");
test_display(&[0x67, 0xff, 0x15, 0x12, 0x12, 0x12, 0x12], "call word [0x12121212]");
+ // note that this call only writes two bytes, and only moves sp by two.
test_display(&[0x66, 0xff, 0x15], "call dword [di]");
test_display(&[0xff, 0x18], "callf dword [bx + si]");
test_display(&[0xff, 0x24], "jmp word [si]");
diff --git a/test/real_mode/operand.rs b/test/real_mode/operand.rs
new file mode 100644
index 0000000..e037fee
--- /dev/null
+++ b/test/real_mode/operand.rs
@@ -0,0 +1,20 @@
+use yaxpeax_x86::real_mode::{InstDecoder, Operand, RegSpec};
+use yaxpeax_x86::MemoryAccessSize;
+
+#[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(2));
+ assert_eq!(mem_size_of(&[0xe8, 0x11, 0x22, 0x33, 0x44]), Some(2));
+ assert_eq!(mem_size_of(&[0x50]), Some(2));
+ assert_eq!(mem_size_of(&[0x58]), Some(2));
+ assert_eq!(mem_size_of(&[0x66, 0x50]), Some(2));
+ assert_eq!(mem_size_of(&[0x66, 0x58]), Some(2));
+ assert_eq!(mem_size_of(&[0xff, 0xf0]), Some(2));
+ assert_eq!(mem_size_of(&[0x66, 0xff, 0xf0]), Some(4));
+}