Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
暂时修复煞笔rust&&cargo的煞笔链接问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kekeimiku committed May 15, 2024
1 parent 247d44e commit 8abe07f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/build
Cargo.lock
**/.DS_Store
.cargo
.cargo
RELEASE
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
26 changes: 23 additions & 3 deletions command/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::{fs, path::Path};

fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
Expand All @@ -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());
}
}
8 changes: 4 additions & 4 deletions command/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ pub fn parse_pointer_chain(value: &str) -> Option<(String, usize, Vec<isize>)> {
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::<Result<Vec<_>, _>>()
.ok()?;
Some((module_name.to_string(), module_offset, pointer_chain))
Expand Down Expand Up @@ -567,15 +567,15 @@ 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::<usize>()];
for offset in chain {
ptrscan.read_memory_exact(address, &mut buf)?;
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(())
Expand Down

0 comments on commit 8abe07f

Please sign in to comment.