Skip to content

Commit c41d39f

Browse files
committed
seperate exe and dll crates
1 parent 52359dc commit c41d39f

File tree

11 files changed

+99
-25
lines changed

11 files changed

+99
-25
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ jobs:
3131
id: restore-cache-test
3232
uses: actions/cache/restore@v4
3333
with:
34-
path: tests/manual/test_inject/target
35-
key: ${{ runner.os }}-${{ hashFiles('tests/manual/test_inject/src/**') }}
34+
path: target
35+
key: ${{ runner.os }}-${{ hashFiles('tests/manual/test_binaries/**') }}
3636

3737
- name: Setup rust
3838
if: steps.restore-cache-test.outputs.cache-hit != 'true'
3939
uses: actions-rust-lang/setup-rust-toolchain@v1
4040

4141
- name: Build test binaries
4242
if: steps.restore-cache-test.outputs.cache-hit != 'true'
43-
run: cargo build --release --manifest-path tests/manual/test_inject/Cargo.toml
43+
run: cargo build --release
4444

4545
- name: Cache test binaries
4646
if: steps.restore-cache-test.outputs.cache-hit != 'true'
4747
uses: actions/cache/save@v4
4848
with:
49-
path: tests/manual/test_inject/target
50-
key: ${{ runner.os }}-${{ hashFiles('tests/manual/test_inject/src/**') }}
49+
path: target
50+
key: ${{ runner.os }}-${{ hashFiles('tests/manual/test_binaries/**') }}
5151

5252
- name: Set up Python ${{ matrix.python-version }}
5353
uses: actions/setup-python@v5

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3-
"tests/manual/test_inject"
3+
"tests/manual/test_binaries/test_inject",
4+
"tests/manual/test_binaries/inject_target"
45
]
56
resolver = "2"

justfile

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ format:
4747
black .
4848
alejandra .
4949

50-
# build test dll
51-
build-test-dll:
52-
if (!(Test-Path "tests/manual/test_inject/target/release/test_inject.dll")) { cargo build --release --manifest-path tests/manual/test_inject/Cargo.toml }
53-
54-
# build test exe
55-
build-test-exe:
56-
if (!(Test-Path "tests/manual/test_inject/target/release/inject_target.dll")) { cargo build --release --manifest-path tests/manual/test_inject/Cargo.toml --bin inject_target }
57-
5850
# build test binaries
59-
build-test-bins: build-test-dll build-test-exe
51+
build-test-bins:
52+
cargo build --release
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "inject_target"
3+
version = "0.1.0"
4+
edition = "2021"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use std::str::FromStr;
2+
3+
fn main() {
4+
std::hint::black_box(add_five);
5+
std::hint::black_box(create_player);
6+
std::hint::black_box(uses_player);
7+
8+
let value = std::hint::black_box(add_five(60 * 1_000_000));
9+
10+
// This process just waits, so it can be injected into.
11+
//std::thread::sleep(std::time::Duration::from_secs(60 * 5));
12+
//std::thread::sleep(std::time::Duration::from_secs(60 * 1_000_000));
13+
std::thread::sleep(std::time::Duration::from_secs(value as u64));
14+
}
15+
16+
// static gives us a global address rather than in-lining the value
17+
#[used]
18+
static FIVE: u32 = 5;
19+
20+
static mut MUTATED: u32 = 0;
21+
22+
23+
#[repr(C)]
24+
pub struct Pet {
25+
name: String,
26+
health: f32,
27+
}
28+
29+
#[repr(C)]
30+
pub struct Player {
31+
pub ammo: u32,
32+
pub health: f32,
33+
pub x: f32,
34+
pub y: f32,
35+
pub z: f32,
36+
pub pet: Pet
37+
}
38+
39+
impl Player {
40+
#[no_mangle]
41+
pub fn new() -> Player {
42+
Player {
43+
ammo: 100,
44+
health: 100.0,
45+
x: 250.0,
46+
y: -250.0,
47+
z: 0.0,
48+
pet: Pet { name: String::from_str("Test").unwrap(), health: 200.0 }
49+
}
50+
}
51+
}
52+
53+
// TODO: keep these from getting compiled away
54+
#[no_mangle]
55+
extern "C" fn add_five(value: u32) -> u32 {
56+
value + FIVE
57+
}
58+
59+
#[no_mangle]
60+
extern "C" fn create_player() -> () {
61+
let player = Player::new();
62+
63+
uses_player(&player);
64+
}
65+
66+
#[no_mangle]
67+
extern "C" fn uses_player(player: &Player) -> () {
68+
// cmp with object offset
69+
if player.health > 100.0 {
70+
let new_value = add_five(player.ammo);
71+
72+
unsafe { MUTATED += new_value; }
73+
}
74+
}
File renamed without changes.

tests/manual/test_inject/Cargo.toml renamed to tests/manual/test_binaries/test_inject/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
windows = { version = "0.62.2", features = ["Win32_System_Console", "Win32_Foundation", "Win32_System_SystemServices"] }
11-
12-
[[bin]]
13-
name = "inject_target"
14-
path = "src/bin/inject_target.rs"
File renamed without changes.

tests/manual/test_dll_injection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99

1010
def test_dll_injection():
11+
# there is probably a better way to get this
12+
library_root = Path(__file__).parent.parent.parent
13+
14+
assert library_root.name == "memobj"
15+
assert (library_root / "README.md").exists() is True
16+
1117
dll_path = (
12-
Path(__file__).parent / "test_inject/target/release/test_inject.dll"
18+
library_root / "target/release/test_inject.dll"
1319
).resolve()
1420
exe_path = (
15-
Path(__file__).parent / "test_inject/target/release/inject_target.exe"
21+
library_root / "target/release/inject_target.exe"
1622
).resolve()
1723

1824
if not dll_path.exists():

0 commit comments

Comments
 (0)