Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Loading a driver

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Mar 29, 2009 9:12 pm    Post subject: [C++] Loading a driver Reply with quote

Hi, I've just started learning how to make drivers and I made this driver loader. But it isn't working all the times and I can't find anything that's wrong with it. Also does anyone know a good driver tutorial? So far I can only print "Hello World".. :p.

Code:
#include <windows.h>
#include <stdio.h>

WCHAR szDriverName[256];
SC_HANDLE schManager, schCreate;

BOOL LoadAndStartDriver(LPCTSTR lpDriverName, LPCTSTR lpPath)
{
   schManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
   if(schManager != NULL)
   {
      wcscat_s(szDriverName, lpDriverName);
      wcscat_s(szDriverName, L".sys");
      schCreate = CreateService(schManager, szDriverName, lpDriverName, SERVICE_ALL_ACCESS,
         SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, lpPath, NULL, NULL, NULL, NULL, NULL);
      
      if(!StartService(schCreate, 0, NULL))
      {
         if(GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
         {
            wprintf(L"Driver already running!");
            return FALSE;
         }
      }
   }
   return TRUE;
}

void UnloadDriver()
{
   SERVICE_STATUS Status;

   DeleteService(schCreate);
   ControlService(schCreate, SERVICE_CONTROL_STOP, &Status);
   CloseServiceHandle(schCreate);
   CloseServiceHandle(schManager);
}

int wmain()
{
   LoadAndStartDriver(L"Driver", L"C:\\Driver.sys");
   Sleep(5000);
   UnloadDriver();
}
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Mon Mar 30, 2009 12:08 am    Post subject: Reply with quote

Why are you first deleting the service then trying to control it?
And i recommend on reading "Rootkits: Subverting the windows kernel", which i have read myself.
Back to top
View user's profile Send private message MSN Messenger
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Mon Mar 30, 2009 8:45 am    Post subject: Reply with quote

Zerith wrote:
Why are you first deleting the service then trying to control it?
And i recommend on reading "Rootkits: Subverting the windows kernel", which i have read myself.
Didn't notice I deleted the service before ControlService. And I found out why it stoped working, for some reason I couldnt use the name "Driver" :s.

I downloaded "Rootkits: Subverting the windows kernel" and will start reading it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites