Compare commits

...

2 Commits

Author SHA1 Message Date
HorizonCode 195eae4980 chore: update deps 2026-07-05 12:08:19 +02:00
HorizonCode 8c70c00ebd feat: add memory reader 2026-07-05 12:07:58 +02:00
4 changed files with 608 additions and 107 deletions
+74 -100
View File
@@ -10,23 +10,12 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "aead"
version = "0.5.2"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99"
dependencies = [
"crypto-common 0.1.7",
"generic-array",
]
[[package]]
name = "aes"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
dependencies = [
"cfg-if",
"cipher 0.4.4",
"cpufeatures 0.2.17",
"crypto-common 0.2.2",
"inout",
]
[[package]]
@@ -35,20 +24,20 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66bd29a732b644c0431c6140f370d097879203d79b80c94a6747ba0872adaef8"
dependencies = [
"cipher 0.5.2",
"cipher",
"cpubits",
"cpufeatures 0.3.0",
]
[[package]]
name = "aes-gcm"
version = "0.10.3"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
checksum = "fdf011db2e21ce0d575593d749db5554b47fed37aff429e4dc50bc91ac93a028"
dependencies = [
"aead",
"aes 0.8.4",
"cipher 0.4.4",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
@@ -89,9 +78,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.102"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"
[[package]]
name = "async-broadcast"
@@ -560,24 +549,15 @@ dependencies = [
"windows-link 0.2.1",
]
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common 0.1.7",
"inout 0.1.4",
]
[[package]]
name = "cipher"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"
dependencies = [
"block-buffer 0.12.0",
"crypto-common 0.2.2",
"inout 0.2.2",
"inout",
]
[[package]]
@@ -779,7 +759,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"rand_core 0.6.4",
"typenum",
]
@@ -789,7 +768,9 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
dependencies = [
"getrandom 0.4.2",
"hybrid-array",
"rand_core 0.10.1",
]
[[package]]
@@ -850,11 +831,11 @@ checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1"
[[package]]
name = "ctr"
version = "0.9.2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
checksum = "baaca1c4b237092596f64d571e9db6ce4109c4ef9742e27590f1709594461f21"
dependencies = [
"cipher 0.4.4",
"cipher",
]
[[package]]
@@ -1272,6 +1253,7 @@ dependencies = [
"url",
"widestring",
"winapi",
"windows 0.62.2",
"windows-sys 0.61.2",
"winreg 0.56.0",
"zip",
@@ -1668,6 +1650,7 @@ dependencies = [
"js-sys",
"libc",
"r-efi 6.0.0",
"rand_core 0.10.1",
"wasip2",
"wasip3",
"wasm-bindgen",
@@ -1675,11 +1658,10 @@ dependencies = [
[[package]]
name = "ghash"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
dependencies = [
"opaque-debug",
"polyval",
]
@@ -1885,12 +1867,21 @@ dependencies = [
]
[[package]]
name = "hashlink"
version = "0.11.0"
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0b22561a9c04a7cb1a302c013e0259cd3b4bb619f145b32f72b8b4bcbed230"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
dependencies = [
"hashbrown 0.16.1",
"foldhash 0.2.0",
]
[[package]]
name = "hashlink"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5081f264ed7adee96ea4b4778b6bb9da0a7228b084587aa3bd3ff05da7c5a3b"
dependencies = [
"hashbrown 0.17.1",
]
[[package]]
@@ -2246,15 +2237,6 @@ dependencies = [
"cfb",
]
[[package]]
name = "inout"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
"generic-array",
]
[[package]]
name = "inout"
version = "0.2.2"
@@ -2488,9 +2470,9 @@ dependencies = [
[[package]]
name = "libsqlite3-sys"
version = "0.38.0"
version = "0.38.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a76001fb4daed01e5f2b518aac0b4dc592e7c734da63dbffcf0c64fa612a8d0c"
checksum = "f6c19a05435c21ac299d71b6a9c13db3e3f47c520517d58990a462a1397a61db"
dependencies = [
"cc",
"pkg-config",
@@ -3029,22 +3011,15 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "opaque-debug"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "open"
version = "5.3.5"
version = "5.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fbaa89d2ddc8473c78a3adf69eea8cffa28c483b8e02a971ef31527cd0fc92c"
checksum = "cd8d3b65c44123a56e0133d2cd06ce4361bd3ca99d41198b2f25e3c3db9b8b4a"
dependencies = [
"dunce",
"is-wsl",
"libc",
"pathdiff",
]
[[package]]
@@ -3133,12 +3108,6 @@ dependencies = [
"windows-link 0.2.1",
]
[[package]]
name = "pathdiff"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
[[package]]
name = "pbkdf2"
version = "0.13.0"
@@ -3412,13 +3381,12 @@ dependencies = [
[[package]]
name = "polyval"
version = "0.6.2"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
checksum = "7dfc63250416fea14f5749b90725916a6c903f599d51cb635aa7a52bfd03eede"
dependencies = [
"cfg-if",
"cpufeatures 0.2.17",
"opaque-debug",
"cpubits",
"cpufeatures 0.3.0",
"universal-hash",
]
@@ -3748,6 +3716,12 @@ dependencies = [
"getrandom 0.3.4",
]
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_hc"
version = "0.2.0"
@@ -3937,9 +3911,9 @@ dependencies = [
[[package]]
name = "rusqlite"
version = "0.40.0"
version = "0.40.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b3492ea85308705c3a5cc24fb9b9cf77273d30590349070db42991202b214c4"
checksum = "11438310b19e3109b6446c33d1ed5e889428cf2e278407bc7896bc4aaea43323"
dependencies = [
"bitflags 2.10.0",
"fallible-iterator",
@@ -4698,9 +4672,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.39.2"
version = "0.39.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14311e7e9a03114cd4b65eedd54e8fed2945e17f08586ae97ef53bc0669f9581"
checksum = "2c8bd2130a9b60bee2581bf82cfe89ee836424d1f37dcfa4ce21509611684673"
dependencies = [
"libc",
"memchr",
@@ -4804,9 +4778,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
[[package]]
name = "tauri"
version = "2.11.2"
version = "2.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "437404997acf375d85f1177afa7e11bb971f274ed6a7b83a2a3e339015f4cc28"
checksum = "667b20e2726d572dea2de7370da16e188eb06008faf9a92fab7cdc46791190b5"
dependencies = [
"anyhow",
"bytes",
@@ -4856,9 +4830,9 @@ dependencies = [
[[package]]
name = "tauri-build"
version = "2.6.2"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4aa1f9055fc23919a54e4e125052bed16ed04aef0487086e758fe01a67b451c7"
checksum = "bc9ce40b16101cb6ea63d3e221567affd1c3a9205f95d7bc574941a10636b632"
dependencies = [
"anyhow",
"cargo_toml",
@@ -4877,9 +4851,9 @@ dependencies = [
[[package]]
name = "tauri-codegen"
version = "2.6.2"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a0319528a025a38c4078e7dae2c446f4e63620ddb0659a643ede1cb38f90e9"
checksum = "08279169ff42f8fc45a1dbc9dcae888893ba95288142e5880c59b93a26d2cfc5"
dependencies = [
"base64 0.22.1",
"brotli",
@@ -4904,9 +4878,9 @@ dependencies = [
[[package]]
name = "tauri-macros"
version = "2.6.2"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae6cb4e3896c21d2f6da5b31251d2faea0153bba56ed0e970f918115dbee4924"
checksum = "e8b394794f399a421811d06966343e7933fcae92d59f5180b9388d1174497a45"
dependencies = [
"heck 0.5.0",
"proc-macro2",
@@ -5033,9 +5007,9 @@ dependencies = [
[[package]]
name = "tauri-runtime"
version = "2.11.2"
version = "2.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48222d7116c8807eaa6fe2f372e023fae125084e61e6eca6d70b7961cdf129ef"
checksum = "b0b4bc95aed361b0019067d189a1174a603d460d0f6c72606512d59fc9c12ec8"
dependencies = [
"cookie",
"dpi",
@@ -5058,9 +5032,9 @@ dependencies = [
[[package]]
name = "tauri-runtime-wry"
version = "2.11.2"
version = "2.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b83849ee63ecb27a8e8d0fe51915ca215076914aca43f96db1179f0f415f6cd9"
checksum = "4e6fac707727b7a2f48e4ded90976324267371073edbb415ffb73bb0458d203f"
dependencies = [
"gtk",
"http",
@@ -5084,9 +5058,9 @@ dependencies = [
[[package]]
name = "tauri-utils"
version = "2.9.2"
version = "2.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "092379df9a707631978e6c56b1bc2401d387f01e2d4a3c123360d167bbb9aa95"
checksum = "3e176a18e67764923c4f1ce66f25ae4abe5f688384d5eb1a0fa6c77f3d90f887"
dependencies = [
"anyhow",
"brotli",
@@ -5513,9 +5487,9 @@ dependencies = [
[[package]]
name = "tray-icon"
version = "0.23.1"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15edbb0d80583e85ee8df283410038e17314df5cba30da2087a54a85216c0773"
checksum = "65ba1e5f6b9ef9fd87e21b9c6f351554dbd717960089168fcfdef854686961dc"
dependencies = [
"crossbeam-channel",
"dirs",
@@ -5629,12 +5603,12 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "universal-hash"
version = "0.5.1"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96"
dependencies = [
"crypto-common 0.1.7",
"subtle",
"crypto-common 0.2.2",
"ctutils",
]
[[package]]
@@ -6896,7 +6870,7 @@ version = "8.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b"
dependencies = [
"aes 0.9.0",
"aes",
"bzip2",
"constant_time_eq",
"crc32fast",
+14 -7
View File
@@ -25,10 +25,10 @@ name = "ezpplauncher_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2.6.2", features = [] }
tauri-build = { version = "2.6.3", features = [] }
[dependencies]
tauri = { version = "2.11.2", features = ["protocol-asset"] }
tauri = { version = "2.11.5", features = ["protocol-asset"] }
tauri-plugin-shell = "2.3.5"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.150"
@@ -37,22 +37,22 @@ tauri-plugin-dialog = "2.7.1"
tauri-plugin-fs = "2.5.1"
hardware-id = "0.3.0"
tauri-plugin-cors-fetch = "5.0.0"
sysinfo = "0.39.2"
sysinfo = "0.39.5"
reqwest = { version = "0.13.4", features = ["json", "stream", "query"] }
md5 = "0.8.0"
tokio = { version = "1.52.3", features = ["full"] }
open = "5.3.5"
open = "5.3.6"
presenceforge = { version = "0.2.1", features = ["tokio-runtime"] }
once_cell = "1.21.4"
futures-util = "0.3.32"
byteorder = "1.5.0"
anyhow = "1.0.102"
anyhow = "1.0.103"
url = "2.5.8"
zip = "8.6.0"
sha1 = "0.11.0"
hex = "0.4.3"
rusqlite = { version = "0.40.0", features = ["bundled"] }
aes-gcm = "0.10.3"
rusqlite = { version = "0.40.1", features = ["bundled"] }
aes-gcm = "0.11.0"
base64 = "0.22.1"
sha2 = "0.11.0"
thiserror = "2.0.18"
@@ -62,6 +62,13 @@ winreg = "0.56.0"
winapi = { version = "0.3.9", features = ["winuser", "wincrypt", "memoryapi", "winbase", "dpapi"] }
widestring = "1.2.1"
windows-sys = "0.61.2"
windows = { version = "0.62.2", features = [
"Win32_System_Diagnostics_ToolHelp",
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_System_Diagnostics_Debug",
"Win32_Foundation"
] }
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-single-instance = "2.4.2"
+1
View File
@@ -7,6 +7,7 @@ use tauri_plugin_fs::FsExt;
pub mod commands;
pub mod config;
pub mod memory_reader;
pub mod osudb;
pub mod presence;
pub mod state;
+519
View File
@@ -0,0 +1,519 @@
//! osu_memory_reader.rs
//!
//! External, read-only memory reader for the osu! stable client, structured
//! the same way community tools like tosu / gosumemory work:
//!
//! 1. Open the osu process with PROCESS_VM_READ.
//! 2. Enumerate its committed memory regions.
//! 3. Scan those regions for known byte-pattern "signatures".
//! 4. Walk a short pointer chain from each signature to the real struct.
//! 5. Parse out the fields you care about (username, mods, combo, etc).
//!
//! IMPORTANT: The actual signature bytes below are PLACEHOLDERS. osu!
//! updates its binary regularly, which shifts/breaks raw byte signatures.
//! Community tools maintain live, current signatures — pull up-to-date
//! ones from tosu's open-source repo (github.com/KotRikD/tosu, see its
//! `packages/tosu/src/memory/` signature definitions) and drop them into
//! the `SIGNATURES` table below. This file gives you the engine; you keep
//! the signature table current.
//!
//! This is entirely read-only (ReadProcessMemory only, never Write) and
//! only targets your own launched osu! process — no injection involved.
//!
//! ---------------------------------------------------------------------
//! Cargo.toml additions (on top of the ones from osu_scanner.rs):
//!
//! [dependencies]
//! windows = { version = "0.58", features = [
//! "Win32_System_Diagnostics_ToolHelp",
//! "Win32_System_Memory",
//! "Win32_System_Threading",
//! "Win32_System_Diagnostics_Debug",
//! "Win32_Foundation"
//! ] }
//! ---------------------------------------------------------------------
use serde::Serialize;
use std::collections::HashMap;
use windows::Win32::Foundation::{CloseHandle, HANDLE};
use windows::Win32::System::Diagnostics::Debug::ReadProcessMemory;
use windows::Win32::System::Memory::{
MEM_COMMIT, MEMORY_BASIC_INFORMATION, PAGE_GUARD, PAGE_NOACCESS, VirtualQueryEx,
};
use windows::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_INFORMATION, PROCESS_VM_READ};
// =========================================================================
// Signature table — REPLACE with current values, see module doc comment.
// =========================================================================
/// A byte pattern to search for in process memory. `None` = wildcard byte.
#[derive(Clone)]
pub struct Signature {
pub name: &'static str,
pub pattern: &'static [Option<u8>],
/// Byte offset from the START of the matched pattern to the address
/// (or start of a pointer chain) you actually want to read.
pub offset: isize,
}
/// Helper macro so signatures can be written like Cheat Engine AOB strings,
/// e.g. sig!("F8 01 74 04 ?? ?? ?? ??", offset = 5).
macro_rules! sig {
($bytes:expr) => {{ parse_aob($bytes) }};
}
fn parse_aob(s: &str) -> Vec<Option<u8>> {
s.split_whitespace()
.map(|tok| {
if tok == "??" || tok == "?" {
None
} else {
Some(u8::from_str_radix(tok, 16).expect("bad AOB byte"))
}
})
.collect()
}
/// NOTE: These are PLACEHOLDER patterns illustrating the *shape* tosu-style
/// signatures take (short, somewhat unique byte runs with wildcards around
/// the volatile parts). Do not expect these exact bytes to match a real
/// osu! binary — swap them for current ones before using this for real.
pub fn build_signature_table() -> HashMap<&'static str, Signature> {
let mut map = HashMap::new();
map.insert(
"username_ptr",
Signature {
name: "username_ptr",
pattern: Box::leak(sig!("75 04 33 C0 EB 0A A1 ?? ?? ?? ??").into_boxed_slice()),
offset: 7, // offset to the 4-byte address embedded in the instruction
},
);
map.insert(
"game_mode_ptr",
Signature {
name: "game_mode_ptr",
pattern: Box::leak(sig!("83 F8 08 7D 05 ?? ?? ?? ?? ??").into_boxed_slice()),
offset: 5,
},
);
map.insert(
"current_beatmap_ptr",
Signature {
name: "current_beatmap_ptr",
pattern: Box::leak(sig!("6A 01 6A 00 A1 ?? ?? ?? ?? 8B 00").into_boxed_slice()),
offset: 4,
},
);
map.insert(
"combo_ptr",
Signature {
name: "combo_ptr",
pattern: Box::leak(
sig!("83 3D ?? ?? ?? ?? 00 7E 34 A1 ?? ?? ?? ??").into_boxed_slice(),
),
offset: 9,
},
);
// userId typically lives on the same "player info" object as username,
// just at a different field offset — but tosu-style tools usually give
// it its own independent signature since it's read even when the
// username string hasn't been touched yet (e.g. right after login).
map.insert(
"user_id_ptr",
Signature {
name: "user_id_ptr",
pattern: Box::leak(sig!("A1 ?? ?? ?? ?? 89 45 ?? 8B 45 ?? 8B 0D").into_boxed_slice()),
offset: 1,
},
);
map
}
// =========================================================================
// Process handle + raw memory access
// =========================================================================
pub struct MemoryReader {
handle: HANDLE,
pid: u32,
/// Cached list of readable committed memory regions.
regions: Vec<(usize, usize)>, // (base_address, size)
}
impl MemoryReader {
/// Opens the given PID for reading. Returns None if the process can't
/// be opened (e.g. insufficient privileges, process exited).
pub fn open(pid: u32) -> Option<Self> {
let handle =
unsafe { OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, pid).ok()? };
Some(Self {
handle,
pid,
regions: Vec::new(),
})
}
/// Re-enumerates committed, readable memory regions. Call once after
/// open() and periodically after (e.g. once per scan cycle), since the
/// process's memory layout can change.
pub fn refresh_regions(&mut self) {
self.regions.clear();
let mut address: usize = 0;
loop {
let mut mbi = MEMORY_BASIC_INFORMATION::default();
let result = unsafe {
VirtualQueryEx(
self.handle,
Some(address as *const _),
&mut mbi,
std::mem::size_of::<MEMORY_BASIC_INFORMATION>(),
)
};
if result == 0 {
break; // no more regions
}
let region_size = mbi.RegionSize;
let is_committed = mbi.State == MEM_COMMIT;
let is_guarded = (mbi.Protect & PAGE_GUARD).0 != 0;
let is_no_access = mbi.Protect == PAGE_NOACCESS;
if is_committed && !is_guarded && !is_no_access && region_size > 0 {
self.regions.push((mbi.BaseAddress as usize, region_size));
}
address = (mbi.BaseAddress as usize).saturating_add(region_size);
if address == 0 {
break;
}
}
}
/// Reads `size` bytes starting at `address`. Returns None on failure
/// (unmapped page, access denied, process exited mid-read, etc).
pub fn read_bytes(&self, address: usize, size: usize) -> Option<Vec<u8>> {
let mut buffer = vec![0u8; size];
let mut bytes_read = 0usize;
unsafe {
ReadProcessMemory(
self.handle,
address as *const _,
buffer.as_mut_ptr() as *mut _,
size,
Some(&mut bytes_read),
)
.ok()?;
}
buffer.truncate(bytes_read);
if buffer.is_empty() {
None
} else {
Some(buffer)
}
}
pub fn read_i32(&self, address: usize) -> Option<i32> {
let bytes = self.read_bytes(address, 4)?;
Some(i32::from_le_bytes(bytes.try_into().ok()?))
}
pub fn read_u32(&self, address: usize) -> Option<u32> {
let bytes = self.read_bytes(address, 4)?;
Some(u32::from_le_bytes(bytes.try_into().ok()?))
}
pub fn read_u16(&self, address: usize) -> Option<u16> {
let bytes = self.read_bytes(address, 2)?;
Some(u16::from_le_bytes(bytes.try_into().ok()?))
}
pub fn read_f64(&self, address: usize) -> Option<f64> {
let bytes = self.read_bytes(address, 8)?;
Some(f64::from_le_bytes(bytes.try_into().ok()?))
}
/// Reads a pointer-sized value (4 bytes for the 32-bit osu! stable
/// client). Change to 8 bytes if you ever target a 64-bit build.
pub fn read_ptr(&self, address: usize) -> Option<usize> {
self.read_u32(address).map(|v| v as usize)
}
/// Reads a .NET-style string: [object header][length: i32][utf16 chars].
/// `base` should point at the object header; the classic offset for
/// .NET string length is +0x4 and chars start at +0x8, but verify
/// against your target since layouts can differ.
pub fn read_dotnet_string(&self, base: usize, max_len: usize) -> Option<String> {
let len = self.read_i32(base + 0x4)? as usize;
let len = len.min(max_len);
if len == 0 {
return Some(String::new());
}
let bytes = self.read_bytes(base + 0x8, len * 2)?;
let utf16: Vec<u16> = bytes
.chunks_exact(2)
.map(|b| u16::from_le_bytes([b[0], b[1]]))
.collect();
String::from_utf16(&utf16).ok()
}
/// Scans all cached regions for `signature.pattern`, returning the
/// absolute address where the pattern begins (before applying offset).
pub fn find_signature(&self, signature: &Signature) -> Option<usize> {
for &(base, size) in &self.regions {
// Read in chunks to avoid gigantic single allocations on huge
// regions; 1MB chunks with overlap so patterns aren't missed
// across a chunk boundary.
const CHUNK: usize = 1 << 20;
let overlap = signature.pattern.len().saturating_sub(1);
let mut offset = 0;
while offset < size {
let read_size = CHUNK.min(size - offset);
let Some(mem) = self.read_bytes(base + offset, read_size) else {
offset += CHUNK;
continue;
};
if let Some(pos) = find_pattern(&mem, signature.pattern) {
return Some(base + offset + pos);
}
offset += CHUNK.saturating_sub(overlap).max(1);
}
}
None
}
pub fn pid(&self) -> u32 {
self.pid
}
}
impl Drop for MemoryReader {
fn drop(&mut self) {
unsafe {
let _ = CloseHandle(self.handle);
}
}
}
/// Naive substring search over a byte pattern with wildcards. Fine for
/// per-scan-cycle use; swap for a Boyer-Moore-style skip table if you need
/// to scan very large regions many times per second.
fn find_pattern(haystack: &[u8], pattern: &[Option<u8>]) -> Option<usize> {
if pattern.is_empty() || haystack.len() < pattern.len() {
return None;
}
haystack.windows(pattern.len()).position(|window| {
window
.iter()
.zip(pattern.iter())
.all(|(b, p)| p.map_or(true, |expected| *b == expected))
})
}
// =========================================================================
// High-level "osu state" reader
// =========================================================================
#[derive(Serialize, Debug, Default, Clone)]
pub struct OsuState {
pub username: Option<String>,
pub user_id: Option<i32>,
pub game_mode: Option<i32>,
pub combo: Option<i32>,
pub beatmap_id: Option<i32>,
}
pub struct OsuMemoryClient {
reader: MemoryReader,
signatures: HashMap<&'static str, Signature>,
/// Cached resolved addresses so we don't re-scan the whole memory space
/// every single read — only re-resolve if a read at the cached address
/// stops making sense (e.g. after an osu update / restart).
resolved: HashMap<&'static str, usize>,
/// When true, prints signature resolution + read results to stderr.
/// Toggle via `new_with_debug`, or flip at runtime with `set_debug`.
debug: bool,
}
impl OsuMemoryClient {
pub fn new(pid: u32) -> Option<Self> {
Self::new_with_debug(pid, false)
}
/// Same as `new`, but with debug logging to stderr enabled/disabled
/// explicitly. Handy to wire up to a `--debug` CLI flag or a Tauri
/// dev-mode check (`cfg!(debug_assertions)`).
pub fn new_with_debug(pid: u32, debug: bool) -> Option<Self> {
let mut reader = MemoryReader::open(pid)?;
if debug {
eprintln!("[osu_memory] opening pid {pid} for reading");
}
reader.refresh_regions();
if debug {
eprintln!(
"[osu_memory] found {} readable regions",
reader.regions.len()
);
}
Some(Self {
reader,
signatures: build_signature_table(),
resolved: HashMap::new(),
debug,
})
}
pub fn set_debug(&mut self, debug: bool) {
self.debug = debug;
}
/// Call periodically (e.g. every few seconds, or whenever osu restarts)
/// to pick up new memory layout / re-find signatures.
pub fn refresh(&mut self) {
if self.debug {
eprintln!(
"[osu_memory] refreshing regions + clearing {} cached signature(s)",
self.resolved.len()
);
}
self.reader.refresh_regions();
self.resolved.clear();
if self.debug {
eprintln!(
"[osu_memory] {} readable regions after refresh",
self.reader.regions.len()
);
}
}
fn resolve(&mut self, key: &'static str) -> Option<usize> {
if let Some(addr) = self.resolved.get(key) {
if self.debug {
eprintln!("[osu_memory] {key} -> 0x{addr:X} (cached)");
}
return Some(*addr);
}
let sig = self.signatures.get(key)?.clone();
let Some(found) = self.reader.find_signature(&sig) else {
if self.debug {
eprintln!("[osu_memory] {key}: signature NOT FOUND in any scanned region");
}
return None;
};
let target = (found as isize + sig.offset) as usize;
if self.debug {
eprintln!(
"[osu_memory] {key}: signature matched at 0x{found:X}, target (offset {}) -> 0x{target:X}",
sig.offset
);
}
self.resolved.insert(key, target);
Some(target)
}
pub fn read_username(&mut self) -> Option<String> {
let addr = self.resolve("username_ptr")?;
let ptr = self.reader.read_ptr(addr)?;
let value = self.reader.read_dotnet_string(ptr, 64);
if self.debug {
eprintln!("[osu_memory] username -> {value:?}");
}
value
}
pub fn read_user_id(&mut self) -> Option<i32> {
let addr = self.resolve("user_id_ptr")?;
// Unlike username/combo/beatmap, this signature usually points
// straight at a static int slot rather than through an extra
// object pointer — verify against whatever real signature you use,
// some variants do need an extra self.reader.read_ptr() hop first.
let value = self.reader.read_i32(addr);
if self.debug {
eprintln!("[osu_memory] user_id -> {value:?}");
}
value
}
pub fn read_game_mode(&mut self) -> Option<i32> {
let addr = self.resolve("game_mode_ptr")?;
let ptr = self.reader.read_ptr(addr)?;
let value = self.reader.read_i32(ptr);
if self.debug {
eprintln!("[osu_memory] game_mode -> {value:?}");
}
value
}
pub fn read_combo(&mut self) -> Option<i32> {
let addr = self.resolve("combo_ptr")?;
let ptr = self.reader.read_ptr(addr)?;
let value = self.reader.read_i32(ptr);
if self.debug {
eprintln!("[osu_memory] combo -> {value:?}");
}
value
}
pub fn read_beatmap_id(&mut self) -> Option<i32> {
let addr = self.resolve("current_beatmap_ptr")?;
let ptr = self.reader.read_ptr(addr)?;
let value = self.reader.read_i32(ptr + 0xC); // example nested offset into the beatmap struct
if self.debug {
eprintln!("[osu_memory] beatmap_id -> {value:?}");
}
value
}
/// Convenience: read everything at once into a single struct, suitable
/// for bundling into your existing scan payload / emitting to the
/// frontend.
pub fn read_state(&mut self) -> OsuState {
if self.debug {
eprintln!(
"[osu_memory] --- reading full state (pid {}) ---",
self.reader.pid()
);
}
let state = OsuState {
username: self.read_username(),
user_id: self.read_user_id(),
game_mode: self.read_game_mode(),
combo: self.read_combo(),
beatmap_id: self.read_beatmap_id(),
};
if self.debug {
eprintln!("[osu_memory] state = {state:?}");
}
state
}
}
// =========================================================================
// Example wiring into your existing watcher loop
// =========================================================================
//
// let mut mem_client = OsuMemoryClient::new(osu_pid)?;
// loop {
// let state = mem_client.read_state();
// // attach `state` to your ScanPayload before POSTing to the server
// // if a read silently comes back all-None a few cycles in a row,
// // call mem_client.refresh() in case osu updated/restarted.
// }