Refactor and move Linux code to separate branch

This commit is contained in:
a2x
2024-04-03 02:59:30 +11:00
parent 86dc0fa8f6
commit 3a935f5d73
229 changed files with 705 additions and 121739 deletions

View File

@@ -0,0 +1,13 @@
use memflow::prelude::v1::*;
#[repr(C)]
pub struct KeyboardKey {
pad_0000: [u8; 0x8],
pub name: Pointer64<ReprCString>,
pad_0010: [u8; 0x20],
pub state: u32,
pad_0034: [u8; 0x50],
pub next: Pointer64<KeyboardKey>,
}
unsafe impl Pod for KeyboardKey {}

View File

@@ -0,0 +1,3 @@
pub use input::*;
pub mod input;

7
src/source2/mod.rs Normal file
View File

@@ -0,0 +1,7 @@
pub use client::*;
pub use schema_system::*;
pub use tier1::*;
pub mod client;
pub mod schema_system;
pub mod tier1;

View File

@@ -0,0 +1,21 @@
pub use schema_base_class_info_data::*;
pub use schema_class_field_data::*;
pub use schema_class_info_data::*;
pub use schema_enum_info_data::*;
pub use schema_enumerator_info_data::*;
pub use schema_metadata_entry_data::*;
pub use schema_static_field_data::*;
pub use schema_system::*;
pub use schema_system_type_scope::*;
pub use schema_type::*;
pub mod schema_base_class_info_data;
pub mod schema_class_field_data;
pub mod schema_class_info_data;
pub mod schema_enum_info_data;
pub mod schema_enumerator_info_data;
pub mod schema_metadata_entry_data;
pub mod schema_static_field_data;
pub mod schema_system;
pub mod schema_system_type_scope;
pub mod schema_type;

View File

@@ -0,0 +1,11 @@
use memflow::prelude::v1::*;
use super::SchemaClassInfoData;
#[repr(C)]
pub struct SchemaBaseClassInfoData {
pub offset: u32,
pub prev: Pointer64<SchemaClassInfoData>,
}
unsafe impl Pod for SchemaBaseClassInfoData {}

View File

@@ -0,0 +1,14 @@
use memflow::prelude::v1::*;
use super::{SchemaMetadataEntryData, SchemaType};
#[repr(C)]
pub struct SchemaClassFieldData {
pub name: Pointer64<ReprCString>,
pub type_: Pointer64<SchemaType>,
pub offset: u32,
pub metadata_count: u32,
pub metadata: Pointer64<SchemaMetadataEntryData>,
}
unsafe impl Pod for SchemaClassFieldData {}

View File

@@ -0,0 +1,33 @@
use memflow::prelude::v1::*;
use super::{
SchemaBaseClassInfoData, SchemaClassFieldData, SchemaMetadataEntryData, SchemaStaticFieldData,
SchemaSystemTypeScope, SchemaType,
};
pub type SchemaClassBinding = SchemaClassInfoData;
#[repr(C)]
pub struct SchemaClassInfoData {
pub base: Pointer64<SchemaClassInfoData>,
pub name: Pointer64<ReprCString>,
pub module_name: Pointer64<ReprCString>,
pub size: u32,
pub fields_count: u16,
pub static_fields_count: u16,
pub static_metadata_count: u16,
pub alignment: u8,
pub has_base_class: bool,
pub total_class_size: u16,
pub derived_class_size: u16,
pub fields: Pointer64<SchemaClassFieldData>,
pub static_fields: Pointer64<SchemaStaticFieldData>,
pub base_classes: Pointer64<SchemaBaseClassInfoData>,
pad_0040: [u8; 0x8],
pub static_metadata: Pointer64<SchemaMetadataEntryData>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pub type_: Pointer64<SchemaType>,
pad_0060: [u8; 0x10],
}
unsafe impl Pod for SchemaClassInfoData {}

View File

@@ -0,0 +1,22 @@
use memflow::prelude::v1::*;
use super::{SchemaEnumeratorInfoData, SchemaMetadataEntryData, SchemaSystemTypeScope};
pub type SchemaEnumBinding = SchemaEnumInfoData;
#[repr(C)]
pub struct SchemaEnumInfoData {
pub base: Pointer64<SchemaEnumInfoData>,
pub name: Pointer64<ReprCString>,
pub module_name: Pointer64<ReprCString>,
pub alignment: u8,
pad_0019: [u8; 0x3],
pub size: u16,
pub static_metadata_count: u16,
pub enum_info: Pointer64<SchemaEnumeratorInfoData>,
pub static_metadata: Pointer64<SchemaMetadataEntryData>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pad_0038: [u8; 0xC],
}
unsafe impl Pod for SchemaEnumInfoData {}

View File

@@ -0,0 +1,21 @@
use memflow::prelude::v1::*;
use super::SchemaMetadataEntryData;
#[repr(C)]
pub struct SchemaEnumeratorInfoData {
pub name: Pointer64<ReprCString>,
pub u: SchemaEnumeratorInfoDataUnion,
pub metadata_count: u32,
pub metadata: Pointer64<SchemaMetadataEntryData>,
}
unsafe impl Pod for SchemaEnumeratorInfoData {}
#[repr(C)]
pub union SchemaEnumeratorInfoDataUnion {
pub uchar: u8,
pub ushort: u16,
pub uint: u32,
pub ulong: u64,
}

View File

@@ -0,0 +1,35 @@
use std::ffi::c_char;
use memflow::prelude::v1::*;
#[repr(C)]
pub struct SchemaMetadataEntryData {
pub name: Pointer64<ReprCString>,
pub network_value: Pointer64<SchemaNetworkValue>,
}
unsafe impl Pod for SchemaMetadataEntryData {}
#[repr(C)]
pub struct SchemaNetworkValue {
pub u: SchemaNetworkValueUnion,
}
unsafe impl Pod for SchemaNetworkValue {}
#[repr(C)]
pub union SchemaNetworkValueUnion {
pub name_ptr: Pointer64<ReprCString>,
pub int_value: i32,
pub float_value: f32,
pub ptr: Pointer64<()>,
pub var_value: SchemaVarName,
pub name_value: [c_char; 32],
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaVarName {
pub name: Pointer64<ReprCString>,
pub ty: Pointer64<ReprCString>,
}

View File

@@ -0,0 +1,13 @@
use memflow::prelude::v1::*;
use super::SchemaType;
#[repr(C)]
pub struct SchemaStaticFieldData {
pub name: Pointer64<ReprCString>,
pub type_: Pointer64<SchemaType>,
pub instance: Address,
pad_0018: [u8; 0x10],
}
unsafe impl Pod for SchemaStaticFieldData {}

View File

@@ -0,0 +1,15 @@
use memflow::prelude::v1::*;
use super::SchemaSystemTypeScope;
use crate::source2::UtlVector;
#[repr(C)]
pub struct SchemaSystem {
pad_0000: [u8; 0x190],
pub type_scopes: UtlVector<Pointer64<SchemaSystemTypeScope>>,
pad_01a0: [u8; 0x120],
pub num_registrations: u32,
}
unsafe impl Pod for SchemaSystem {}

View File

@@ -0,0 +1,19 @@
use std::ffi::c_char;
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaEnumBinding};
use crate::source2::UtlTsHash;
#[repr(C)]
pub struct SchemaSystemTypeScope {
pad_0000: [u8; 0x8],
pub name: [c_char; 256],
pad_0108: [u8; 0x4B0],
pub class_bindings: UtlTsHash<Pointer64<SchemaClassBinding>>,
pad_05f0: [u8; 0x2810],
pub enum_bindings: UtlTsHash<Pointer64<SchemaEnumBinding>>,
}
unsafe impl Pod for SchemaSystemTypeScope {}

View File

@@ -0,0 +1,99 @@
use memflow::prelude::v1::*;
use super::{SchemaClassBinding, SchemaEnumBinding, SchemaSystemTypeScope};
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(u8)]
pub enum SchemaAtomicCategory {
Basic = 0,
T,
CollectionOfT,
TF,
TT,
TTF,
I,
None,
}
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(u8)]
pub enum SchemaTypeCategory {
BuiltIn = 0,
Ptr,
Bitfield,
FixedArray,
Atomic,
DeclaredClass,
DeclaredEnum,
None,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaArray {
pub array_size: u32,
pad_0004: [u8; 0x4],
pub element_type: Pointer64<SchemaType>,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomic {
pub element_type: Pointer64<SchemaType>,
pad_0008: [u8; 0x8],
pub template_ty: Pointer64<SchemaType>,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicI {
pad_0000: [u8; 0x10],
pub value: u64,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTF {
pad_0000: [u8; 0x10],
pub template_ty: Pointer64<SchemaType>,
pub size: u32,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTT {
pad_0000: [u8; 0x10],
pub templates: [Pointer64<SchemaType>; 2],
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct SchemaAtomicTTF {
pad_0000: [u8; 0x10],
pub templates: [Pointer64<SchemaType>; 2],
pub size: u32,
}
#[repr(C)]
pub struct SchemaType {
pad_0000: [u8; 0x8],
pub name: Pointer64<ReprCString>,
pub type_scope: Pointer64<SchemaSystemTypeScope>,
pub type_category: SchemaTypeCategory,
pub atomic_category: SchemaAtomicCategory,
}
unsafe impl Pod for SchemaType {}
#[repr(C)]
pub union SchemaTypeUnion {
pub schema_type: Pointer64<SchemaType>,
pub class_binding: Pointer64<SchemaClassBinding>,
pub enum_binding: Pointer64<SchemaEnumBinding>,
pub array: SchemaArray,
pub atomic: SchemaAtomic,
pub atomic_tt: SchemaAtomicTT,
pub atomic_tf: SchemaAtomicTF,
pub atomic_ttf: SchemaAtomicTTF,
pub atomic_i: SchemaAtomicI,
}

View File

@@ -0,0 +1,10 @@
use memflow::prelude::v1::*;
#[repr(C)]
pub struct InterfaceReg {
pub create_fn: Address,
pub name: Pointer64<ReprCString>,
pub next: Pointer64<InterfaceReg>,
}
unsafe impl Pod for InterfaceReg {}

7
src/source2/tier1/mod.rs Normal file
View File

@@ -0,0 +1,7 @@
pub use interface::*;
pub use utl_ts_hash::*;
pub use utl_vector::*;
pub mod interface;
pub mod utl_ts_hash;
pub mod utl_vector;

View File

@@ -0,0 +1,102 @@
use memflow::prelude::v1::*;
use crate::error::Result;
pub trait HashData: Copy + Sized + Pod {}
impl<T: Copy + Sized + Pod> HashData for T {}
pub trait HashKey: Copy + Sized + Pod {}
impl<K: Copy + Sized + Pod> HashKey for K {}
#[repr(C)]
struct HashFixedDataInternal<T: HashData, K: HashKey> {
ui_key: K,
next: Pointer64<HashFixedDataInternal<T, K>>,
data: T,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashFixedDataInternal<T, K> {}
#[repr(C)]
struct HashBucketDataInternal<T: HashData, K: HashKey> {
data: T,
next: Pointer64<HashFixedDataInternal<T, K>>,
ui_key: K,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashBucketDataInternal<T, K> {}
#[repr(C)]
struct HashAllocatedData<T: HashData, K: HashKey> {
pad_0000: [u8; 0x18],
list: [HashFixedDataInternal<T, K>; 128],
}
unsafe impl<T: HashData, K: HashKey> Pod for HashAllocatedData<T, K> {}
#[repr(C)]
struct HashUnallocatedData<T: HashData, K: HashKey> {
next: Pointer64<HashUnallocatedData<T, K>>,
unk_1: K,
ui_key: K,
unk_2: K,
block_list: [HashBucketDataInternal<T, K>; 256],
}
unsafe impl<T: HashData, K: HashKey> Pod for HashUnallocatedData<T, K> {}
#[repr(C)]
struct HashBucket<T: HashData, K: HashKey> {
pad_0000: [u8; 0x10],
allocated_data: Pointer64<HashAllocatedData<T, K>>,
unallocated_data: Pointer64<HashUnallocatedData<T, K>>,
}
unsafe impl<T: HashData, K: HashKey> Pod for HashBucket<T, K> {}
#[repr(C)]
struct UtlMemoryPool {
block_size: u32,
blocks_per_blob: u32,
grow_mode: u32,
blocks_alloc: u32,
block_alloc_size: u32,
peak_alloc: u32,
}
#[repr(C)]
pub struct UtlTsHash<T: HashData, K: HashKey = u64> {
entry: UtlMemoryPool,
buckets: HashBucket<T, K>,
}
impl<T: HashData, K: HashKey> UtlTsHash<T, K> {
pub fn elements(&self, process: &mut IntoProcessInstanceArcBox<'_>) -> Result<Vec<T>> {
let mut element_ptr = self.buckets.unallocated_data;
let min_size =
(self.entry.blocks_per_blob as usize).min(self.entry.block_alloc_size as usize);
let mut list = Vec::with_capacity(min_size);
while !element_ptr.is_null() {
let element = element_ptr.read(process)?;
for i in 0..min_size {
if list.len() >= self.entry.block_alloc_size as usize {
return Ok(list);
}
list.push(element.block_list[i].data);
}
element_ptr = element.next;
}
Ok(list)
}
}
unsafe impl<T: HashData, K: HashKey> Pod for UtlTsHash<T, K> {}

View File

@@ -0,0 +1,29 @@
use std::mem;
use memflow::prelude::v1::*;
use crate::error::{Error, Result};
#[repr(C)]
pub struct UtlVector<T: Copy + Sized + Pod> {
pub size: u32,
pub mem: Pointer64<T>,
}
impl<T: Copy + Sized + Pod> UtlVector<T> {
#[inline]
pub fn get(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result<T> {
if idx >= self.size as usize {
return Err(Error::OutOfBounds {
idx,
len: self.size as usize,
});
}
let ptr = Pointer64::from(self.mem.address() + (idx * mem::size_of::<T>()));
Ok(ptr.read(process)?)
}
}
unsafe impl<T: Copy + Sized + Pod> Pod for UtlVector<T> {}