Update constants of bindings

This commit is contained in:
Bet4
2022-02-16 20:08:17 +08:00
parent cc45585e90
commit 504b31b928
18 changed files with 309 additions and 150 deletions

View File

@@ -40,11 +40,13 @@ mod m68k;
mod mips;
mod ppc;
mod riscv;
mod s390x;
mod sparc;
mod x86;
pub use crate::{
arm::*, arm64::*, m68k::*, mips::*, ppc::*, riscv::*, sparc::*, unicorn_const::*, x86::*,
arm::*, arm64::*, m68k::*, mips::*, ppc::*, riscv::*, s390x::*, sparc::*, unicorn_const::*,
x86::*,
};
use alloc::{boxed::Box, rc::Rc, vec::Vec};
@@ -164,7 +166,7 @@ impl<'a> TryFrom<uc_handle> for Unicorn<'a, ()> {
type Error = uc_error;
fn try_from(handle: uc_handle) -> Result<Unicorn<'a, ()>, uc_error> {
if handle == ptr::null_mut() {
if handle.is_null() {
return Err(uc_error::HANDLE);
}
let mut arch: libc::size_t = Default::default();
@@ -514,7 +516,8 @@ impl<'a, D> Unicorn<'a, D> {
/// The user has to make sure that the buffer length matches the register size.
/// This adds support for registers >64 bit (GDTR/IDTR, XMM, YMM, ZMM (x86); Q, V (arm64)).
pub fn reg_write_long<T: Into<i32>>(&self, regid: T, value: &[u8]) -> Result<(), uc_error> {
let err = unsafe { ffi::uc_reg_write(self.get_handle(), regid.into(), value.as_ptr() as _) };
let err =
unsafe { ffi::uc_reg_write(self.get_handle(), regid.into(), value.as_ptr() as _) };
if err == uc_error::OK {
Ok(())
} else {
@@ -527,8 +530,9 @@ impl<'a, D> Unicorn<'a, D> {
/// Not to be used with registers larger than 64 bit.
pub fn reg_read<T: Into<i32>>(&self, regid: T) -> Result<u64, uc_error> {
let mut value: u64 = 0;
let err =
unsafe { ffi::uc_reg_read(self.get_handle(), regid.into(), &mut value as *mut u64 as _) };
let err = unsafe {
ffi::uc_reg_read(self.get_handle(), regid.into(), &mut value as *mut u64 as _)
};
if err == uc_error::OK {
Ok(value)
} else {
@@ -595,8 +599,9 @@ impl<'a, D> Unicorn<'a, D> {
/// Read a signed 32-bit value from a register.
pub fn reg_read_i32<T: Into<i32>>(&self, regid: T) -> Result<i32, uc_error> {
let mut value: i32 = 0;
let err =
unsafe { ffi::uc_reg_read(self.get_handle(), regid.into(), &mut value as *mut i32 as _) };
let err = unsafe {
ffi::uc_reg_read(self.get_handle(), regid.into(), &mut value as *mut i32 as _)
};
if err == uc_error::OK {
Ok(value)
} else {
@@ -1002,6 +1007,7 @@ impl<'a, D> Unicorn<'a, D> {
Arch::M68K => RegisterM68K::PC as i32,
Arch::PPC => RegisterPPC::PC as i32,
Arch::RISCV => RegisterRISCV::PC as i32,
Arch::S390X => RegisterS390X::PC as i32,
Arch::MAX => panic!("Illegal Arch specified"),
};
self.reg_read(reg)
@@ -1020,6 +1026,7 @@ impl<'a, D> Unicorn<'a, D> {
Arch::M68K => RegisterM68K::PC as i32,
Arch::PPC => RegisterPPC::PC as i32,
Arch::RISCV => RegisterRISCV::PC as i32,
Arch::S390X => RegisterS390X::PC as i32,
Arch::MAX => panic!("Illegal Arch specified"),
};
self.reg_write(reg, value)