Skip to content

Commit 4d9f4e4

Browse files
committed
Updated detection of incompatible programs
1 parent e803d6f commit 4d9f4e4

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

Client/loader/MainFunctions.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,26 +391,30 @@ void HandleNotUsedMainMenu ( void )
391391
// Check if problem processes are active
392392
struct
393393
{
394-
const char* szFilename;
394+
std::vector<SString> matchTextList;
395395
const char* szProductName;
396396
const char* szTrouble;
397397
} procItems[] = {
398-
{"Evolve", "Evolve", "not-used-menu-evolve"},
399-
{"GbpSv.exe", "GAS Tecnologia - G-Buster Browser Defense", "not-used-menu-gbpsv"}};
398+
{{"\\Evolve"}, "Evolve", "not-used-menu-evolve"},
399+
{{"\\GbpSv.exe", "Diebold\\Warsaw"}, "GAS Tecnologia - G-Buster Browser Defense", "not-used-menu-gbpsv"}};
400400
for (uint i = 0; i < NUMELMS(procItems); i++ )
401401
{
402402
for ( auto processId : MyEnumProcesses( true ) )
403403
{
404-
SString strFilename = GetProcessFilename( processId );
405-
if ( strFilename.BeginsWithI( procItems[i].szFilename ) )
404+
SString strProcessFilename = GetProcessPathFilename(processId);
405+
for (auto strMatchText : procItems[i].matchTextList)
406406
{
407-
SString strMessage = _("Are you having problems running MTA:SA?.\n\nTry disabling the following products for GTA and MTA:");
408-
strMessage += "\n\n";
409-
strMessage += procItems[i].szProductName;
410-
DisplayErrorMessageBox ( strMessage, _E("CL43"), procItems[i].szTrouble );
411-
break;
407+
if (strProcessFilename.ContainsI(strMatchText))
408+
{
409+
SString strMessage = _("Are you having problems running MTA:SA?.\n\nTry disabling the following products for GTA and MTA:");
410+
strMessage += "\n\n";
411+
strMessage += procItems[i].szProductName;
412+
DisplayErrorMessageBox ( strMessage, _E("CL43"), procItems[i].szTrouble );
413+
goto done;
414+
}
412415
}
413416
}
417+
done:;
414418
}
415419
}
416420

Client/loader/StdInc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <Psapi.h>
1616
#include <time.h>
1717
#include <fstream>
18+
#include <winternl.h>
1819

1920
#include "..\sdk\core\CLocalizationInterface.h"
2021
extern CLocalizationInterface* g_pLocalization;

Client/loader/Utils.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ WString devicePathToWin32Path ( const WString& strDevicePath )
349349
}
350350

351351

352-
typedef WINBASEAPI BOOL (WINAPI *LPFN_QueryFullProcessImageNameW)(__in HANDLE hProcess, __in DWORD dwFlags, __out_ecount_part(*lpdwSize, *lpdwSize) LPWSTR lpExeName, __inout PDWORD lpdwSize);
353-
354-
355352
///////////////////////////////////////////////////////////////////////////
356353
//
357354
// GetProcessPathFilename
@@ -361,17 +358,7 @@ typedef WINBASEAPI BOOL (WINAPI *LPFN_QueryFullProcessImageNameW)(__in HANDLE hP
361358
///////////////////////////////////////////////////////////////////////////
362359
SString GetProcessPathFilename ( DWORD processID )
363360
{
364-
static LPFN_QueryFullProcessImageNameW fnQueryFullProcessImageNameW = NULL;
365-
static bool bDoneGetProcAddress = false;
366-
if ( !bDoneGetProcAddress )
367-
{
368-
// Find 'QueryFullProcessImageNameA'
369-
bDoneGetProcAddress = true;
370-
HMODULE hModule = GetModuleHandle ( "Kernel32.dll" );
371-
fnQueryFullProcessImageNameW = static_cast < LPFN_QueryFullProcessImageNameW > ( static_cast < PVOID > ( GetProcAddress( hModule, "QueryFullProcessImageNameW" ) ) );
372-
}
373-
374-
if ( fnQueryFullProcessImageNameW )
361+
if ( _QueryFullProcessImageNameW )
375362
{
376363
for ( int i = 0 ; i < 2 ; i++ )
377364
{
@@ -380,7 +367,7 @@ SString GetProcessPathFilename ( DWORD processID )
380367
{
381368
WCHAR szProcessName[MAX_PATH] = L"";
382369
DWORD dwSize = NUMELMS(szProcessName);
383-
DWORD bOk = fnQueryFullProcessImageNameW ( hProcess, 0, szProcessName, &dwSize );
370+
DWORD bOk = _QueryFullProcessImageNameW ( hProcess, 0, szProcessName, &dwSize );
384371
CloseHandle( hProcess );
385372
if ( bOk )
386373
{
@@ -433,6 +420,23 @@ SString GetProcessPathFilename ( DWORD processID )
433420
}
434421
}
435422

423+
if ( _NtQuerySystemInformation )
424+
{
425+
SYSTEM_PROCESS_IMAGE_NAME_INFORMATION info;
426+
WCHAR szProcessName[MAX_PATH] = L"";
427+
info.ProcessId = (HANDLE)processID;
428+
info.ImageName.Length = 0;
429+
info.ImageName.MaximumLength = sizeof(szProcessName);
430+
info.ImageName.Buffer = szProcessName;
431+
432+
NTSTATUS status = _NtQuerySystemInformation(SystemProcessImageNameInformation, &info, sizeof(info), NULL);
433+
if (NT_SUCCESS(status))
434+
{
435+
WString strProcessName = WStringX(info.ImageName.Buffer, info.ImageName.Length / 2);
436+
return ToUTF8(devicePathToWin32Path(strProcessName));
437+
}
438+
}
439+
436440
return "";
437441
}
438442

@@ -1260,7 +1264,7 @@ Return Value:
12601264
void RelaunchAsAdmin(const SString& strCmdLine, const SString& strReason)
12611265
{
12621266
HideSplash();
1263-
AddReportLog(7115, SString("Loader - Request to elevate privilages (%s)", *strReason));
1267+
AddReportLog(7115, SString("Loader - Request to elevate privileges (%s)", *strReason));
12641268
MessageBoxUTF8(NULL, SString ( _("MTA:SA needs Administrator access for the following task:\n\n '%s'\n\nPlease confirm in the next window."), *strReason), "Multi Theft Auto: San Andreas", MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
12651269
ReleaseSingleInstanceMutex();
12661270
ShellExecuteNonBlocking("runas", PathJoin(GetMTASAPath(), MTA_EXE_NAME), strCmdLine);

Client/loader/Utils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ class CStuckProcessDetector
201201
CElapsedTime m_StuckTimer;
202202
};
203203

204+
// For NtQuerySystemInformation
205+
#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
206+
#define SystemProcessImageNameInformation ((SYSTEM_INFORMATION_CLASS)88)
207+
typedef struct _SYSTEM_PROCESS_IMAGE_NAME_INFORMATION
208+
{
209+
HANDLE ProcessId;
210+
UNICODE_STRING ImageName;
211+
} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION, *PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION;
204212

205213
#undef CREATE_SUSPENDED
206214
#define CREATE_SUSPENDED 5
@@ -242,6 +250,8 @@ class CStuckProcessDetector
242250
#define _InitializeProcThreadAttributeList __InitializeProcThreadAttributeList()
243251
#define _DeleteProcThreadAttributeList __DeleteProcThreadAttributeList()
244252
#define _UpdateProcThreadAttribute __UpdateProcThreadAttribute()
253+
#define _QueryFullProcessImageNameW __QueryFullProcessImageNameW()
254+
#define _NtQuerySystemInformation __NtQuerySystemInformation()
245255

246256
DEFFUNCTION( "kernel32", Virt,ualAll,ocEx )
247257
DEFFUNCTION( "kernel32", Virt,ualPro,tectEx )
@@ -254,5 +264,7 @@ class CStuckProcessDetector
254264
DEFFUNCTION( "kernel32", Initiali,zeProcT,hreadAttributeList )
255265
DEFFUNCTION( "kernel32", Dele,teProcT,hreadAttributeList )
256266
DEFFUNCTION( "kernel32", Upda,teProcT,hreadAttribute )
267+
DEFFUNCTION( "kernel32", QueryFullProcessImageNam,e,W )
268+
DEFFUNCTION( "ntdll", NtQuerySystemInformati,o,n )
257269

258270
#endif

0 commit comments

Comments
 (0)