-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanAPP.cpp
89 lines (89 loc) · 2.03 KB
/
cleanAPP.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "cleanAPP.h"
void GetRamX( uHandle fHandle, u64 fAddress, void* fBuffer, u32 fSize )
{
#ifdef __WXMSW__
ReadProcessMemory( fHandle, ( void* )fAddress, fBuffer, fSize, NULL );
#endif
}
void SetRamX( uHandle fHandle, u64 fAddress, void* fBuffer, u32 fSize )
{
#ifdef __WXMSW__
WriteProcessMemory( fHandle, ( void* )fAddress, fBuffer, fSize, NULL );
#endif
}
#ifdef __WXMSW__
PROCESSENTRY32 GetAppMSW( DWORD appID )
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof( PROCESSENTRY32 );
HANDLE shot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
Process32First( shot, &pe32 );
do {
if ( pe32.th32ProcessID == appID )
{
break;
}
} while ( Process32Next( shot, &pe32 ) );
return pe32;
}
#endif
bool LaunchExe( xStr path )
{
xStr text = wxT( '"' ) + path + wxT( '"' );
#ifdef __WXMSW__
return ( WinExec( text.mb_str().data(), SW_HIDE ) );
#else
return false;
#endif
}
uHandle GetAppHandle( const xStr appExe )
{
uHandle ah = NULL;
#ifdef __WXMSW__
xStr exe;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof( PROCESSENTRY32 );
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 DelAppHandle( uHandle &fHandle )
{
#ifdef __WXMSW__
CloseHandle( fHandle );
#else
fHandle = NULL;
#endif
}
xStr GetAppExe( DWORD appID )
{
xStr text;
#ifdef __WXMSW__
PROCESSENTRY32 pe32 = GetAppMSW( appID );
text.Printf( wxT( "%s" ), pe32.szExeFile );
#endif
return text;
}
bool GetAppSize( uHandle ah, u64 &size )
{
bool worked = false;
size = 0u;
#ifdef __WXMSW__
PROCESS_MEMORY_COUNTERS* pmc = new PROCESS_MEMORY_COUNTERS;
if ( GetProcessMemoryInfo( ah, pmc, ( DWORD )sizeof( PROCESS_MEMORY_COUNTERS ) ) )
{
size = pmc->PagefileUsage;
worked = true;
}
#endif
return worked;
}