aboutsummaryrefslogtreecommitdiff
path: root/differential-tests/tests/capstone-differential.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-03-17 08:58:26 +0000
committeriximeow <me@iximeow.net>2024-03-17 08:58:26 +0000
commit1840e5e026b1e1c7f61f1c5a2cade4dc2deda4c4 (patch)
tree67109c5bfbf026039e3d2bb01a20d303f85bdbb7 /differential-tests/tests/capstone-differential.rs
parent6ed26619c09e1d43572e17642e89161ab8e429b0 (diff)
differential test: use raw capstone interface to avoid reallocating cs_insn
Diffstat (limited to 'differential-tests/tests/capstone-differential.rs')
-rw-r--r--differential-tests/tests/capstone-differential.rs42
1 files changed, 35 insertions, 7 deletions
diff --git a/differential-tests/tests/capstone-differential.rs b/differential-tests/tests/capstone-differential.rs
index 36274b5..7bfc7b4 100644
--- a/differential-tests/tests/capstone-differential.rs
+++ b/differential-tests/tests/capstone-differential.rs
@@ -356,11 +356,19 @@ fn capstone_differential() {
};
fn test_range(start: u64, end: u64, stats: Arc<Stats>) {
+ let mut csh: capstone_sys::csh = capstone_sys::csh::default();
+ assert_eq!(
+ unsafe { capstone_sys::cs_open(capstone_sys::cs_arch::CS_ARCH_ARM64, capstone_sys::cs_mode(0), &mut csh as *mut capstone_sys::csh) },
+ 0
+ );
+ let mut cs_insn: *mut capstone_sys::cs_insn = unsafe { libc::malloc(std::mem::size_of::<capstone_sys::cs_insn>()) as *mut capstone_sys::cs_insn };
+ /*
let cs = Capstone::new()
.arm64()
.mode(capstone::arch::arm64::ArchMode::Arm)
.build()
.expect("can create capstone");
+ */
let yax = <yaxpeax_arm::armv8::a64::ARMv8 as Arch>::Decoder::default();
@@ -371,14 +379,34 @@ fn capstone_differential() {
eprintln!("case {:08x}", i);
}
- let res = cs.disasm_all(bytes, 0);
- if let Ok(insts) = &res {
- let insts_slice = insts.as_ref();
- if insts_slice.len() == 1 {
+ let mut address = 0;
+// let res = cs.disasm_all(bytes, 0);
+ let res = unsafe {
+ capstone_sys::cs_disasm_iter(
+ csh,
+ &mut bytes.as_ptr() as *mut *const u8,
+ &mut bytes.len() as *mut usize,
+ &mut 0u64 as *mut u64,
+ cs_insn,
+ )
+ };
+// if let Ok(insts) = &res {
+ if res {
+// let insts_slice = insts.as_ref();
+// if insts_slice.len() == 1 {
+ {
// then yax should also succeed..
// and it should only be one instruction
- let cs_text = format!("{}", insts_slice[0]);
- let cs_text = &cs_text[5..];
+// let cs_text = format!("{}", insts_slice[0]);
+// let cs_text = &cs_text[5..];
+ let cs_text = unsafe {
+ use std::ffi::CStr;
+ format!("{} {}",
+ CStr::from_ptr((*cs_insn).mnemonic.as_ptr()).to_str().unwrap(),
+ CStr::from_ptr((*cs_insn).op_str.as_ptr()).to_str().unwrap(),
+ )
+ };
+ let cs_text = &cs_text;
let yax_res = yax.decode(&mut yaxpeax_arch::U8Reader::new(bytes));
let yax_text = if let Ok(inst) = yax_res {
@@ -567,7 +595,7 @@ fn capstone_differential() {
} else {
stats.good.fetch_add(1, Ordering::Relaxed);
}
- } else {
+// } else {
// yax should also fail?
}
}