Windows game hack helper utilities in rust.

Overview

⚗️ toy-arms

Windows game hack helper utilities in rust.

This crate has some useful macros, functions and traits.

🔥 How to use this crate?

With this crate, making dll is simple as this:

// A neat macro which defines entry point instead of you.
// Also, you dont have to alloc/free console by yourself, console will show up only when debug compile.
toy_arms::create_entrypoint!(hack_main_thread);

// Main thread
fn hack_main_thread() {
    // YOUR STUNNING CODE'S SUPPOSED TO BE HERE;
    for i in 0..30000 {
        println!("using toy-arms {}", i);
    }
}

🌐 Other examples?

Take a look at examples directory, you'll see more examples! To run the example:

cargo build --example EXAMPLE_NAME
Comments
  • pattern scan with regex

    pattern scan with regex

    background

    toy-arms' pattern scanning has been significantly slow, therefore I replaced it with the way uses regex.

    progress

    external replacement is done so far. internal is waiting to be done

    opened by pseuxide 9
  • [Feature Request] AoB Scanning

    [Feature Request] AoB Scanning

    Hello! First and foremost- Great project!

    It has basically everything I need, although I wanted to check if you could potentially implement a function for performing AoB (Array of Byte) scans? Since that's what I'm working with over SIG/Pattern ones.

    opened by vars1ty 7
  • Modify some pattern internals, cargo fmt, some tidying.

    Modify some pattern internals, cargo fmt, some tidying.

    Hello, there was some issues with the tests so I didn't get to try - although, there shouldn't be any issue. If there is please tell me and I'll take care of it.

    Also, why not reimplement the pattern scanner as following?

        /// Find `pattern` indice in `self.size`-sized raw parts of `self.bytes`, returns either
        /// `Pointer<T>` or `std::io::Error`
        ///
        /// # Arguments
        ///
        /// `pattern` - Array, can contain wildcard (`0`) which'll be ignored in matching
        ///
        /// # Example
        ///
        /// ```
        /// module.find_pattern_bytes::<u8>(b"\x55\x8B\xEC").expect("Failed finding prologue")
        /// ```
        ///
        /// # Safety
        ///
        /// Computes `from_raw_parts` from raw pointer of `self.size` and walks section,
        /// which is considered `unsafe`
        pub fn find_pattern_bytes<T>(&self, pattern: &[u8]) -> Result<Pointer<T>, Error> {
            /// Custom predicate for iterator position finder
            fn match_with_wildcard(wildcard_array: &[u8], memory_view: &[u8]) -> bool {
                !wildcard_array
                    .iter()
                    .zip(memory_view)
                    .map(|x| if *x.0 == 0 { true } else { *x.0 == *x.1 })
                    .any(|x| !x)
            }
    
            let indice = unsafe {
                std::slice::from_raw_parts(self.get_bytes(), self.get_size() - pattern.len())
                    .windows(pattern.len())
                    .position(|x| match_with_wildcard(pattern, x))
                    .ok_or(Error::new(
                        ErrorKind::InvalidData,
                        format_args!(
                            "Failed finding subsequence {:x?} in slice sequence",
                            pattern
                        )
                        .to_string(),
                    ))?
            };
    
            Ok(Pointer::new((self.get_bytes() as usize + indice) as _))
        }
    
        /// This is a wrapper for it's [base function](Module::find_pattern_bytes)
        ///
        /// # Arguments
        ///
        /// `pattern` - String which'll get split by whitespaces. If a resulting substring
        /// contains `'?'`, it'll be mapped to `0` in the iterator, otherwise, it'll be turned into it's
        /// hexadecimal form. If it's not contained within hexadecimal alphanumerical bounds, it'll
        /// panic
        pub fn find_pattern<T>(&self, pattern: &str) -> Result<Pointer<T>, Error> {
            fn string_to_vec(pattern: &str) -> Vec<u8> {
                pattern
                    .split_whitespace()
                    .map(|x| {
                        if x.contains('?') {
                            0
                        } else {
                            u8::from_str_radix(x, 16)
                                .expect("Substring not contained within hexadecimal alphanumeric form")
                        }
                    })
                    .collect()
            }
    
            self.find_pattern_bytes(string_to_vec(pattern).as_slice())
        }
    

    I do it like that personally. Should also work on externals with little modification inside the find_pattern_bytes based on cfg.

    opened by cristeigabriel 7
  • Writing memory in an internal dll

    Writing memory in an internal dll

    How does one do this? There are no example's for this specific thing, only for reading and writing patterns. In C++ it would go like this:

    namespace mem {
        template<typename T>
        void write(DWORD64 addr, T value) {
            *((T*)addr) = value;
        }
    }
    
    mem::write<int>(localPlayer + offsets::playerHealth, 1337);
    

    but it doesnt work the same way in Rust or well, i dont know how to.

    opened by Autist69420 6
  • Writing C struct to process memory

    Writing C struct to process memory

    Hi. I'm trying to write a custom C struct to another process' memory, but it seems the write method only writes the size of size_of::<LPCVOID>() as SIZE_T regardless of value T's size.

    Write method:

    #[cfg(feature = "external")]
        pub fn write<T>(&self, base_address: usize, value: &mut T) -> Result<(), ToyArmsExternalError> {
            unsafe {
                let ok = WriteProcessMemory(self.process_handle, base_address as LPVOID, value as *mut T as LPCVOID, size_of::<LPCVOID>() as SIZE_T, null_mut::<SIZE_T>());
                if ok == FALSE {
                    println!("{}", GetLastError());
                    return Err(ToyArmsExternalError::WriteProcessMemoryFailed);
                }
            }
            Ok(())
        }
    

    Would this be correct, or am I using the library wrong? Cheers

    opened by gardc 3
  • Error code 998  when using external::write

    Error code 998 when using external::write

    I attempted to write a simple external hack (for AssaultCube) following the example given:

    use toy_arms::external::Process;
    use toy_arms::external::{ write };
    use toy_arms::VirtualKeyCode;
    
    const HEALTH_OFFSET: u32 = 0xEC;
    
    fn main() {
        let process = Process::from_process_name("ac_client.exe").expect("could not find process");
        println!("{:#?} {:#?} {:#?}", process.process_name, process.process_id, process.process_handle);
    
        loop {
            write::<u32>(
                process.process_handle,
                process.get_module_base(process.process_name).unwrap() + HEALTH_OFFSET as usize,
                &mut 0x100,
            ).unwrap();
    
            if toy_arms::detect_keypress(VirtualKeyCode::VK_INSERT) {
                break;
            }
        }
    }
    

    however this is the output given:

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: WriteMemoryFailed(UnknownError { error_code: 998 })', src\main.rs:16:11
    stack backtrace:
       0: std::panicking::begin_panic_handler
                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\std\src\panicking.rs:584
       1: core::panicking::panic_fmt
                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\core\src\panicking.rs:142
       2: core::result::unwrap_failed
                 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\core\src\result.rs:1785
       3: core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    error: process didn't exit successfully: `target\release\RustGameHax.exe` (exit code: 101)
    

    I could just be using the library the wrong way though

    opened by TetrisLitHub 2
  • pattern scanning for external feature.

    pattern scanning for external feature.

    As of now when you only enable the feature "external", the compiler warns you about tons of unused function that is in pattern_scan_core.rs cuz it's only refer to by internal.rs. pattern scanning for external feature must be done.

    opened by pseuxide 1
  • Make workspace for respective fields to organize

    Make workspace for respective fields to organize

    resolves #10

    workspace member description

    • toy-arms_utils - common parts
    • toy-arms_derive - derive macro
    • internal - internal hack libs
    • external - external hack libs

    Todo:

    • [x] All the migration
    • [x] Example correction
    • [x] bug fix
    • [ ] Readme correction
    opened by pseuxide 0
  • implement  detect_keypress

    implement detect_keypress

    detect_keypress function have to be added that would catches keyPRESS in addition to the function detects keyDOWN. Moreover, now we have detect_keydown function but it acrually catches keypress now, so it's supposed to be renamed to detect_keypress.

    enhancement 
    opened by pseuxide 0
  • brush up get_all_module_handles function

    brush up get_all_module_handles function

    have to implement the handling where the modules' buffer that is meant to store module handles is smaller than required size. it's gonna be like call EnumProcessModules with bigger buffer.

    opened by pseuxide 0
  • How to get base address of process?

    How to get base address of process?

    I have a game that doesnt have any dll modules so i cannot use those, instead i need to take the base address of the game and add my offsets to it. How may i do this?

    opened by Leastrio 17
Owner
s3pt3mb3r
I'm terrible at coding but you're even worse, aren't you?
s3pt3mb3r
Utilities for creating strictly ordered execution graphs of systems for the Bevy game engine

bevy_system_graph This crate provides the utilities for creating strictly ordered execution graphs of systems for the Bevy game engine. Bevy Version S

Hourai Teahouse 19 Dec 2, 2022
Helper functions and structs for working with 2D space in Bevy.

About Baffled by quaternions? Want to accelerate an object in 2D? Wish that there was a simple way to work with grids? Just want to know if two axis-a

Leafwing Studios 11 May 9, 2022
A helper bevy plugin to handle downloading OpenStreetMap-compliant slippy tiles

Bevy Slippy Tiles A helper bevy plugin to handle downloading OpenStreetMap-compliant slippy tiles. [DownloadSlippyTilesEvent] can be fired to request

Edouard Poitras 4 Jan 25, 2023
A simple helper for spawning objects in Bevy.

Spew A simple helper for spawning objects in Bevy. Usage First, create an enum that holds objects you might want to spawn: #[derive(Debug, Eq, Partial

Jan Hohenheim 6 Mar 20, 2023
A simple helper to run cronjobs (at repeated schedule) in Bevy.

bevy_cronjob bevy_cronjob is a simple helper to run cronjobs (at repeated schedule) in Bevy. Usage use std::time::Duration; use bevy::{ MinimalPlugins

ZoOL 5 Aug 5, 2023
Solana Game Server is a decentralized game server running on Solana, designed for game developers

Solana Game Server* is the first decentralized Game Server (aka web3 game server) designed for game devs. (Think web3 SDK for game developers as a ser

Tardigrade Life Sciences, Inc 16 Dec 1, 2022
minesweeper-rs is a simple minesweeper game using Rust and windows-rs.

minesweeper-rs minesweeper-rs is a simple minesweeper game using Rust and windows-rs. Key Features TBA Quick Start TBA How To Contribute Contributions

Chris Ohk 15 Jun 25, 2022
A Rust port of the "Heroes of Math & Mech" game. Currently macOS, Windows, Linux and iOS app. WIP.

[WIP] Герои Мата и Меха Попытка переписать известный в узких кругах текстовый квест «Герои Мата и Меха» на Rust. Ещё не закончено! Оригинальная версия

null 2 Jan 18, 2022
Rollback-safe implementations and utilities for Bevy Engine

bevy_roll_safe Rollback-safe implementations and utilities for Bevy Engine. Motivation Some of Bevy's features can't be used in a rollback context (wi

Johan Klokkhammer Helsing 3 Sep 17, 2023
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

Petros 3 Oct 25, 2021
A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it techinically works

rustetris A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it tech

Eric G 3 Oct 15, 2022
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with ?? ?? by The Rust and WebAssembly Working Group About T

Rust and WebAssembly 236 Dec 24, 2022
Conway's Game of Life implemented for Game Boy Advance in Rust

game-of-life An implementation of a Conway's Game of Life environment on GBA. The ultimate game should have two modes: Edit and Run mode which can be

Shane Snover 1 Feb 16, 2022
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game for the game jam "1-Button Jam 2021"

One click ninja A game for the game jam "1-Button Jam 2021" written in Rust with the Bevy engine. A rhythm game, where you play a soldier that can def

Alex Helfet 7 Apr 12, 2022
My first attempt at game programming. This is a simple target shooting game built in macroquad.

sergio My first attempt at game programming. This is a simple target shooting game built in macroquad. Rules Hit a target to increase score by 1 Score

Laz 1 Jan 11, 2022
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022