Skip to content

Commit 643750d

Browse files
committed
feat: add example cheat
1 parent 5003c8a commit 643750d

File tree

10 files changed

+239
-45
lines changed

10 files changed

+239
-45
lines changed

.envrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
watch_file devenv.nix
2+
watch_file devenv.yaml
3+
watch_file devenv.lock
4+
eval "$(devenv print-dev-env)"

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
target/
2-
!example/target
2+
!example/target
3+
4+
.devenv*
5+
devenv.local.nix

Cargo.lock

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

devenv.lock

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1673522518,
7+
"narHash": "sha256-dnx3rqIPWlKXtmMpgJt0IYVW993NE3hFQbmkTOqF31Q=",
8+
"owner": "cachix",
9+
"repo": "devenv",
10+
"rev": "5ad17277d94133e015307f3dbc2f30f5fe693464",
11+
"type": "github"
12+
},
13+
"original": {
14+
"dir": "src/modules",
15+
"owner": "cachix",
16+
"repo": "devenv",
17+
"type": "github"
18+
}
19+
},
20+
"flake-compat": {
21+
"flake": false,
22+
"locked": {
23+
"lastModified": 1668681692,
24+
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
25+
"owner": "edolstra",
26+
"repo": "flake-compat",
27+
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
28+
"type": "github"
29+
},
30+
"original": {
31+
"owner": "edolstra",
32+
"repo": "flake-compat",
33+
"type": "github"
34+
}
35+
},
36+
"flake-utils": {
37+
"locked": {
38+
"lastModified": 1667395993,
39+
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
40+
"owner": "numtide",
41+
"repo": "flake-utils",
42+
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
43+
"type": "github"
44+
},
45+
"original": {
46+
"owner": "numtide",
47+
"repo": "flake-utils",
48+
"type": "github"
49+
}
50+
},
51+
"gitignore": {
52+
"inputs": {
53+
"nixpkgs": [
54+
"pre-commit-hooks",
55+
"nixpkgs"
56+
]
57+
},
58+
"locked": {
59+
"lastModified": 1660459072,
60+
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
61+
"owner": "hercules-ci",
62+
"repo": "gitignore.nix",
63+
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
64+
"type": "github"
65+
},
66+
"original": {
67+
"owner": "hercules-ci",
68+
"repo": "gitignore.nix",
69+
"type": "github"
70+
}
71+
},
72+
"nixpkgs": {
73+
"locked": {
74+
"lastModified": 1673466167,
75+
"narHash": "sha256-1HzUCtWwHRGzTOHCIKGG0lVL6wvsyPSSyBuIqZWYowc=",
76+
"owner": "NixOS",
77+
"repo": "nixpkgs",
78+
"rev": "68e03abb2fd8db50eaee69ad58b208451143e005",
79+
"type": "github"
80+
},
81+
"original": {
82+
"owner": "NixOS",
83+
"ref": "nixpkgs-unstable",
84+
"repo": "nixpkgs",
85+
"type": "github"
86+
}
87+
},
88+
"nixpkgs-stable": {
89+
"locked": {
90+
"lastModified": 1671271954,
91+
"narHash": "sha256-cSvu+bnvN08sOlTBWbBrKaBHQZq8mvk8bgpt0ZJ2Snc=",
92+
"owner": "NixOS",
93+
"repo": "nixpkgs",
94+
"rev": "d513b448cc2a6da2c8803e3c197c9fc7e67b19e3",
95+
"type": "github"
96+
},
97+
"original": {
98+
"owner": "NixOS",
99+
"ref": "nixos-22.05",
100+
"repo": "nixpkgs",
101+
"type": "github"
102+
}
103+
},
104+
"pre-commit-hooks": {
105+
"inputs": {
106+
"flake-compat": "flake-compat",
107+
"flake-utils": "flake-utils",
108+
"gitignore": "gitignore",
109+
"nixpkgs": [
110+
"nixpkgs"
111+
],
112+
"nixpkgs-stable": "nixpkgs-stable"
113+
},
114+
"locked": {
115+
"lastModified": 1673281605,
116+
"narHash": "sha256-v6U0G3pJe0YaIuD1Ijhz86EhTgbXZ4f/2By8sLqFk4c=",
117+
"owner": "cachix",
118+
"repo": "pre-commit-hooks.nix",
119+
"rev": "f8992fb404c7e79638192a10905b7ea985818050",
120+
"type": "github"
121+
},
122+
"original": {
123+
"owner": "cachix",
124+
"repo": "pre-commit-hooks.nix",
125+
"type": "github"
126+
}
127+
},
128+
"root": {
129+
"inputs": {
130+
"devenv": "devenv",
131+
"nixpkgs": "nixpkgs",
132+
"pre-commit-hooks": "pre-commit-hooks"
133+
}
134+
}
135+
},
136+
"root": "root",
137+
"version": 7
138+
}

devenv.nix

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{pkgs, ...}: {
2+
env.RUST_LOG = "info";
3+
env.NIXPKGS_ALLOW_UNFREE = "1";
4+
5+
packages = with pkgs; [
6+
assaultcube
7+
];
8+
9+
languages.rust.enable = true;
10+
}

devenv.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
inputs:
2+
nixpkgs:
3+
url: github:NixOS/nixpkgs/nixpkgs-unstable

example/cheat/src/main.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use hax::ExternalMemory;
2-
use hax::memlib::MemoryReadExt;
31
use env_logger::Env;
2+
use hax::memlib::MemoryReadExt;
3+
use hax::ExternalMemory;
44

55
fn test_simple(mem: ExternalMemory) {
66
// &value
@@ -34,7 +34,6 @@ fn test_struct(mem: ExternalMemory) {
3434
log::info!("money: {}", money);
3535
}
3636

37-
3837
fn main() {
3938
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
4039

example/target/src/main.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use memoffset::offset_of;
55
struct Player {
66
health: u32,
77
armor: u32,
8-
money: u32
8+
money: u32,
99
}
1010

1111
impl Player {
1212
pub fn new() -> Self {
1313
Self {
1414
health: 100,
1515
armor: 200,
16-
money: 1000
16+
money: 1000,
1717
}
1818
}
1919
}
@@ -52,9 +52,6 @@ fn main() {
5252
log::info!("offset: {:x}", offset_of!(Player, money));
5353
println!();
5454

55-
56-
57-
5855
// Wait for user input
5956
//
6057
let mut input = String::new();

project/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
hax = { git = "https://github.com/hax-rs/hax", branch = "feature" }
9+
env_logger = "0.10.0"
10+
log = "0.4.17"
11+
12+
hax = { git = "https://github.com/hax-rs/hax" }

project/src/main.rs

+67-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,68 @@
1-
#[hax::main]
2-
fn entrypoint() {
3-
println!("Hello, world!");
1+
#![allow(unused)]
2+
3+
use env_logger::Env;
4+
use hax::memlib::MemoryReadExt;
5+
use hax::ExternalMemory;
6+
use hax::memlib::MemoryWriteExt;
7+
8+
9+
#[cfg(target_os = "linux")]
10+
const PLAYER_POINTER: u64 = 0x5F0E10;
11+
#[cfg(target_os = "linux")]
12+
const HEALTH: u64 = 0x100;
13+
#[cfg(target_os = "linux")]
14+
const ARMOR: u64 = 0x104;
15+
16+
17+
#[cfg(target_os = "windows")]
18+
const PLAYER_POINTER: u64 = 0x10F4F4;
19+
#[cfg(target_os = "windows")]
20+
const HEALTH: u64 = 0xF8;
21+
#[cfg(target_os = "windows")]
22+
const ARMOR: u64 = 0x150;
23+
24+
struct Player {
25+
mem: ExternalMemory,
26+
player: u64
27+
}
28+
29+
impl Player {
30+
pub fn new(mem: ExternalMemory) -> Self {
31+
let player = mem.read::<u32>(PLAYER_POINTER) as u64;
32+
33+
Self {
34+
mem,
35+
player
36+
}
37+
}
38+
39+
pub fn health(&self) -> u16 {
40+
self.mem.read(self.player + HEALTH)
41+
}
42+
43+
pub fn set_health(&self, health: u16) {
44+
self.mem.write(self.player + HEALTH, &health)
45+
}
46+
47+
pub fn armor(&self) -> u16 {
48+
self.mem.read(self.player + ARMOR)
49+
}
50+
51+
pub fn set_armor(&self, armor: u16) {
52+
self.mem.write(self.player + ARMOR, &armor)
53+
}
54+
}
55+
56+
fn main() {
57+
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
58+
59+
let pid = 1284855;
60+
let mem = ExternalMemory::new(pid);
61+
62+
let player = Player::new(mem);
63+
log::info!("health: {}", player.health());
64+
log::info!("armor: {}", player.armor());
65+
66+
player.set_health(1337);
67+
player.set_armor(1337);
468
}

0 commit comments

Comments
 (0)