Skip to content

Commit 5003c8a

Browse files
committed
feat: add cheat and target
1 parent 9ee2346 commit 5003c8a

File tree

6 files changed

+140
-8
lines changed

6 files changed

+140
-8
lines changed

Cargo.lock

+43-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/cheat/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ edition = "2021"
88
[dependencies]
99
env_logger = "0.10.0"
1010
log = "0.4.17"
11+
12+
hax = { git = "https://github.com/hax-rs/hax" }

example/cheat/src/main.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
use hax::ExternalMemory;
2+
use hax::memlib::MemoryReadExt;
3+
use env_logger::Env;
4+
5+
fn test_simple(mem: ExternalMemory) {
6+
// &value
7+
//
8+
let ref_value = 0x7ffc57418314_u64;
9+
let health = mem.read::<u32>(ref_value);
10+
11+
log::info!("&value ({:x}) is pointing to {}", ref_value, health);
12+
13+
// &&value
14+
//
15+
let ref_ref_value = 0x7ffc57418450;
16+
17+
let value = mem.read::<u64>(ref_ref_value);
18+
log::info!("&&value ({:x}) is pointing to {:x}", ref_value, value);
19+
20+
let health = mem.read::<u32>(value as u64);
21+
log::info!("&value ({:x}) is pointing to {:x}", value, health);
22+
}
23+
24+
fn test_struct(mem: ExternalMemory) {
25+
let struct_ptr = 0x7ffd93a2ba40; // &value
26+
let value = mem.read::<u32>(struct_ptr);
27+
28+
log::info!("struct_ptr ({:x}) is pointing to {}", struct_ptr, value);
29+
30+
let armor = mem.read::<u32>(struct_ptr + 4);
31+
let money = mem.read::<u32>(struct_ptr + 8);
32+
33+
log::info!("armor: {}", armor);
34+
log::info!("money: {}", money);
35+
}
36+
37+
138
fn main() {
2-
println!("Hello, world!");
39+
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
40+
41+
let pid = 1270336;
42+
let mem = ExternalMemory::new(pid);
43+
44+
// test_simple(mem);
45+
test_struct(mem);
346
}

example/target/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ edition = "2021"
88
[dependencies]
99
env_logger = "0.10.0"
1010
log = "0.4.17"
11+
memoffset = "0.8.0"

example/target/src/main.rs

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,59 @@
11
use env_logger::Env;
2+
use memoffset::offset_of;
3+
4+
#[derive(Debug, Copy, Clone)]
5+
struct Player {
6+
health: u32,
7+
armor: u32,
8+
money: u32
9+
}
10+
11+
impl Player {
12+
pub fn new() -> Self {
13+
Self {
14+
health: 100,
15+
armor: 200,
16+
money: 1000
17+
}
18+
}
19+
}
220

321
fn main() {
422
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
523

624
log::info!("Example Target Application");
25+
log::info!("Pid: {}", std::process::id());
726

8-
let health = 42;
27+
let health: u32 = 42;
28+
let player = Player::new();
929
loop {
10-
log::info!("Value: {}", health);
11-
log::info!("&value: {:p}", &health);
12-
log::info!("&&value: {:p}", &&health);
30+
log::info!("health: {}", health);
31+
log::info!("&health: {:p}", &health);
32+
log::info!("&&health: {:p}", &&health);
33+
println!();
34+
35+
log::info!("player: {:?}", player);
36+
log::info!("&player: {:p}", &player);
37+
log::info!("&&player: {:p}", &&player);
38+
println!();
39+
40+
log::info!("player.health: {}", player.health);
41+
log::info!("&player.health: {:p}", &player.health);
42+
log::info!("offset: {:x}", offset_of!(Player, health));
43+
println!();
44+
45+
log::info!("player.armor: {}", player.armor);
46+
log::info!("&player.armor: {:p}", &player.armor);
47+
log::info!("offset: {:x}", offset_of!(Player, armor));
48+
println!();
49+
50+
log::info!("player.money: {}", player.money);
51+
log::info!("&player.money: {:p}", &player.money);
52+
log::info!("offset: {:x}", offset_of!(Player, money));
53+
println!();
54+
55+
56+
1357

1458
// Wait for user input
1559
//

slides/slides.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ marp: true
2929
- [IDA Free](https://hex-rays.com/ida-free/)
3030
- [Rust](https://rustup.rs/)
3131
- [VSCode](https://code.visualstudio.com/download) with Rust Analyzer extension
32+
- [Cheat Engine](https://www.cheatengine.org/) (Windows)
33+
- [Scanmem](https://github.com/scanmem/scanmem) (Linux)
3234

3335

3436
---

0 commit comments

Comments
 (0)