Skip to content

Commit

Permalink
Add error message for using wrong architecture NetHook2
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphyrus authored and psychonic committed Aug 19, 2023
1 parent db86e24 commit f5f2da7
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Resources/NetHook2/NetHook2/injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase;

int FindSteamProcessID();
BOOL FindProcessByName(const char * szProcessName, int * piFirstProcessID, int * piNumProcesses);
BOOL ProcessIsDifferentArchitecture(const int iProcessID);
BOOL ProcessHasModuleLoaded(const int iProcessID, const char * szModuleName, bool bPartialMatchFromEnd);
BOOL TryParseInt(const char * szStringIn, int * pIntOut);
BOOL SelfInjectIntoSteam(const HWND hWindow, const int iSteamProcessID, const char * szNetHookDllPath);
Expand Down Expand Up @@ -73,6 +74,7 @@ typedef enum {
k_ESteamProcessSearchErrorCouldNotFindProcessWithSuppliedName,
k_ESteamProcessSearchErrorFoundMultipleProcessesWithSuppliedName,
k_ESteamProcessSearchErrorTargetProcessDoesNotHaveSteamClientDllLoaded,
k_ESteamProcessSearchErrorTargetDifferentArchitecture,

k_ESteamProcessSearchErrorMax,
} ESteamProcessSearchError;
Expand All @@ -93,6 +95,9 @@ const char * NameFromESteamProcessSearchError( ESteamProcessSearchError eValue )
case k_ESteamProcessSearchErrorTargetProcessDoesNotHaveSteamClientDllLoaded:
return "Invalid process: Target process does not have steamclient.dll loaded.";

case k_ESteamProcessSearchErrorTargetDifferentArchitecture:
return "Invalid process: Target process is not the same architecture as NetHook2.";

default:
return "Unknown error.";
}
Expand Down Expand Up @@ -120,8 +125,12 @@ ESteamProcessSearchError GetSteamProcessID( HWND hWindow, LPSTR lpszCommandLine,
return k_ESteamProcessSearchErrorFoundMultipleProcessesWithSuppliedName;
}
}

if ( !ProcessHasModuleLoaded( *piSteamProcessID, STEAMCLIENT_DLL, /* bPartialMatchFromEnd */ true ) )

if ( ProcessIsDifferentArchitecture( *piSteamProcessID ) )
{
return k_ESteamProcessSearchErrorTargetDifferentArchitecture;
}
else if ( !ProcessHasModuleLoaded( *piSteamProcessID, STEAMCLIENT_DLL, /* bPartialMatchFromEnd */ true ) )
{
return k_ESteamProcessSearchErrorTargetProcessDoesNotHaveSteamClientDllLoaded;
}
Expand Down Expand Up @@ -286,6 +295,20 @@ BOOL FindProcessByName(const char * szProcessName, int * piFirstProcessID, int *
return iNumProcessesFound > 0;
}

BOOL ProcessIsDifferentArchitecture(const int iProcessID)
{
SafeHandle hProcess = MakeSafeHandle(OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, iProcessID));
if (hProcess != NULL)
{
USHORT processMachine, ownProcessMachine;

if (IsWow64Process2(hProcess.get(), &processMachine, NULL) && IsWow64Process2(GetCurrentProcess(), &ownProcessMachine, NULL)) {
return processMachine != ownProcessMachine;
}
}
return false;
}

BOOL ProcessHasModuleLoaded(const int iProcessID, const char * szModuleName, bool bPartialMatchFromEnd)
{
SafeHandle hProcess = MakeSafeHandle(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, iProcessID));
Expand Down

0 comments on commit f5f2da7

Please sign in to comment.