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 


Improved driver loader, win32 with gui and driver selection

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Feb 18, 2008 5:52 pm    Post subject: Improved driver loader, win32 with gui and driver selection Reply with quote

Code and project attached.

I also attached dbgview so you can see my debugprint messages to prove that it works. Make sure you are capturing kernel messages in it.

Updated: cleaned up source and added a STATIC
Commented source.

Newest update is DriverGui1.1rar



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.



Last edited by HomerSexual on Mon Feb 18, 2008 6:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Feb 18, 2008 6:06 pm    Post subject: Reply with quote

nice, but talk about messy coding lol.
_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Feb 18, 2008 6:12 pm    Post subject: Reply with quote

Yeah, ill clean it up and reload it.

I was focusing on content and not organization. I'm very good with finding stuff that i've done, organized or messy as hell. It's just my personality. XP
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Feb 18, 2008 8:02 pm    Post subject: Reply with quote

why use an int and hwnd parameter?
and why check the text box's if your uninstalling the driver...
might as well do everything for only the install driver, then just close the handles and stop the service in the uninstall part.

you can just use a bool parameter and keep hWnd a global declaration.


here, i neatened it up like crazy, added a font change loop, and added labels:

Code:
#include <windows.h>
#include <tchar.h>
#define WIN32_LEAN_AND_MEAN

#define ID_DRIVERNAME  101
#define ID_DRIVERDNAME 102
#define ID_PATH        103
#define ID_INSTALL     104
#define ID_STATUS      105
#define ID_UNINSTALL   106
#define ID_LABEL1      107
#define ID_LABEL2      108
#define ID_LABEL3      109
#define ID_BROWSE      110

void Driver( BOOL Install );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

LPWSTR szClassName = L"DriverLoaderClass";
LPWSTR szError     = L"Error";
TCHAR  szDriverName[MAX_PATH];
TCHAR  szDriveDName[MAX_PATH];
TCHAR  szDriverPath[MAX_PATH];
TCHAR  szOpFileName[MAX_PATH];

HWND hWnd, hDrvName, hInstall, hUnInstall, hDrvPath, hBrowse, hStatus, hDrvDName,
    hLabel1, hLabel2, hLabel3;

SC_HANDLE scManager, scService;
SERVICE_STATUS sStatus;

OPENFILENAME openFile;

void Driver( BOOL bInstall )
{
   if ( bInstall )
   {
      if ( GetDlgItemText( hWnd, ID_DRIVERNAME, szDriverName, MAX_PATH ) == NULL )
      {
         MessageBox( hWnd, L"Enter Driver Name", szError, MB_OK | MB_ICONERROR );
         return;
      }
      if ( GetDlgItemText( hWnd, ID_DRIVERDNAME, szDriveDName, MAX_PATH ) == NULL )
      {
         MessageBox( hWnd, L"Enter Display Driver Name", szError, MB_OK | MB_ICONERROR );
         return;
      }
      if ( GetDlgItemText( hWnd, ID_PATH, szDriverPath, MAX_PATH ) == NULL )
      {
         MessageBox( hWnd, L"Choose a .Sys File to Load", szError, MB_OK | MB_ICONERROR );
         return;
      }

      scManager = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE );
      if ( !scManager )
      {
         MessageBox( hWnd, L"Unable to gain access to install driver.", szError, MB_OK | MB_ICONERROR );
         return;
      }
      
      scService = CreateService(
         scManager,
         szDriverName,
         szDriveDName,
         SERVICE_START | DELETE | SERVICE_STOP,
         SERVICE_KERNEL_DRIVER,
         SERVICE_DEMAND_START,
         SERVICE_ERROR_IGNORE,
         szDriverPath,
         NULL,
         NULL,
         NULL,
         NULL,
         NULL );
      if ( !scService )
      {
         MessageBox( hWnd, L"Unable to create service", szError, MB_OK | MB_ICONERROR );
         CloseServiceHandle( scManager );
         CloseServiceHandle( scService );
         return;
      }
      else
      {
         if ( !StartService( scService, NULL, NULL ) )
         {
            MessageBox( hWnd, L"Unable to start the driver", szError, MB_OK | MB_ICONERROR );
            return;
         }
         else
            SetDlgItemText( hWnd, ID_STATUS, L"Status: Driver Installed" );
      }
   }
   else
   {
      ControlService( scService, SERVICE_CONTROL_STOP, &sStatus );
      DeleteService( scService );
      CloseServiceHandle( scService );
      CloseServiceHandle( scManager );
      SetDlgItemText( hWnd, ID_STATUS, L"Status: No Driver Installed" );
   }
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
   switch ( Msg )
   {
   case WM_CLOSE:
      DestroyWindow( hWnd );
      break;
   case WM_DESTROY:
      PostQuitMessage(0);
      break;
   case WM_COMMAND:
      switch( LOWORD(wParam) )
      {
      case ID_INSTALL:
         Driver( TRUE );
         break;
      case ID_UNINSTALL:
         Driver( FALSE );
         break;
      case ID_BROWSE:
         if ( GetOpenFileName( &openFile ) )
            SetDlgItemText( hWnd, ID_PATH, szOpFileName );
      default:
         break;
      }
   default:
      return DefWindowProc( hWnd, Msg, wParam, lParam );
   }
   return 0;
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
   WNDCLASSEX wc;
   MSG Msg;
   HFONT hFont = CreateFont( 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Segoe UI" );

   wc.cbClsExtra    = 0;
   wc.cbSize       = sizeof(WNDCLASSEX);
   wc.cbWndExtra    = 0;
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
   wc.hIcon       = LoadIcon( NULL, IDI_APPLICATION );
   wc.hIconSm       = LoadIcon( NULL, IDI_APPLICATION );
   wc.hInstance    = hInstance;
   wc.lpfnWndProc    = WndProc;
   wc.lpszClassName = szClassName;
   wc.lpszMenuName  = 0;
   wc.style       = 0;

   if ( !RegisterClassEx( &wc ) )
   {
      MessageBox( NULL, L"Unable to Create Class", szError, MB_OK + MB_ICONERROR );
      return 0;
   }

   hWnd       = CreateWindowEx( NULL, szClassName, L"Driver Loader", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
      CW_USEDEFAULT, CW_USEDEFAULT, 305, 205, HWND_DESKTOP, NULL, hInstance, NULL );

   hStatus    = CreateWindowEx( NULL, L"Static", L"Status: No Driver Installed", WS_VISIBLE | WS_CHILD,
      20, 20, 150, 17, hWnd, (HMENU)ID_STATUS, hInstance, NULL );

   hLabel1    = CreateWindowEx( NULL, L"Static", L"Driver Name:", WS_VISIBLE | WS_CHILD,
      20, 50, 80, 17, hWnd, (HMENU)ID_LABEL1, hInstance, NULL );
   
   hLabel2    = CreateWindowEx( NULL, L"Static", L"Display Name:", WS_VISIBLE | WS_CHILD,
      20, 70, 80, 17, hWnd, (HMENU)ID_LABEL2, hInstance, NULL );

   hLabel3    = CreateWindowEx( NULL, L"Static", L"Driver Path:", WS_VISIBLE | WS_CHILD,
      20, 90, 80, 17, hWnd, (HMENU)ID_LABEL3, hInstance, NULL );

   hDrvName   = CreateWindowEx( NULL, L"Edit", L"", WS_VISIBLE | WS_BORDER | WS_CHILD | ES_AUTOHSCROLL,
      110, 50, 150, 17, hWnd, (HMENU)ID_DRIVERNAME, hInstance, NULL );

   hDrvDName  = CreateWindowEx( NULL, L"Edit", L"", WS_VISIBLE | WS_BORDER | WS_CHILD | ES_AUTOHSCROLL,
      110, 70, 150, 17, hWnd, (HMENU)ID_DRIVERDNAME, hInstance, NULL );

   hDrvPath   = CreateWindowEx( NULL, L"Edit", L"", WS_VISIBLE | WS_BORDER | WS_CHILD | ES_AUTOHSCROLL,
      110, 90, 150, 17, hWnd, (HMENU)ID_PATH, hInstance, NULL );

   hBrowse    = CreateWindowEx( NULL, L"Button", L"...", WS_VISIBLE | WS_CHILD,
      265, 90, 17, 17, hWnd, (HMENU)ID_BROWSE, hInstance, NULL );

   hInstall   = CreateWindowEx( NULL, L"Button", L"Install", WS_VISIBLE | WS_CHILD,
      20, 120, 60, 17, hWnd, (HMENU)ID_INSTALL, hInstance, NULL );

   hUnInstall = CreateWindowEx( NULL, L"Button", L"UnInstall", WS_VISIBLE | WS_CHILD,
      20, 140, 60, 17, hWnd, (HMENU)ID_UNINSTALL, hInstance, NULL );

   ZeroMemory( &openFile, sizeof(openFile) );
   openFile.lStructSize = sizeof(openFile);
   openFile.hwndOwner = hWnd;
   openFile.lpstrFilter = L"Driver (*.sys)\0*.sys\0All Files (*.*)\0*.*\0";
   openFile.lpstrFile = szOpFileName;
   openFile.nMaxFile = MAX_PATH;
   openFile.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
   openFile.lpstrDefExt = L"txt";

   for ( int i = ID_DRIVERNAME; i <= ID_BROWSE; i++ )
      SendDlgItemMessage( hWnd, i, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE );

   ShowWindow( hWnd, nShowCmd );
   UpdateWindow( hWnd );

   while( GetMessage( &Msg, NULL, 0, 0 ) > 0 )
   {
      TranslateMessage( &Msg );
      DispatchMessage( &Msg );
   }
   return Msg.wParam;
}


Uses UNICODE Charecter Set btw.



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
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