1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
bool LaunchExe( xStr path )
{
#ifdef __WXMSW__
STARTUPINFO si;
PROCESS_INFORMATION pi;
return ( CreateProcess( path.data(), ( WCHAR* )"",
NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) );
#else
return false;
#endif
}
uHandle GetAppHandle( const xStr appExe )
{
uHandle ah = NULL;
#ifdef __WXMSW__
xStr exe;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof( pe32 );
HANDLE shot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
Process32First( shot, &pe32 );
do {
exe.Printf( wxT( "%s" ), pe32.szExeFile );
if ( exe.CmpNoCase( appExe ) == 0 ) {
ah = OpenProcess( PROCESS_ALL_ACCESS,
FALSE, pe32.th32ProcessID );
break;
}
} while ( Process32Next( shot, &pe32 ) );
#endif
return ah;
}
void G::NewHook( void )
{
++isHooked;
if ( isHooked > 1 ) return;
xStr binPath = binPath_TXT->GetValue();
xStr binFile = binBind_TXT->GetValue();
xStr text = binPath + gGetSlash() + binFile;
if ( hookApp )
{
appHandle = GetAppHandle( binFile );
if ( appHandle == NULL )
{
if ( LaunchExe( text ) )
appHandle = GetAppHandle( binFile );
}
if ( appHandle == NULL ) --isHooked;
}
else
{
if ( !wxFileExists( text ) ) --isHooked;
else bin_BF.Open( text );
}
}
|