diff --git a/.gitignore b/.gitignore index f9422f0..1011c83 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /build Cargo.lock **/.DS_Store -.cargo \ No newline at end of file +.cargo +RELEASE \ No newline at end of file diff --git a/build.sh b/build.sh index 8938d43..c5c46c5 100755 --- a/build.sh +++ b/build.sh @@ -28,6 +28,8 @@ cargo +nightly build -Z build-std=std,panic_abort,core,alloc -Z build-std-featur RELEASE_DIR=RELEASE/$TARGET +mkdir -p $RELEASE_DIR + cp target/$TARGET/release/libptrscan.dylib $RELEASE_DIR cp target/$TARGET/release/ptrscan $RELEASE_DIR cp libptrscan/libptrs.h $RELEASE_DIR @@ -44,6 +46,8 @@ cargo +nightly build -Z build-std=std,panic_abort,core,alloc -Z build-std-featur RELEASE_DIR=RELEASE/$TARGET +mkdir -p $RELEASE_DIR + cp target/$TARGET/release/libptrscan.so $RELEASE_DIR cp target/$TARGET/release/ptrscan $RELEASE_DIR cp libptrscan/libptrs.h $RELEASE_DIR @@ -60,6 +64,8 @@ cargo +nightly build -Z build-std=std,panic_abort,core,alloc -Z build-std-featur RELEASE_DIR=RELEASE/$TARGET +mkdir -p $RELEASE_DIR + cp target/$TARGET/release/libptrscan.so $RELEASE_DIR cp target/$TARGET/release/ptrscan $RELEASE_DIR cp libptrscan/libptrs.h $RELEASE_DIR diff --git a/command/build.rs b/command/build.rs index ec79ac8..1880ee6 100644 --- a/command/build.rs +++ b/command/build.rs @@ -1,4 +1,4 @@ -use std::path::Path; +use std::{fs, path::Path}; fn main() { let out_dir = std::env::var("OUT_DIR").unwrap(); @@ -8,7 +8,27 @@ fn main() { .parent() .unwrap() .parent() + .unwrap() + .join("deps"); + + let target = std::env::var("TARGET").unwrap(); + + // fuck https://github.com/rust-lang/rust/issues/44322 + const LINUX: [&str; 2] = ["x86_64-unknown-linux-gnu", "aarch64-linux-android"]; + if LINUX.contains(&target.as_str()) { + println!("cargo:rustc-link-arg=-Wl,--allow-multiple-definition"); + println!("cargo:rustc-link-search={}", path.display()); + } + + const APPLE: [&str; 2] = ["aarch64-apple-darwin", "aarch64-apple-ios"]; + if APPLE.contains(&target.as_str()) { + // fuck https://github.com/rust-lang/rust/issues/124462 + fs::rename( + path.join("libptrscan.dylib"), + path.join("this.not.static.libptrscan.dylib"), + ) .unwrap(); - println!("cargo:rustc-link-search={}", path.display()); - println!("cargo:rustc-link-lib=static=ptrscan"); + + println!("cargo:rustc-link-search={}", path.display()); + } } diff --git a/command/src/cmd.rs b/command/src/cmd.rs index 2bf15ee..58a0567 100644 --- a/command/src/cmd.rs +++ b/command/src/cmd.rs @@ -536,9 +536,9 @@ pub fn parse_pointer_chain(value: &str) -> Option<(String, usize, Vec)> { let mut iter = b.split('.'); let module_offset = iter .next() - .and_then(|s| usize::from_str_radix(s, 16).ok())?; + .and_then(|s| usize::from_str_radix(s.trim_start_matches("0x"), 16).ok())?; let pointer_chain = iter - .map(|s| isize::from_str_radix(s, 16)) + .map(|s| isize::from_str_radix(s.trim_start_matches("0x"), 16)) .collect::, _>>() .ok()?; Some((module_name.to_string(), module_offset, pointer_chain)) @@ -567,7 +567,7 @@ impl TestPointerChain { .and_then(|Module { start, .. }| start.checked_add(offset)) .ok_or("invalid base address")?; - println!("{name} + {offset} = {address:x}"); + println!("{name} + {offset:x} = {address:x}"); let mut buf = [0_u8; mem::size_of::()]; for offset in chain { @@ -575,7 +575,7 @@ impl TestPointerChain { address = usize::from_ne_bytes(buf) .checked_add_signed(offset) .ok_or("invalid offset address")?; - println!("+ {offset} = {address:x}"); + println!("+ {offset:x} = {address:x}"); } Ok(())