From b8b7d8c4fc128af28acb65c74b656d26be3117f5 Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 1 Jun 2024 05:51:32 +0800 Subject: [PATCH] Fix --- Cargo.lock | 5 +++-- Cargo.toml | 1 + examples/il-test.rs | 3 ++- fuzz/Cargo.lock | 53 ++++++++++++++++++++++----------------------- src/lib.rs | 5 ----- src/wrapper.rs | 16 +++++++++----- 6 files changed, 43 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53a1637..b707a55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,9 +565,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -834,6 +834,7 @@ dependencies = [ "criterion", "glob", "itertools 0.12.1", + "libc", "rand", ] diff --git a/Cargo.toml b/Cargo.toml index 678462f..9bdb0db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,3 +36,4 @@ harness = false [dependencies] anyhow = "1.0.86" +libc = "0.2.155" diff --git a/examples/il-test.rs b/examples/il-test.rs index e2acf95..66083f0 100644 --- a/examples/il-test.rs +++ b/examples/il-test.rs @@ -1,6 +1,7 @@ use rizin_rs::wrapper::Core; +use anyhow::Result; -fn main() -> Result<(), ()> { +fn main() -> Result<()> { let core = Core::new(); core.set("analysis.arch", "pic")?; core.set("analysis.cpu", "pic18")?; diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 48a26b2..7903a6d 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -11,27 +11,31 @@ dependencies = [ "memchr", ] +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + [[package]] name = "arbitrary" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e" -dependencies = [ - "derive_arbitrary", -] [[package]] name = "bindgen" -version = "0.66.1" -source = "git+https://github.com/rust-lang/rust-bindgen.git?branch=main#820ca42982fe77d5504f7a0534a3de6db6a1d703" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ "bitflags", "cexpr", "clang-sys", + "itertools", "lazy_static", "lazycell", "log", - "peeking_take_while", "prettyplease", "proc-macro2", "quote", @@ -84,17 +88,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "derive_arbitrary" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "either" version = "1.9.0" @@ -137,6 +130,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "jobserver" version = "0.1.26" @@ -160,9 +162,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libfuzzer-sys" @@ -225,12 +227,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "prettyplease" version = "0.2.14" @@ -290,10 +286,13 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "rizin-rs" -version = "0.1.0" +version = "0.1.2" dependencies = [ - "arbitrary", + "anyhow", "bindgen", + "glob", + "itertools", + "libc", ] [[package]] diff --git a/src/lib.rs b/src/lib.rs index 7c9adb3..afc45f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,9 +32,4 @@ mod tests { } } } - - #[test] - fn test_none() { - assert!(true); - } } diff --git a/src/wrapper.rs b/src/wrapper.rs index 6d345bd..52eac4f 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,13 +1,14 @@ -use anyhow::anyhow; use std::ffi::{CStr, CString}; use std::fmt::Display; use std::marker::PhantomData; -use std::mem::ManuallyDrop; +use std::mem::{ManuallyDrop, size_of}; use std::ops::{Deref, DerefMut}; use std::path::PathBuf; use std::ptr::{addr_of, addr_of_mut, null_mut, NonNull}; use std::{fmt, result, slice}; +use anyhow::anyhow; + use crate::*; pub type Result = anyhow::Result; @@ -173,8 +174,12 @@ pub struct DwarfAbbrev(pub NonNull); impl DwarfAbbrev { pub fn new(input: &[u8]) -> Result { - let mut R = RzBinEndianReader::new(input, false); - let abbrev = unsafe { rz_bin_dwarf_abbrev_new(addr_of_mut!(R)) }; + let R = RzBinEndianReader::new(input, false); + let abbrev = unsafe { + let ptr = libc::malloc(size_of::()); + libc::memcpy(ptr, addr_of!(R) as _, size_of::()); + rz_bin_dwarf_abbrev_new(ptr as _) + }; NonNull::::new(abbrev) .map(DwarfAbbrev) .ok_or(anyhow!("failed new")) @@ -378,9 +383,10 @@ impl DerefMut for PVector { #[cfg(test)] mod tests { - use crate::wrapper::*; use std::mem::size_of; + use crate::wrapper::*; + #[test] fn test_core() { let _ = Core::new();