mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-04-24 19:25:34 +08:00
Move platform specific configs in config.rs
This commit is contained in:
parent
10a908ab6f
commit
96da055d1a
@ -39,3 +39,36 @@ pub struct Signature {
|
||||
pub pattern: String,
|
||||
pub operations: Vec<Operation>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SchemaSystemConfig {
|
||||
pub module_name: &'static str,
|
||||
pub pattern: &'static str,
|
||||
pub type_scope_size_offset: usize,
|
||||
pub type_scope_data_offset: usize,
|
||||
pub declared_classes_offset: usize,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub const SCHEMA_CONF: SchemaSystemConfig = SchemaSystemConfig {
|
||||
module_name: "schemasystem.dll",
|
||||
pattern: "48 8D 0D ? ? ? ? E9 ? ? ? ? CC CC CC CC 48 8D 0D ? ? ? ? E9 ? ? ? ? CC CC CC CC 48 83 EC 28",
|
||||
type_scope_size_offset: 0x190,
|
||||
type_scope_data_offset: 0x198,
|
||||
declared_classes_offset: 0x5B8,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const SCHEMA_CONF: SchemaSystemConfig = SchemaSystemConfig {
|
||||
module_name: "libschemasystem.so",
|
||||
pattern: "48 8D 05 ? ? ? ? c3 ? ? ? 00 00 00 00 00 48 8d 05 ? ? ? ? c3 ? ? ? 00 00 00 00 00 48 ? ? ? c3",
|
||||
type_scope_size_offset: 0x1f8,
|
||||
type_scope_data_offset: 0x200,
|
||||
declared_classes_offset: 0x620,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub const PROC_NAME: &str = "cs2.exe";
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const PROC_NAME: &str = "cs2";
|
||||
|
@ -93,7 +93,7 @@ fn main() -> Result<()> {
|
||||
// Create the output directory if it doesn't exist.
|
||||
fs::create_dir_all(&output)?;
|
||||
|
||||
let mut process = Process::new("cs2.exe")?;
|
||||
let mut process = Process::new(config::PROC_NAME)?;
|
||||
|
||||
let now = Instant::now();
|
||||
|
||||
|
@ -56,8 +56,8 @@ impl Process {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn new(process_name: &str) -> Result<Self> {
|
||||
let id = Self::get_process_id_by_name(process_name.strip_suffix(".exe").unwrap())?;
|
||||
pub fn new(name: &str) -> Result<Self> {
|
||||
let id = Self::get_process_id_by_name(name)?;
|
||||
let mut process = Self {
|
||||
id,
|
||||
modules: HashMap::new(),
|
||||
@ -298,29 +298,6 @@ impl Process {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn read_elf_file(path: &PathBuf) -> Result<Vec<u8>> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
fn get_transformed_module_name(path: PathBuf) -> Option<String> {
|
||||
if let Ok(module_path) = path.into_os_string().into_string() {
|
||||
if let Some(module_name) = module_path.split('/').last() {
|
||||
if module_name.starts_with("lib") && module_name.ends_with(".so") {
|
||||
return Some(format!(
|
||||
"{}.dll",
|
||||
module_name.strip_prefix("lib")?.strip_suffix(".so")?
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn parse_loaded_modules(&mut self) -> Result<()> {
|
||||
let process = process::Process::new(self.id as i32)?;
|
||||
@ -328,35 +305,37 @@ impl Process {
|
||||
let mut modules_info: HashMap<String, ((u64, u64), PathBuf)> = HashMap::new();
|
||||
|
||||
for mmap in process.maps()? {
|
||||
let mmap_path = match mmap.pathname {
|
||||
let module_path = match mmap.pathname {
|
||||
process::MMapPath::Path(path) => path,
|
||||
_ => continue,
|
||||
};
|
||||
let module_name = match Process::get_transformed_module_name(mmap_path.clone()) {
|
||||
Some(new_path) => new_path,
|
||||
None => continue,
|
||||
let get_module_name = |path: &PathBuf| -> Option<String> {
|
||||
path.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.filter(|name| name.starts_with("lib") && name.ends_with(".so"))
|
||||
.map(|name| name.to_string())
|
||||
};
|
||||
if module_name != "client.dll"
|
||||
&& module_name != "engine2.dll"
|
||||
&& module_name != "inputsystem.dll"
|
||||
&& module_name != "matchmaking.dll"
|
||||
&& module_name != "schemasystem.dll"
|
||||
{
|
||||
continue;
|
||||
if let Some(module_name) = get_module_name(&module_path) {
|
||||
let module_entry = modules_info
|
||||
.entry(module_name)
|
||||
.or_insert_with(|| (mmap.address, module_path));
|
||||
module_entry.0 = (
|
||||
std::cmp::min(mmap.address.0, module_entry.0 .0),
|
||||
std::cmp::max(mmap.address.1, module_entry.0 .1),
|
||||
);
|
||||
}
|
||||
let module_entry = modules_info
|
||||
.entry(module_name)
|
||||
.or_insert_with(|| (mmap.address, mmap_path));
|
||||
module_entry.0 = (
|
||||
std::cmp::min(mmap.address.0, module_entry.0 .0),
|
||||
std::cmp::max(mmap.address.1, module_entry.0 .1),
|
||||
);
|
||||
}
|
||||
|
||||
for (module_name, (address_space, path)) in modules_info.into_iter() {
|
||||
let (start, end) = address_space;
|
||||
// let mut data = vec![0; (end - start + 1) as usize];
|
||||
if let Ok(data) = Process::read_elf_file(&path) {
|
||||
let read_elf_file = |path: &PathBuf| -> Result<Vec<u8>> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
Ok(data)
|
||||
};
|
||||
if let Ok(data) = read_elf_file(&path) {
|
||||
self.modules.insert(
|
||||
module_name,
|
||||
ModuleEntry {
|
||||
|
@ -6,6 +6,8 @@ use super::SchemaSystemTypeScope;
|
||||
|
||||
use crate::os::Process;
|
||||
|
||||
use crate::config::SCHEMA_CONF;
|
||||
|
||||
pub struct SchemaSystem<'a> {
|
||||
process: &'a Process,
|
||||
address: usize,
|
||||
@ -14,11 +16,7 @@ pub struct SchemaSystem<'a> {
|
||||
impl<'a> SchemaSystem<'a> {
|
||||
pub fn new(process: &'a Process) -> Result<Self> {
|
||||
let mut address = process
|
||||
.find_pattern(
|
||||
"schemasystem.dll",
|
||||
"48 8D 05 ? ? ? ? c3 ? ? ? 00 00 00 00 00 48 8d 05 ? ? ? ? c3 ? ? ? 00 00 00 00 00 48 ? ? ? c3"
|
||||
// "48 8D 0D ? ? ? ? E9 ? ? ? ? CC CC CC CC 48 8D 0D ? ? ? ? E9 ? ? ? ? CC CC CC CC 48 83 EC 28"
|
||||
)
|
||||
.find_pattern(SCHEMA_CONF.module_name, SCHEMA_CONF.pattern)
|
||||
.expect("unable to find schema system pattern");
|
||||
|
||||
address = process.resolve_rip(address, None, None)?;
|
||||
@ -27,15 +25,17 @@ impl<'a> SchemaSystem<'a> {
|
||||
}
|
||||
|
||||
pub fn type_scopes(&self) -> Result<Vec<SchemaSystemTypeScope>> {
|
||||
// let size = self.process.read_memory::<u32>(self.address + 0x190)?;
|
||||
let size = self.process.read_memory::<u32>(self.address + 0x1f8)?;
|
||||
let size = self
|
||||
.process
|
||||
.read_memory::<u32>(self.address + SCHEMA_CONF.type_scope_size_offset)?;
|
||||
|
||||
if size == 0 {
|
||||
bail!("no type scopes found");
|
||||
}
|
||||
|
||||
// let data = self.process.read_memory::<usize>(self.address + 0x198)?;
|
||||
let data = self.process.read_memory::<usize>(self.address + 0x200)?;
|
||||
let data = self
|
||||
.process
|
||||
.read_memory::<usize>(self.address + SCHEMA_CONF.type_scope_data_offset)?;
|
||||
|
||||
let mut addresses = vec![0; size as usize];
|
||||
|
||||
|
@ -4,6 +4,8 @@ use super::{SchemaClassInfo, SchemaTypeDeclaredClass, UtlTsHash};
|
||||
|
||||
use crate::os::Process;
|
||||
|
||||
use crate::config::SCHEMA_CONF;
|
||||
|
||||
pub struct SchemaSystemTypeScope<'a> {
|
||||
process: &'a Process,
|
||||
address: usize,
|
||||
@ -17,8 +19,9 @@ impl<'a> SchemaSystemTypeScope<'a> {
|
||||
pub fn classes(&self) -> Result<Vec<SchemaClassInfo>> {
|
||||
let declared_classes = self
|
||||
.process
|
||||
.read_memory::<UtlTsHash<*mut SchemaTypeDeclaredClass>>(self.address + 0x620)?;
|
||||
// .read_memory::<UtlTsHash<*mut SchemaTypeDeclaredClass>>(self.address + 0x5B8)?;
|
||||
.read_memory::<UtlTsHash<*mut SchemaTypeDeclaredClass>>(
|
||||
self.address + SCHEMA_CONF.declared_classes_offset,
|
||||
)?;
|
||||
|
||||
let classes: Vec<SchemaClassInfo> = declared_classes
|
||||
.elements(self.process)?
|
||||
|
Loading…
x
Reference in New Issue
Block a user