From d0cce2b04c93d1dc1633dfefe61e9a3b8b0e0c66 Mon Sep 17 00:00:00 2001 From: TA Thanh Dinh Date: Thu, 30 Aug 2018 15:12:26 +0200 Subject: [PATCH] add get_version function --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8221c7b..70f5a9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,3 +17,22 @@ pub use mnemonic::*; pub use register::*; pub use status::*; pub use utils::*; + +/// Returns the version of the zydis C library as a quadruple `(major, minor, patch, build)` +/// +/// # Examples +/// ``` +/// use zydis; +/// let (major, minor, patch, build) = zydis::get_version(); +/// println!("Zydis version: {}.{}.{}.{}", major, minor, patch, build); +/// ``` +pub fn get_version() -> (u16, u16, u16, u16) { + let combined_ver = unsafe { + gen::ZydisGetVersion() + }; + let major = ((combined_ver << 0) >> 48) as u16; + let minor = ((combined_ver << 16) >> 48) as u16; + let patch = ((combined_ver << 32) >> 48) as u16; + let build = ((combined_ver << 48) >> 48) as u16; + (major, minor, patch, build) +}