From 28f41cf689def99fb586bfca47b7e1786227a5a2 Mon Sep 17 00:00:00 2001 From: navewindre Date: Fri, 12 Jul 2024 05:40:41 +0200 Subject: base shit --- src/cs2/cs2.h | 46 ++++++++++++++++++++++++ src/cs2/hack.cpp | 22 ++++++++++++ src/cs2/hack.h | 9 +++++ src/cs2/iface.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cs2/schema.h | 0 5 files changed, 183 insertions(+) create mode 100644 src/cs2/cs2.h create mode 100644 src/cs2/hack.cpp create mode 100644 src/cs2/hack.h create mode 100644 src/cs2/iface.h create mode 100644 src/cs2/schema.h (limited to 'src/cs2') diff --git a/src/cs2/cs2.h b/src/cs2/cs2.h new file mode 100644 index 0000000..58eba14 --- /dev/null +++ b/src/cs2/cs2.h @@ -0,0 +1,46 @@ +#pragma once + +#include "../process64.h" + +class CS2 : public PROCESS64 { +public: + CS2() : PROCESS64( "cs2.exe" ) {}; + + bool open() { + if( !PROCESS64::open() ) + return false; + + mod.client = get_module64( "client.dll"fnv ); + mod.engine = get_module64( "engine.dll"fnv ); + mod.schema = get_module64( "schemasystem.dll"fnv ); + + // todo: handle this using loader + iface.client = get_iface( "Source2Client0" ); + iface.engine = get_iface( "Source2EngineToClient0" ); + + return true; + } + + IFACE_ENTRY get_iface( const char* name ) { + VECTOR entries = iface_get_all( this ); + for( auto it : entries ) { + if( strncmp( it.name, name, strlen( name ) ) == 0 ) { + clog( "iface %s: [%llx]\n", it.name.data, it.ptr ); + return it; + } + } + + return {}; + } + + struct { + MODULE_ENTRY client; + MODULE_ENTRY engine; + MODULE_ENTRY schema; + } mod; + + struct { + IFACE_ENTRY client; + IFACE_ENTRY engine; + } iface; +}; \ No newline at end of file diff --git a/src/cs2/hack.cpp b/src/cs2/hack.cpp new file mode 100644 index 0000000..b5f0242 --- /dev/null +++ b/src/cs2/hack.cpp @@ -0,0 +1,22 @@ +#include "hack.h" +#include "iface.h" + +SETTING_HOLDER gcfg; + +#include "cs2.h" + +PROCESS64* hack_init() { + CS2* p = new CS2(); + if( !p->open() ) { + delete p; + return nullptr; + } + + VECTOR entries = iface_get_all( p ); + + return p; +} + +bool hack_run( PROCESS64* p ) { + return true; +} \ No newline at end of file diff --git a/src/cs2/hack.h b/src/cs2/hack.h new file mode 100644 index 0000000..18bd4e3 --- /dev/null +++ b/src/cs2/hack.h @@ -0,0 +1,9 @@ +#pragma once + +#include "../process64.h" +#include "../setting.h" + +extern SETTING_HOLDER gcfg; + +extern PROCESS64* hack_init(); +extern bool hack_run( PROCESS64* p ); \ No newline at end of file diff --git a/src/cs2/iface.h b/src/cs2/iface.h new file mode 100644 index 0000000..6c3b34b --- /dev/null +++ b/src/cs2/iface.h @@ -0,0 +1,106 @@ +#pragma once + +#include "../process64.h" + +struct IFACE_ENTRY { + U64 ptr; + STR<64> name; + U64 module; + STR<64> module_name; +}; + +struct IFACE_REG { + U64 create_fn; + U64 name; + U64 next; +}; + +inline bool iface_is_createinterface_export( PROCESS64* p, U64 exp ) { + U8 data[64]; + p->read( exp, data, 64 ); + + // mov r9, cs:iface_list + // mov r10, rdx + return + data[0] == 0x4c && data[1] == 0x8b && data[2] == 0x0d && + data[7] == 0x4c && data[8] == 0x8b && data[9] == 0xd2; +} + +inline U64 iface_get_list( PROCESS64* p, U64 createiface ) { + U8 data[64]; + p->read( createiface, data, 64 ); + + U32 off = *(U32*)&data[3]; + U64 list = createiface + off + 7; + + return p->read( list ); +} + +inline U64 iface_get_address( PROCESS64* p, U64 create_fn ) { + U8 data[64]; + p->read( create_fn, data, 64 ); + + U32 off = *(U32*)&data[3]; + U64 addr = create_fn + off + 7; +} + +inline U64 iface_get_createinterface( PROCESS64* p, U64 module ) { + VECTOR exports = module_get_exports64( module, p->get_base() ); + for( auto& it : exports ) { + if( fnv1a( it.name ) == "CreateInterface"fnv ) + return it.base; + } + + return {}; +} + +inline VECTOR iface_dump_module( PROCESS64* p, MODULE_ENTRY module ) { + VECTOR entries; + U64 createiface, list, head, prev; + IFACE_REG reg; + + createiface = iface_get_createinterface( p, module.base ); + if( !createiface ) + return entries; + + if( !iface_is_createinterface_export( p, createiface ) ) + return entries; + + list = iface_get_list( p, createiface ); + if( !list ) + return entries; + + head = list; + prev = 0; + p->read( head, ®, sizeof( IFACE_REG ) ); + + for( ;; ) { + IFACE_ENTRY entry; + p->read( reg.name, entry.name.data, 64 ); + entry.ptr = reg.create_fn; + entry.module = module.base; + entry.module_name = module.name; + entries.push_back( entry ); + + if( reg.next == head || reg.next == prev || !reg.next ) + break; + + prev = reg.next; + p->read( reg.next, ®, sizeof( IFACE_REG ) ); + } + + return entries; +} + +inline VECTOR iface_get_all( PROCESS64* p ) { + VECTOR entries; + + VECTOR modules = p->dump_modules(); + for( auto& it : modules ) { + VECTOR module_entries = iface_dump_module( p, it ); + entries.insert( entries.end(), module_entries.begin(), module_entries.end() ); + } + + return entries; +} + diff --git a/src/cs2/schema.h b/src/cs2/schema.h new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3