2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-15 06:12:54 +00:00

Include new hook for newer Steam versions

This commit is contained in:
Peter Repukat 2017-09-24 19:39:34 +02:00
parent e07a443205
commit e77529137d
2 changed files with 88 additions and 64 deletions

View File

@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#include "EnforceBindings.h"
#include <vector>
//stuff for finding the function as well as the injected code
//should probably be moved somewhere else
DWORD address;
DWORD address = NULL;
DWORD JMPBack;
int32_t currentBindings;
const int32_t desktopBindingsID = 413080; //desktop_config appid
@ -26,29 +27,27 @@ const int32_t steamChordBindingsID = 443510; //steam_chord_config appid
int32_t enforceBindingsID = 413080;
char originalBytes_V0[] = "\x8B\x45\x0c\x57\x8B\x7D\x08\x3D\x76\xC4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V0)
std::string originalBytes_V0 = "\x8B\x45\x0c\x57\x8B\x7D\x08\x3D\x76\xC4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V0)
/* ==
mov eax, dword ptr ss : [ebp + 0xc] //appId of bindings to be switched gets moved into eax register
push edi //part of original steam code
mov edi, dword ptr ss : [ebp + 0x8] //part of original steam code
cmp eax, 0x6C476 //part of original steam code - checks if bindings to be set are steamchord bindings
*/
char mask_V0[] = "xxxxxxxxxxxx"; //mask for searching
int32_t sigLen_V0 = 12;
std::string mask_V0 = "xxxxxxxxxxxx"; //mask for searching
char originalBytes_V1[] = "\x8B\x45\x0C\x3D\x76\xC4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V1)
std::string originalBytes_V1 = "\x8B\x45\x0C\x3D\x76\xC4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V1)
/* ==
mov eax,dword ptr ss:[ebp + 0xC] //appId of bindings to be switched gets moved into eax register
cmp eax,6C476 //part of original steam code - checks if bindings to be set are steamchord bindings
*/
char mask_V1[] = "xxxxxxxx"; //mask for searching
int32_t sigLen_V1 = 8;
std::string mask_V1 = "xxxxxxxx"; //mask for searching
char originalBytes_V2[] = "\x8B\x4D\x0C\x53\x8D\x9f\x2a\x03\x00\x00\x8D\x1C\x9E\x81\xF9\x76\xc4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V2)
std::string originalBytes_V2 = "\x8B\x4D\x0C\x53\x8D\x9f\x2a\x03\x00\x00\x8D\x1C\x9E\x81\xF9\x76\xc4\x06\x00"; //original assembly code of steamclient.dll that we want to hook (V2)
/* ==
mov ecx,dword ptr ss:[ebp+C] //appId of bindings to be switched gets moved into ecx register
push ebx //part of original steam code
@ -56,25 +55,47 @@ lea ebx,dword ptr ds:[edi+32A] //part of original steam code
lea ebx,dword ptr ds:[esi+ebx*4] //part of original steam code
cmp ecx,6C476 //part of original steam code - checks if bindings to be set are steamchord bindings
*/
char mask_V2[] = "xxxxxxxxxxxxxxxxxxx"; //mask for searching
std::string mask_V2 = "xxxxxxxxxxxxxxxxxxx"; //mask for searching
int32_t sigLen_V2 = 19;
char originalBytes_V3[] = "\x8D\x8e\x38\x0c\x00\x00\x8B\x45\x0C"; //original assembly code of steamclient.dll that we want to hook (V2)
std::string originalBytes_V3 = "\x8D\x8e\x38\x0c\x00\x00\x8B\x45\x0C"; //original assembly code of steamclient.dll that we want to hook (V2)
/* ==
lea ecx,dword ptr ds:[esi+C38] //part of original steam code
mov eax,dword ptr ss:[ebp+C] //appId of bindings to be switched gets moved into ecx register
*/
char mask_V3[] = "xxxxxxxxx"; //mask for searching
int32_t sigLen_V3 = 9;
std::string mask_V3 = "xxxxxxxxx"; //mask for searching
std::string originalBytes_V4 = "\x8B\x45\x0C\x89\x45\xF4\x8D\x45\xF0\x50\x89\x7D\xF0"; //original assembly code of steamclient.dll that we want to hook (V2)
/* ==
mov eax,dword ptr ss:[ebp+C] //appId of bindings to be switched gets moved into eax register
mov dword ptr ss:[ebp-C],eax
lea eax,dword ptr ss:[ebp-10]
push eax
mov dword ptr ss:[ebp-10],edi
*/
std::string mask_V4 = "xxxxxxxxxxxxx"; //mask for searching
int patchversion = 0;
std::vector<std::string> masks = {
mask_V0,
mask_V1,
mask_V2,
mask_V3,
mask_V4
};
std::vector<std::string> sig_bytes = {
originalBytes_V0,
originalBytes_V1,
originalBytes_V2,
originalBytes_V3,
originalBytes_V4
};
////////////////////////////////// CODE ///////////////////////////////////////////
__declspec(naked) void enforceBindingsHookFn_V0()
{
__asm
@ -206,66 +227,69 @@ __declspec(naked) void enforceBindingsHookFn_V3()
//\\\
__declspec(naked) void enforceBindingsHookFn_V4()
{
__asm
{
mov eax, dword ptr ss : [ebp+0xC] //appId of bindings to be switched gets moved into ecx register
mov currentBindings, eax //move into "currentBindings" variable
}
if (currentBindings != desktopBindingsID //if the current bindings aren't desktop, big picture, or steam-chord bindings
&& currentBindings != bigPictureBindingsID //they have to be our game bindings
&& currentBindings != steamChordBindingsID) //we can grab them here, because bindings switch right after we have injected and the target changes focused window
{
enforceBindingsID = currentBindings;
}
if (currentBindings == desktopBindingsID) //if steam wants to set desktop-bindings
{
__asm
{
mov eax, enforceBindingsID //move appid of bindings to enforce into ecx register
}
}
__asm
{
mov dword ptr ss : [ebp - 0xC], eax
lea eax, dword ptr ss : [ebp - 0x10]
push eax
mov dword ptr ss : [ebp - 0x10], edi
jmp[JMPBack] //jump back and continiue with original steam function
}
}
//\\\
std::vector<void(*)()> hook_funs = {
enforceBindingsHookFn_V0,
enforceBindingsHookFn_V1,
enforceBindingsHookFn_V2,
enforceBindingsHookFn_V3,
enforceBindingsHookFn_V4,
};
void EnforceBindings::patchBytes()
{
address = FindPattern("steamclient.dll", originalBytes_V0, mask_V0);
if (address != NULL)
for (int i = 0; i < sig_bytes.size(); i++)
{
patchversion = 0;
JMPBack = address + sigLen_V0; //12 size of pattern/mask == patched instructions
PlaceJMP((BYTE*)address, (DWORD)enforceBindingsHookFn_V0, sigLen_V0);
} else {
patchversion = 1;
address = FindPattern("steamclient.dll", originalBytes_V1, mask_V1);
address = FindPattern("steamclient.dll", sig_bytes[i].c_str(), masks[i].c_str());
if (address != NULL)
{
JMPBack = address + sigLen_V1; //8 size of pattern/mask == patched instructions
PlaceJMP((BYTE*)address, (DWORD)enforceBindingsHookFn_V1, sigLen_V1);
} else {
patchversion = 2;
address = FindPattern("steamclient.dll", originalBytes_V2, mask_V2);
if (address != NULL)
{
JMPBack = address + sigLen_V2; //8 size of pattern/mask == patched instructions
PlaceJMP((BYTE*)address, (DWORD)enforceBindingsHookFn_V2, sigLen_V2);
}
else
{
patchversion = 3;
address = FindPattern("steamclient.dll", originalBytes_V3, mask_V3);
if (address != NULL)
{
JMPBack = address + sigLen_V3; //8 size of pattern/mask == patched instructions
PlaceJMP((BYTE*)address, (DWORD)enforceBindingsHookFn_V3, sigLen_V3);
}
}
patchversion = i;
JMPBack = address + sig_bytes[i].length();
PlaceJMP((BYTE*)address, (DWORD)hook_funs[i], sig_bytes[i].length());
return;
}
}
}
void EnforceBindings::Unpatch()
{
if (address == NULL)
if (address != NULL)
{
return;
} else {
switch (patchversion)
{
case 0:
RestoreBytes((BYTE*)address, (BYTE*)originalBytes_V0, sigLen_V0);
break;
case 1:
RestoreBytes((BYTE*)address, (BYTE*)originalBytes_V1, sigLen_V1);
break;
case 2:
RestoreBytes((BYTE*)address, (BYTE*)originalBytes_V2, sigLen_V2);
break;
case 3:
RestoreBytes((BYTE*)address, (BYTE*)originalBytes_V3, sigLen_V3);
break;
}
RestoreBytes((BYTE*)address, (BYTE*)sig_bytes[patchversion].c_str(), sig_bytes[patchversion].length());
}
}
@ -312,7 +336,7 @@ MODULEINFO EnforceBindings::GetModInfo(char * szModule)
}
//returns memory address of given pattern ind given module
DWORD EnforceBindings::FindPattern(char * module, char * pattern, char * mask)
DWORD EnforceBindings::FindPattern(char * module, const char * pattern, const char * mask)
{
MODULEINFO mInfo = GetModInfo(module);
DWORD baseAddr = (DWORD)mInfo.lpBaseOfDll;

View File

@ -34,6 +34,6 @@ private:
static void PlaceJMP(BYTE * Address, DWORD jumpTo, DWORD lenght);
static void RestoreBytes(BYTE *Address, BYTE *original, DWORD lenght);
static MODULEINFO GetModInfo(char *szModule);
static DWORD FindPattern(char *module, char *pattern, char *mask);
static DWORD FindPattern(char *module, const char *pattern, const char *mask);
};