Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update signatures and function pointers for x86-64 support #99

Conversation

magnalunar
Copy link
Contributor

Fixed:

  • Fixed issue with locating CLC_CmdKeyValues constructor on Windows x86/x86_64 and Linux x86/x86_64
  • Fixed issue with locating SVC_CmdKeyValues constructor on Windows x86/x86_64 and Linux x86_64
  • Fixed issue with locating SVC_CreateStringTable constructor on Windows x86/x86_64
  • Fixed issue with locating Steam3Server on Linux x86_64 (64bit broken gm_sourcenet#62)

Improvements:

  • Added new signature for the CLC_CmdKeyValues constructor for Linux x86_64
  • Added new signature for the SVC_CmdKeyValues constructor for Linux x86_64
  • Added new signature for the SVC_CreateStringTable constructor for Linux x86_64
  • Updated signatures for the CLC_CmdKeyValues constructor for Windows x86/x86_64
  • Updated signatures for the SVC_CmdKeyValues constructor for Windows x86/x86_64
  • Updated signatures for the SVC_CreateStringTable constructor for Windows x86/x86_64
  • Updated signature for Steam3Server for Linux x86_64

Test results with gm_sourcenet:

Platform Architecture Result
Windows x86 Passed
Windows x86_64 Passed
Linux x86 Passed
Linux x86_64 Passed

@danielga danielga force-pushed the x86-64-support-sourcesdk branch 9 times, most recently from 4f339ee to 16c029d Compare October 15, 2023 22:20
@danielga danielga self-assigned this Feb 22, 2024
@danielga danielga self-requested a review February 22, 2024 22:45
@danielga
Copy link
Owner

Is anything still applicable? Most of what survived time (in the attached patch), seems to be non specific to the x86-64 branch, and is either not up to date or can be applied to the master branch.

From 048511e1a050247f6d8c40944e9565adadeb8c70 Mon Sep 17 00:00:00 2001
From: MagnaLunar <[email protected]>
Date: Tue, 1 Aug 2023 19:46:22 +0300
Subject: [PATCH] Added symbols for CLC_CmdKeyValues, SVC_CreateStringTable and
 SVC_CmdKeyValues constructors

Updated and added new signatures
Improved function pointers
Format file
---
 helpers_extended/source/FunctionPointers.cpp | 23 +++++++++++++-
 helpers_extended/source/Symbols.cpp          | 32 +++++++++++++++-----
 2 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/helpers_extended/source/FunctionPointers.cpp b/helpers_extended/source/FunctionPointers.cpp
index f49f0f2..cee6f0d 100644
--- a/helpers_extended/source/FunctionPointers.cpp
+++ b/helpers_extended/source/FunctionPointers.cpp
@@ -110,10 +110,12 @@ namespace FunctionPointers
 		if( func_pointer == nullptr )
 		{
 			SourceSDK::FactoryLoader engine_loader( "engine" );
+
 			// we use a starting point for sigscan because, on Linux, CBaseClient::ConnectionStart
 			// and CBaseClientState::ConnectionStart have the same signature
 			// this code expects CBaseClient::ConnectionStart to appear before
 			// CBaseClientState::ConnectionStart
+
 			func_pointer = ResolveSymbols<CBaseClientState_ConnectionStart_t>(
 				engine_loader, Symbols::CBaseClientState_ConnectionStart,
 				reinterpret_cast<const uint8_t *>( CBaseClient_ConnectionStart( ) ) + 16
@@ -132,6 +134,19 @@ namespace FunctionPointers
 			func_pointer = ResolveSymbols<CLC_CmdKeyValues_Constructor_t>(
 				engine_loader, Symbols::CLC_CmdKeyValues_Constructor
 			);
+
+			// we use an offset for the function pointer because, on Linux, Base_CmdKeyValues::Base_CmdKeyValues
+			// and CLC_CmdKeyValues::CLC_CmdKeyValues have the same signature
+			// this code adds the necessary offset to locate CLC_CmdKeyValues::CLC_CmdKeyValues
+
+#if defined SYSTEM_LINUX && defined ARCHITECTURE_X86_64
+
+			const uint8_t *tmp_func_pointer = reinterpret_cast<const uint8_t *>( func_pointer ) + 32;
+
+			func_pointer = reinterpret_cast<CLC_CmdKeyValues_Constructor_t>( tmp_func_pointer );
+
+#endif
+
 		}
 
 		return func_pointer;
@@ -143,9 +158,13 @@ namespace FunctionPointers
 		if( func_pointer == nullptr )
 		{
 			SourceSDK::FactoryLoader engine_loader( "engine" );
+
+			// we use a starting point for sigscan because SVC_CmdKeyValues::SVC_CmdKeyValues
+			// appears before SVC_CreateStringTable::SVC_CreateStringTable
+
 			func_pointer = ResolveSymbols<SVC_CreateStringTable_Constructor_t>(
 				engine_loader, Symbols::SVC_CreateStringTable_Constructor,
-				reinterpret_cast<const uint8_t *>( CBaseClientState_ConnectionStart( ) ) + 16
+				reinterpret_cast<const uint8_t *>( SVC_CmdKeyValues_Constructor( ) ) + 16
 			);
 		}
 
@@ -158,10 +177,12 @@ namespace FunctionPointers
 		if( func_pointer == nullptr )
 		{
 			SourceSDK::FactoryLoader engine_loader( "engine" );
+
 			// we use a starting point for sigscan because SVC_CmdKeyValues::SVC_CmdKeyValues
 			// and CLC_CmdKeyValues::CLC_CmdKeyValues have the same signature
 			// this code expects CLC_CmdKeyValues::CLC_CmdKeyValues to appear before
 			// SVC_CmdKeyValues::SVC_CmdKeyValues
+
 			func_pointer = ResolveSymbols<SVC_CmdKeyValues_Constructor_t>(
 				engine_loader, Symbols::SVC_CmdKeyValues_Constructor,
 				reinterpret_cast<const uint8_t *>( CLC_CmdKeyValues_Constructor( ) ) + 16
diff --git a/helpers_extended/source/Symbols.cpp b/helpers_extended/source/Symbols.cpp
index 20b61df..192d17d 100644
--- a/helpers_extended/source/Symbols.cpp
+++ b/helpers_extended/source/Symbols.cpp
@@ -35,11 +35,17 @@ namespace Symbols
 		Symbol::FromName( "?ConnectionStart@CBaseClientState@@UEAAXPEAVINetChannel@@@Z" )
 	};
 
-	const std::vector<Symbol> CLC_CmdKeyValues_Constructor = { };
+	const std::vector<Symbol> CLC_CmdKeyValues_Constructor = {
+		Symbol::FromSignature( "\x48\x8D\x05\x2A\x2A\x2A\x2A\xC6\x41\x08\x01\x48\x89\x01\x48\x8B\xC1" )
+	};
 
-	const std::vector<Symbol> SVC_CreateStringTable_Constructor = { };
+	const std::vector<Symbol> SVC_CreateStringTable_Constructor = {
+		Symbol::FromSignature( "\x40\x53\x48\x83\xEC\x20\x48\x8B\xD9\xC6\x41\x08\x01\x33\xC9\x48\x8D\x05\x2A\x2A\x2A\x2A\x48\x89\x4B\x10" )
+	};
 
-	const std::vector<Symbol> SVC_CmdKeyValues_Constructor = { };
+	const std::vector<Symbol> SVC_CmdKeyValues_Constructor = {
+		Symbol::FromSignature( "\x48\x8D\x05\x2A\x2A\x2A\x2A\xC6\x41\x08\x01\x48\x89\x01\x48\x8B\xC1" )
+	};
 
 	const std::vector<Symbol> CBaseServer_RecalculateTags = {
 		Symbol::FromName( "?RecalculateTags@CBaseServer@@QEAAXXZ" )
@@ -120,15 +126,15 @@ namespace Symbols
 	};
 
 	const std::vector<Symbol> CLC_CmdKeyValues_Constructor = {
-		Symbol::FromSignature( "\x55\x8B\xEC\x8B\x45\x2A\x89\x41\x2A\x8B\xC1\xC6\x41\x2A\x01\xC7\x41\x2A\x00\x00\x00\x00\xC7\x01\x2A\x2A\x2A\x2A\x5D\xC2\x04\x00" )
+		Symbol::FromSignature( "\x55\x8B\xEC\x8B\x45\x08\x89\x41\x0C\x8B\xC1\xC6\x41\x04\x01\xC7\x41\x08\x00\x00\x00\x00\xC7\x01\x2A\x2A\x2A\x2A\x5D\xC2\x04\x00" )
 	};
 
 	const std::vector<Symbol> SVC_CreateStringTable_Constructor = {
-		Symbol::FromSignature( "\x56\x8B\xF1\x8D\x4E\x2A\xC6\x46\x2A\x01" )
+		Symbol::FromSignature( "\x56\x8B\xF1\xC6\x46\x04\x01\x8D\x4E\x54\xC7\x46\x08\x00\x00\x00\x00\xC7\x06\x2A\x2A\x2A\x2A\xC6\x46\x34\x00" )
 	};
 
 	const std::vector<Symbol> SVC_CmdKeyValues_Constructor = {
-		Symbol::FromSignature( "\x55\x8B\xEC\x8B\x45\x2A\x89\x41\x2A\x8B\xC1\xC6\x41\x2A\x01\xC7\x41\x2A\x00\x00\x00\x00\xC7\x01\x2A\x2A\x2A\x2A\x5D\xC2\x04\x00" )
+		Symbol::FromSignature( "\x55\x8B\xEC\x8B\x45\x08\x89\x41\x0C\x8B\xC1\xC6\x41\x04\x01\xC7\x41\x08\x00\x00\x00\x00\xC7\x01\x2A\x2A\x2A\x2A\x5D\xC2\x04\x00" )
 	};
 
 	const std::vector<Symbol> CBaseServer_RecalculateTags = {
@@ -264,6 +270,10 @@ namespace Symbols
 
 		Symbol::FromSignature( "\x55\x89\xE5\x8B\x45\x2A\x8B\x55\x2A\xC6\x40\x2A\x01\xC7\x40\x2A\x00\x00\x00\x00\x89\x50\x2A\xC7\x00\x2A\x2A\x2A\x2A\x5D\xC3" )
 
+#elif defined ARCHITECTURE_X86_64
+
+		Symbol::FromSignature( "\x55\x48\x8D\x05\x2A\x2A\x2A\x2A\xC6\x47\x2A\x2A\x48\x89\xE5\x48\xC7\x47\x2A\x2A\x2A\x2A\x2A\x48\x89\x77\x2A\x48\x89\x07\x5D\xC3" )
+
 #endif
 
 	};
@@ -275,6 +285,10 @@ namespace Symbols
 
 		Symbol::FromSignature( "\x55\x89\xE5\x53\x83\xEC\x14\x8B\x5D\x2A\x8D\x43\x2A\xC6\x43\x2A\x01" )
 
+#elif defined ARCHITECTURE_X86_64
+
+		Symbol::FromSignature( "\x55\x48\x8D\x05\x2A\x2A\x2A\x2A\x48\x89\xE5\x53\x48\x89\xFB\x48\x8D\xBF\x2A\x2A\x2A\x2A\x48\x83\xEC\x2A\xC6\x47" )
+
 #endif
 
 	};
@@ -286,6 +300,10 @@ namespace Symbols
 
 		Symbol::FromSignature( "\x55\x89\xE5\x8B\x45\x2A\x8B\x55\x2A\xC6\x40\x2A\x01\xC7\x40\x2A\x00\x00\x00\x00\x89\x50\x2A\xC7\x00\x2A\x2A\x2A\x2A\x5D\xC3" )
 
+#elif defined ARCHITECTURE_X86_64
+
+		Symbol::FromSignature( "\x55\x48\x8D\x05\x2A\x2A\x2A\x2A\xC6\x47\x2A\x2A\x48\x89\xE5\x48\xC7\x47\x2A\x2A\x2A\x2A\x2A\x48\x89\x77\x2A\x48\x89\x07\x5D\xC3" )
+
 #endif
 
 	};
@@ -371,7 +389,7 @@ namespace Symbols
 #elif defined ARCHITECTURE_X86_64
 
 	const Symbol Steam3Server =
-		Symbol::FromSignature( "\x55\x48\x8D\x05\x2A\x2A\x2A\x2A\x48\x89\xE5\x5D\xC3\x90\x66\x90\x55\x31\xC0\xB9\x09\x00\x00\x00\x48\x89\xE5\x41\x57\xBE" );
+		Symbol::FromSignature( "\x55\x48\x8D\x05\x2A\x2A\x2A\x2A\x48\x89\xE5\x5D\xC3\x2A\x2A\x2A\x55\x31\xC0\xB9\x2A\x2A\x2A\x2A\x48\x89\xE5\x41\x57\xBE" );
 
 #endif
 
-- 
2.43.0.windows.1

@magnalunar
Copy link
Contributor Author

Yes, some things have been changed and are no longer up to date. Therefore, I'm updating my fork from the upstream and closing this pull request, as the important changes have already been merged.

@magnalunar magnalunar closed this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants