mem_rs/process/
read_write.rs

1// This file is part of the mem-rs distribution (https://github.com/FrankvdStam/mem-rs).
2// Copyright (c) 2022 Frank van der Stam.
3// https://github.com/FrankvdStam/mem-rs/blob/main/LICENSE
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, version 3.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17use crate::prelude::{BaseReadWrite, Process, ReadWrite};
18
19impl BaseReadWrite for Process
20{
21    fn read_memory_rel(&self, offset: Option<usize>, buffer: &mut [u8]) -> bool
22    {
23        let mut address = self.get_main_module().base_address;
24        if offset.is_some()
25        {
26            address += offset.unwrap();
27        }
28        return self.read_with_handle(self.process_data.borrow().handle, self.get_memory_type(), address, buffer);
29    }
30
31    fn write_memory_rel(&self, offset: Option<usize>, buffer: &[u8]) -> bool
32    {
33        let mut address = self.get_main_module().base_address;
34        if offset.is_some()
35        {
36            address += offset.unwrap();
37        }
38        return self.write_with_handle(self.process_data.borrow().handle, self.get_memory_type(), address, buffer);
39    }
40
41    fn read_memory_abs(&self, address: usize, buffer: &mut [u8]) -> bool
42    {
43        return self.read_with_handle(self.process_data.borrow().handle, self.get_memory_type(), address, buffer);
44    }
45
46    fn write_memory_abs(&self, address: usize, buffer: &[u8]) -> bool
47    {
48        return self.write_with_handle(self.process_data.borrow().handle, self.get_memory_type(), address, buffer);
49    }
50}
51
52impl ReadWrite for Process{}