Implement ReadProcessMemory compression
This commit is contained in:
Родитель
b1694a9457
Коммит
f0858ddea9
|
@ -1,5 +1,11 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.6"
|
||||
|
@ -47,6 +53,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"log",
|
||||
"miniz_oxide",
|
||||
"simplelog",
|
||||
"tokio",
|
||||
"winapi",
|
||||
|
@ -156,6 +163,16 @@ version = "2.3.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.5"
|
||||
|
|
|
@ -9,6 +9,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
bytes = "0.6"
|
||||
log = "0.4.11"
|
||||
miniz_oxide = "0.4.3"
|
||||
simplelog = "0.7.6"
|
||||
tokio = { version = "0.3.3", features = ["net", "rt-multi-thread", "io-util"] }
|
||||
winapi = { version = "0.3.9", features = ["memoryapi", "processthreadsapi", "tlhelp32", "winnt"], optional = true }
|
||||
|
|
|
@ -105,3 +105,24 @@ pub fn get_process_architecture() -> Architecture {
|
|||
std::compile_error!("Current architecture is not supported by Cheat Engine")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ReadMemoryData {
|
||||
Uncompressed {
|
||||
data: Vec<u8>,
|
||||
},
|
||||
Compressed {
|
||||
uncompressed_size: u32,
|
||||
compressed_data: Vec<u8>,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn compress_data(data: Vec<u8>, level: u8) -> Vec<u8> {
|
||||
// const BLOCK_SIZE: usize = 64 * 1024;
|
||||
// let max_blocks = 1 + (data.len() / BLOCK_SIZE);
|
||||
// let blocks = vec![[0u8; BLOCK_SIZE]; max_blocks];
|
||||
|
||||
// deflate to first block
|
||||
let compressed = miniz_oxide::deflate::compress_to_vec_zlib(&data[..], level);
|
||||
compressed
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ pub struct ReadProcessMemoryRequest {
|
|||
pub handle: u32,
|
||||
pub address: u64,
|
||||
pub size: u32,
|
||||
pub compress: bool,
|
||||
pub compression_level: u8,
|
||||
}
|
||||
|
||||
impl CERequest for ReadProcessMemoryRequest {
|
||||
|
@ -180,7 +180,7 @@ impl CERequest for ReadProcessMemoryRequest {
|
|||
handle: buf.get_u32_le(),
|
||||
address: buf.get_u64_le(),
|
||||
size: buf.get_u32_le(),
|
||||
compress: buf.get_u8() != 0,
|
||||
compression_level: buf.get_u8(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,13 +91,25 @@ impl CEResponse for GetSymbolListFromFileResponse {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct ReadProcessMemoryResponse {
|
||||
pub data: Vec<u8>,
|
||||
pub data: ReadMemoryData,
|
||||
}
|
||||
|
||||
impl CEResponse for ReadProcessMemoryResponse {
|
||||
fn serialize(self, writer: &mut dyn BufMut) {
|
||||
writer.put_i32_le(self.data.len() as i32);
|
||||
writer.put_slice(&self.data[..]);
|
||||
match self.data {
|
||||
ReadMemoryData::Uncompressed { data } => {
|
||||
writer.put_i32_le(data.len() as i32);
|
||||
writer.put_slice(&data[..]);
|
||||
}
|
||||
ReadMemoryData::Compressed {
|
||||
uncompressed_size,
|
||||
compressed_data,
|
||||
} => {
|
||||
writer.put_u32_le(uncompressed_size);
|
||||
writer.put_u32_le(compressed_data.len() as u32);
|
||||
writer.put_slice(&compressed_data[..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,10 +157,18 @@ impl Handler<ReadProcessMemoryRequest> for WindowsHandler {
|
|||
&mut bytes_read,
|
||||
)
|
||||
};
|
||||
if req.compress {
|
||||
todo!()
|
||||
if req.compression_level != 0 {
|
||||
buffer = compress_data(buffer, req.compression_level);
|
||||
ReadProcessMemoryResponse {
|
||||
data: ReadMemoryData::Compressed {
|
||||
uncompressed_size: bytes_read as u32,
|
||||
compressed_data: buffer,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
ReadProcessMemoryResponse { data: buffer }
|
||||
ReadProcessMemoryResponse {
|
||||
data: ReadMemoryData::Uncompressed { data: buffer },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче