mem_rs::process

Struct Process

Source
pub struct Process { /* private fields */ }
Expand description

Wraps a native process and allows memory access/manipulation

§Examples

use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
if process.refresh().is_ok()
{
    process.write_memory_abs(0x1234, &u32::to_ne_bytes(10));
    let result = process.read_u32_rel(Some(0x1234));
    println!("Result: {}", result);
}

Implementations§

Source§

impl Process

Source

pub fn inject_dll(&self, dll_path: &str) -> Result<(), String>

Attempts to inject a dll into the attached process using LoadLibraryW

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
process.refresh().expect("Failed to attach/refresh!");
process.inject_dll(r#"C:\temp\native.dll"#).expect("Failed to inject!");
Examples found in repository?
examples/dsr.rs (line 71)
67
68
69
70
71
72
    pub fn inject_soulmemory_rs(&self)
    {
        //self.process.inject_dll(r#"C:\soulmemory\soulmemory_rs.dll"#);
        //self.process.inject_dll(r#"C:\projects\soulmemory-rs\target\x86_64-pc-windows-msvc\release\soulmemory_rs.dll"#);
        self.process.inject_dll(r#"C:\projects\soulmemory-rs\target\x86_64-pc-windows-msvc\å\soulmemory_rs.dll"#).expect("TODO: panic message");
    }
Source§

impl Process

Source

pub fn scan_abs( &self, error_name: &str, pattern: &str, scan_offset: usize, pointer_offsets: Vec<usize>, ) -> Result<Pointer, String>

Does an absolute scan (for x86 targets or for process code) where the target pointer is absolute Takes a list of offsets to create pointer jumps down a bigger complex structure. Pointers implement memory reading and writing.

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
process.refresh()?;
let pointer = process.scan_abs("Error message", "56 8B F1 8B 46 1C 50 A1 ? ? ? ? 32 C9", 8, vec![0, 0, 0])?;
Source

pub fn scan_rel( &self, error_name: &str, pattern: &str, scan_offset: usize, instruction_size: usize, pointer_offsets: Vec<usize>, ) -> Result<Pointer, String>

Does a relative scan (for x64 targets) where the target pointer is located relative to instruction’s size and location. Takes a list of offsets to create pointer jumps down a bigger complex structure. Pointers implement memory reading and writing.

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
process.refresh()?;
let pointer = process.scan_rel("Error message", "48 8b 05 ? ? ? ? 48 8b 50 10 48 89 54 24 60", 3, 7, vec![0])?;
Examples found in repository?
examples/dsr.rs (line 56)
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    pub fn refresh(&mut self) -> Result<(), String>
    {
        if !self.process.is_attached()
        {
            self.process.refresh()?;
            self.game_data_man = self.process.scan_rel("GameDataMan", "48 8b 05 ? ? ? ? 48 8b 50 10 48 89 54 24 60", 3, 7, vec![0])?;
            self.ai_timer = self.process.scan_rel("AI Timer", "48 8b 0d ? ? ? ? 48 85 c9 74 0e 48 83 c1 28", 3, 7, vec![0])?;
        }
        else
        {
            self.process.refresh()?;
        }
        Ok(())
    }
Source

pub fn create_pointer( &self, address: usize, pointer_offsets: Vec<usize>, ) -> Pointer

Create a pointer without scanning from an absolute address and a list of offsets. For special use cases where an address might be the result of some calculation.

let network = vanilla.process.create_pointer(network_ptr as usize, vec![0xc, 0x6c978])

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
process.refresh()?;
let magic_address = 0x1234;
let pointer = process.create_pointer(magic_address, vec![0xc, 0x10]);
Source§

impl Process

Source

pub fn refresh(&mut self) -> Result<(), String>

Attempts to “attach” to a running process by name. Returns an error when the process is not running or when it has exited. Caches the main module so that pattern scans can be done against it.

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
process.refresh().expect("Failed to attach/refresh!");
Examples found in repository?
examples/dsr.rs (line 55)
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    pub fn refresh(&mut self) -> Result<(), String>
    {
        if !self.process.is_attached()
        {
            self.process.refresh()?;
            self.game_data_man = self.process.scan_rel("GameDataMan", "48 8b 05 ? ? ? ? 48 8b 50 10 48 89 54 24 60", 3, 7, vec![0])?;
            self.ai_timer = self.process.scan_rel("AI Timer", "48 8b 0d ? ? ? ? 48 85 c9 74 0e 48 83 c1 28", 3, 7, vec![0])?;
        }
        else
        {
            self.process.refresh()?;
        }
        Ok(())
    }
Source§

impl Process

Source

pub fn get_current_process_name() -> Result<String, ()>

Returns the current process name, in which this very code is running. Does NOT return the name of the target attachment process.

§Examples
use mem_rs::prelude::*;

let name = Process::get_current_process_name()?;
Source

pub fn get_running_process_names() -> Vec<String>

Returns all the processes that are currently running

§Examples
use mem_rs::prelude::*;

let names = Process::get_running_process_names();
Examples found in repository?
examples/dsr.rs (line 88)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
fn main()
{
    let str = r#"C:\soulmemory\soulmemory_rs.dll"#;
    let w32_str = get_w32str_from_str(str);
    println!("{:?}", w32_str);
    println!("{:?}", vec_u16_to_u8(&w32_str));

    let allocated_str = String::from(str);
    let collected: Vec<u16> = allocated_str.encode_utf16().collect();
    println!("{:?}", collected);
    unsafe { println!("{:?}", collected.align_to::<u8>()); }


    let processes = Process::get_running_process_names();
    for p in &processes
    {
        println!("{}", p);
    }

    let mut ds1 = Ds1::new();

    loop
    {
        match ds1.refresh()
        {
            Ok(()) => {}
            Err(e) => println!("{}", e)
        }

        //ds1.inject_soulmemory_rs();

        println!("igt: {}", ds1.get_in_game_time_milliseconds());
        println!("ai: {}", ds1.get_ai_timer());
        sleep(Duration::from_secs(1));
    }
}
Source§

impl Process

Source

pub fn new(name: &str) -> Self

Creates a new process based on the process name.

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
Examples found in repository?
examples/dsr.rs (line 35)
31
32
33
34
35
36
37
38
39
    pub fn new() -> Self
    {
        Ds1
        {
            process: Process::new("DarkSoulsRemastered.exe"),
            game_data_man: Pointer::default(),
            ai_timer: Pointer::default(),
        }
    }
Source

pub fn is_attached(&self) -> bool

Returns if the process is “attached” and can be read/written from/to

§Examples
use mem_rs::prelude::*;

let mut process = Process::new("name_of_process.exe");
//returns false
let not_attached = process.is_attached();

//refreshing the process will cause it to become attached
process.refresh().unwrap();

//if name_of_process.exe is running, will return true
let attached = process.is_attached();
Examples found in repository?
examples/dsr.rs (line 53)
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    pub fn refresh(&mut self) -> Result<(), String>
    {
        if !self.process.is_attached()
        {
            self.process.refresh()?;
            self.game_data_man = self.process.scan_rel("GameDataMan", "48 8b 05 ? ? ? ? 48 8b 50 10 48 89 54 24 60", 3, 7, vec![0])?;
            self.ai_timer = self.process.scan_rel("AI Timer", "48 8b 0d ? ? ? ? 48 85 c9 74 0e 48 83 c1 28", 3, 7, vec![0])?;
        }
        else
        {
            self.process.refresh()?;
        }
        Ok(())
    }
Source

pub fn get_path(&self) -> String

Returns file path of the processes’ executable

§Examples
use mem_rs::prelude::*;
 
let mut process = Process::new("name_of_process.exe");
process.refresh().unwrap();
 
println!("{}", process.get_path());

Trait Implementations§

Source§

impl BaseReadWrite for Process

Source§

fn read_memory_rel(&self, offset: Option<usize>, buffer: &mut [u8]) -> bool

Read memory relative to the object’s location in memory. Supports an optional offset. Read more
Source§

fn write_memory_rel(&self, offset: Option<usize>, buffer: &[u8]) -> bool

Write memory relative to the object’s location in memory. Supports an optional offset. Read more
Source§

fn read_memory_abs(&self, address: usize, buffer: &mut [u8]) -> bool

Read memory from an absolute address Read more
Source§

fn write_memory_abs(&self, address: usize, buffer: &[u8]) -> bool

Write memory to an absolute address Read more
Source§

fn read_with_handle( &self, handle: HANDLE, address: usize, buffer: &mut [u8], ) -> bool

Read memory into a buffer from a process handle
Source§

fn write_with_handle( &self, handle: HANDLE, address: usize, buffer: &[u8], ) -> bool

Write from a buffer ino memory from a process handle
Source§

impl ReadWrite for Process

Source§

fn read_i8_rel(&self, address: Option<usize>) -> i8

Relatively read an i8 from an optional offset Read more
Source§

fn read_i32_rel(&self, address: Option<usize>) -> i32

Relatively read an i32 from an optional offset Read more
Source§

fn read_i64_rel(&self, address: Option<usize>) -> i64

Relatively read an i64 from an optional offset Read more
Source§

fn read_u8_rel(&self, address: Option<usize>) -> u8

Relatively read an u8 from an optional offset Read more
Source§

fn read_u32_rel(&self, address: Option<usize>) -> u32

Relatively read an u32 from an optional offset Read more
Source§

fn read_u64_rel(&self, address: Option<usize>) -> u64

Relatively read an u64 from an optional offset Read more
Source§

fn read_f32_rel(&self, address: Option<usize>) -> f32

Relatively read an f32 from an optional offset Read more
Source§

fn read_f64_rel(&self, address: Option<usize>) -> f64

Relatively read an f64 from an optional offset Read more
Source§

fn read_bool_rel(&self, address: Option<usize>) -> bool

Relatively read a bool from an optional offset. A single byte is read from the resolved address, the value of the bool is true if this byte is non-zero. Read more
Source§

fn write_i8_rel(&self, address: Option<usize>, value: i8)

Relatively write an i8 to an optional offset Read more
Source§

fn write_i32_rel(&self, address: Option<usize>, value: i32)

Relatively write an i32 to an optional offset Read more
Source§

fn write_i64_rel(&self, address: Option<usize>, value: i64)

Relatively write an i64 to an optional offset Read more
Source§

fn write_u8_rel(&self, address: Option<usize>, value: u8)

Relatively write an u8 to an optional offset Read more
Source§

fn write_u32_rel(&self, address: Option<usize>, value: u32)

Relatively write an u32 to an optional offset Read more
Source§

fn write_u64_rel(&self, address: Option<usize>, value: u64)

Relatively write an u64 to an optional offset Read more
Source§

fn write_f32_rel(&self, address: Option<usize>, value: f32)

Relatively write an f32 to an optional offset Read more
Source§

fn write_f64_rel(&self, address: Option<usize>, value: f64)

Relatively write an f64 to an optional offset Read more

Auto Trait Implementations§

§

impl Freeze for Process

§

impl !RefUnwindSafe for Process

§

impl !Send for Process

§

impl !Sync for Process

§

impl Unpin for Process

§

impl !UnwindSafe for Process

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.