[feat] more powerful modules

This commit is contained in:
rootacite
2025-10-28 00:19:20 +08:00
parent ea1821480f
commit 28253d6806
19 changed files with 1678 additions and 515 deletions

View File

@@ -0,0 +1,49 @@
use crate::elf::ExecuteLinkFile;
use crate::map::MemoryMap;
use crate::processes::{get_pid_by_name, Process};
use anyhow::Context;
use nix::unistd::Pid;
use std::fs;
const GREEN: &str = "\x1b[32m";
const RESET: &str = "\x1b[0m";
mod disassembly;
mod elf;
mod map;
mod processes;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Find our target program
let pid = Pid::from_raw(get_pid_by_name("target")?);
let process = Process::new(pid)?;
let exe = process.get_exe()?;
let maps = process.get_map_str()?;
let lines: Vec<&str> = maps.lines().filter(|&line| !line.is_empty()).collect();
for line in &lines {
println!("{GREEN}[memory map]{RESET} {}", line);
}
let map = MemoryMap::new(&lines);
let bias = map.module_base_address(&exe).unwrap_or(0);
let write_got = process.find_got_pointer_plt("write").unwrap_or(0);
println!("{GREEN}[memory map]{RESET} Bias is {:#016x}", bias);
println!("{GREEN}[memory map]{RESET} pointer to write is at {:#016x}", write_got);
let got_write_vec: [u8; 8] = process.read_memory_vm(write_got as usize, 8)?
.try_into()
.map_err(|_| "Failed to convert Vec to array")?;
let got_write_addr = u64::from_le_bytes(got_write_vec);
let real_write_addr =
process.find_remote_proc("/usr/lib/libc.so.6", "write").context("Failed to find write.")?;
println!(
"{GREEN}[memory map]{RESET} real_write_addr = {:#016x}, got_write_addr = {:#016x}",
real_write_addr, got_write_addr
);
Ok(())
}