Implement/stub more commands
This commit is contained in:
Родитель
d7d94c287c
Коммит
c6da286630
|
@ -10,8 +10,8 @@ edition = "2018"
|
|||
bytes = "0.6"
|
||||
log = "0.4.11"
|
||||
pretty_env_logger = "0.4.0"
|
||||
tokio = {version = "0.3.3", features = ["net", "rt-multi-thread", "io-util"]}
|
||||
winapi = {version = "0.3.9", features = ["tlhelp32"], optional = true}
|
||||
tokio = { version = "0.3.3", features = ["net", "rt-multi-thread", "io-util"] }
|
||||
winapi = { version = "0.3.9", features = ["processthreadsapi", "tlhelp32"], optional = true }
|
||||
|
||||
|
||||
[features]
|
||||
|
|
|
@ -13,6 +13,15 @@ pub struct CeModuleEntry {
|
|||
pub module_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)] // only the one matching this arch will be used
|
||||
pub enum Architecture {
|
||||
I386 = 1,
|
||||
X86_64 = 2,
|
||||
Arm = 3,
|
||||
AArch64 = 4,
|
||||
}
|
||||
|
||||
// NOTE: all handles seem to be 32-bit
|
||||
pub fn read_usize(buf: &mut dyn Buf) -> usize {
|
||||
match std::mem::size_of::<usize>() {
|
||||
|
@ -28,6 +37,13 @@ pub fn write_usize(buf: &mut dyn BufMut, value: usize) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_u32_prefixed_string(buf: &mut dyn Buf) -> String {
|
||||
let len = buf.get_u32_le();
|
||||
let mut v = vec![];
|
||||
v.put(buf.take(len as usize));
|
||||
unsafe { String::from_utf8_unchecked(v) }
|
||||
}
|
||||
|
||||
pub fn write_i32_prefixed_string(buf: &mut dyn BufMut, value: String) {
|
||||
let bytes = value.into_bytes();
|
||||
|
||||
|
@ -52,3 +68,31 @@ fn test_cstring_to_string() {
|
|||
assert_eq!(String::from("abc"), cstring_to_string(b"abc\0"));
|
||||
assert_eq!(String::from("abc"), cstring_to_string(b"abc\0\0abc"));
|
||||
}
|
||||
|
||||
pub fn get_process_architecture() -> Architecture {
|
||||
#[cfg(target_arch = "x86")]
|
||||
{
|
||||
Architecture::I386
|
||||
}
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
Architecture::X86_64
|
||||
}
|
||||
#[cfg(target_arch = "arm")]
|
||||
{
|
||||
Architecture::Arm
|
||||
}
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
{
|
||||
Architecture::AArch64
|
||||
}
|
||||
#[cfg(not(any(
|
||||
target_arch = "x86",
|
||||
target_arch = "x86_64",
|
||||
target_arch = "arm",
|
||||
target_arch = "aarch64",
|
||||
)))]
|
||||
{
|
||||
std::compile_error!("Current architecture is not supported by Cheat Engine")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,3 +114,50 @@ impl CERequest for Module32NextRequest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GetArchitectureRequest;
|
||||
|
||||
impl CERequest for GetArchitectureRequest {
|
||||
type Response = ArchitectureResponse;
|
||||
|
||||
const ID: Command = CMD_GETARCHITECTURE;
|
||||
|
||||
fn read(_buf: &mut dyn Buf) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OpenProcessRequest {
|
||||
pub pid: i32,
|
||||
}
|
||||
|
||||
impl CERequest for OpenProcessRequest {
|
||||
type Response = HandleResponse;
|
||||
|
||||
const ID: Command = CMD_OPENPROCESS;
|
||||
|
||||
fn read(buf: &mut dyn Buf) -> Self {
|
||||
OpenProcessRequest {
|
||||
pid: buf.get_i32_le(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GetSymbolListFromFileRequest {
|
||||
pub symbol_path: String,
|
||||
}
|
||||
|
||||
impl CERequest for GetSymbolListFromFileRequest {
|
||||
type Response = GetSymbolListFromFileResponse;
|
||||
|
||||
const ID: Command = CMD_GETSYMBOLLISTFROMFILE;
|
||||
|
||||
fn read(buf: &mut dyn Buf) -> Self {
|
||||
Self {
|
||||
symbol_path: read_u32_prefixed_string(buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,3 +67,24 @@ impl CEResponse for I32Response {
|
|||
writer.put_i32_le(self.response);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ArchitectureResponse {
|
||||
pub response: Architecture,
|
||||
}
|
||||
|
||||
impl CEResponse for ArchitectureResponse {
|
||||
fn serialize(self, writer: &mut dyn BufMut) {
|
||||
writer.put_u8(self.response as u8);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GetSymbolListFromFileResponse; // TODO implement
|
||||
|
||||
impl CEResponse for GetSymbolListFromFileResponse {
|
||||
fn serialize(self, writer: &mut dyn BufMut) {
|
||||
// writing 0 for now
|
||||
writer.put_i32(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ pub trait FullHandler:
|
|||
+ Handler<Module32FirstRequest>
|
||||
+ Handler<Module32NextRequest>
|
||||
+ Handler<CloseHandleRequest>
|
||||
+ Handler<GetArchitectureRequest>
|
||||
+ Handler<OpenProcessRequest>
|
||||
+ Handler<GetSymbolListFromFileRequest>
|
||||
{
|
||||
fn create() -> Self;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use crate::server::{ce_common::*, commands_request::*, commands_response::*, handler::*};
|
||||
use winapi::um::{
|
||||
handleapi::CloseHandle,
|
||||
tlhelp32::{
|
||||
CreateToolhelp32Snapshot, Module32First, Module32Next, Process32First, Process32Next,
|
||||
LPMODULEENTRY32, LPPROCESSENTRY32,
|
||||
use log::warn;
|
||||
use winapi::{
|
||||
shared::minwindef::FALSE,
|
||||
um::{
|
||||
handleapi::CloseHandle,
|
||||
processthreadsapi::OpenProcess,
|
||||
tlhelp32::{
|
||||
CreateToolhelp32Snapshot, Module32First, Module32Next, Process32First, Process32Next,
|
||||
LPMODULEENTRY32, LPPROCESSENTRY32,
|
||||
},
|
||||
winnt::{HANDLE, PROCESS_ALL_ACCESS},
|
||||
},
|
||||
winnt::HANDLE,
|
||||
};
|
||||
|
||||
pub struct WindowsHandler;
|
||||
|
@ -100,3 +105,31 @@ impl Handler<CloseHandleRequest> for WindowsHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<GetArchitectureRequest> for WindowsHandler {
|
||||
fn handle(&self, _eq: GetArchitectureRequest) -> ArchitectureResponse {
|
||||
ArchitectureResponse {
|
||||
response: get_process_architecture(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<OpenProcessRequest> for WindowsHandler {
|
||||
fn handle(&self, req: OpenProcessRequest) -> HandleResponse {
|
||||
unsafe {
|
||||
let resp = OpenProcess(PROCESS_ALL_ACCESS, FALSE, req.pid as u32);
|
||||
HandleResponse {
|
||||
handle: resp as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler<GetSymbolListFromFileRequest> for WindowsHandler {
|
||||
fn handle(&self, req: GetSymbolListFromFileRequest) -> GetSymbolListFromFileResponse {
|
||||
// TODO: see CheatEngine Server GetSymbolListFromFile
|
||||
// https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/ceserver/symbols.c
|
||||
warn!("STUBBED GetSymbolListFromFileRequest({})", req.symbol_path);
|
||||
GetSymbolListFromFileResponse
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ impl CheatEngineConnection {
|
|||
Module32FirstRequest,
|
||||
Module32NextRequest,
|
||||
CloseHandleRequest,
|
||||
GetArchitectureRequest,
|
||||
OpenProcessRequest,
|
||||
GetSymbolListFromFileRequest,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче