home *** CD-ROM | disk | FTP | other *** search
- /*
- * Author : Ranveer Chandra
- * Directory: VirtualWiFi_Root\install
- * File Name: ioctls.cpp
- * Purpose : Define the functions used to make ioctl calls
- */
-
- #include "VirtualWiFiservice.h"
-
- LPCTSTR DriverName = TEXT("\\\\.\\VWiFi");
- extern bool Verbose;
-
- BOOL isInstalledVirtualWiFi()
- {
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- char lpOutString[50];
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- if(Verbose)
- sprintf(lpOutString, "VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- return FALSE;
- } else {
- CloseHandle(hDriver); // Close the handle
- return TRUE;
- }
- }
-
- VOID ioctlSet(DWORD dwIOControlCode,
- LPVOID lpInBuffer,
- DWORD lpInBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- BOOL b;
- ULONG bytesreturned;
- UCHAR testInput[10];
- //ULONG testLong;
- char lpOutString[50];
-
- //RtlCopyMemory(testInput, lpInBuffer, lpInBufferSize);
- //printf("The buffer is %s, buffer size is %d, string length %d\n", testInput, lpInBufferSize, strlen(testInput));
- // testLong = atol(testInput);
- //printf("The long input is %ld\n", testLong);
-
- //printf("Trying to open %s\n", DriverName);
-
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- if(Verbose)
- sprintf(lpOutString, "VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- // Otherwise, print success and close the driver
- } else {
- sprintf(lpOutString, "VWiFi.sys - CreateFile Success.\n");
- OutputDebugString(TEXT(lpOutString));
- b = DeviceIoControl(hDriver, // handle to a device, file, or directory
- dwIOControlCode, // control code of operation to perform
- lpInBuffer, //lpInBuffer, pointer to buffer to supply input data
- lpInBufferSize, //nInBufferSize, in bytes, of input buffer
- NULL, //lpOutBuffer, pointer to buffer to receive output data
- 0, //nOutBufferSize, in bytes, of output buffer
- &bytesreturned, // pointer to variable to receive byte count
- NULL // pointer to structure for asynchronous
- );
- sprintf(lpOutString, "IOCTL performed\n");
- OutputDebugString(TEXT(lpOutString));
- if (!b) {
- sprintf(lpOutString, "IOCTL FAILED!\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- }
- CloseHandle(hDriver); // Close the driver
- }
- }
-
- VOID ioctlGet(DWORD dwIOControlCode,
- LPVOID lpOutBuffer,
- DWORD lpOutBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- BOOL b;
- ULONG bytesreturned;
- char lpOutString[50];
-
- sprintf(lpOutString, "Trying to open %s\n", DriverName);
-
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- if(Verbose)
- sprintf(lpOutString, "VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- // Otherwise, print success and close the driver
- } else {
- sprintf(lpOutString, "VWiFi.sys - CreateFile Success.\n");
- OutputDebugString(TEXT(lpOutString));
- b = DeviceIoControl(hDriver, // handle to a device, file, or directory
- dwIOControlCode, // control code of operation to perform
- NULL, //lpInBuffer, pointer to buffer to supply input data
- 0, //nInBufferSize, in bytes, of input buffer
- lpOutBuffer, //lpOutBuffer, pointer to buffer to receive output data
- lpOutBufferSize, //nOutBufferSize, in bytes, of output buffer
- &bytesreturned, // pointer to variable to receive byte count
- NULL // pointer to structure for asynchronous
- );
- sprintf(lpOutString, "IOCTL performed\n");
- OutputDebugString(TEXT(lpOutString));
- if (!b) {
- sprintf(lpOutString, "IOCTL FAILED!\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- }
- else {
- sprintf(lpOutString, "IOCTL succeeded! lpoutBuffer value is %s, bytes received %d\n", lpOutBuffer, bytesreturned);
- OutputDebugString(TEXT(lpOutString));
- }
- CloseHandle(hDriver); // Close the driver
- }
- }
-
- ULONG ioctlGetFromAdapter(DWORD dwIOControlCode,
- LPVOID lpInBuffer,
- DWORD lpInBufferSize,
- LPVOID lpOutBuffer,
- DWORD lpOutBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- BOOL b;
- ULONG bytesreturned;
- ULONG output;
- char lpOutString[50];
-
- sprintf(lpOutString, "Trying to open %s\n", DriverName);
-
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- sprintf(lpOutString, "VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- // Otherwise, print success and close the driver
- } else {
- sprintf(lpOutString, "VWiFi.sys - CreateFile Success.\n");
- OutputDebugString(TEXT(lpOutString));
- b = DeviceIoControl(hDriver, // handle to a device, file, or directory
- dwIOControlCode, // control code of operation to perform
- lpInBuffer, //lpInBuffer, pointer to buffer to supply input data
- lpInBufferSize, //nInBufferSize, in bytes, of input buffer
- lpOutBuffer, //lpOutBuffer, pointer to buffer to receive output data
- lpOutBufferSize, //nOutBufferSize, in bytes, of output buffer
- &bytesreturned, // pointer to variable to receive byte count
- NULL // pointer to structure for asynchronous
- );
- sprintf(lpOutString, "IOCTL performed\n");
- OutputDebugString(TEXT(lpOutString));
- if (!b) {
- sprintf(lpOutString, "IOCTL FAILED! %ld\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- CloseHandle(hDriver); // Close the driver
- }
- else {
- sscanf((char *)lpOutBuffer, "%ld", &output);
- //sprintf(lpOutString, "IOCTL succeeded! lpoutBuffer value is %d, bytes received %d\n",
- // output, bytesreturned);
- //OutputDebugString(TEXT(lpOutString));
- CloseHandle(hDriver); // Close the driver
- return output;
- }
- }
- return 0;
- }
-
- ULONG ioctlGetULongFromAdapter(DWORD dwIOControlCode,
- LPVOID lpInBuffer,
- DWORD lpInBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- BOOL b;
- ULONG bytesreturned;
- ULONG recvdULong;
- char lpOutString[50];
-
- sprintf(lpOutString, "Trying to open %s\n", DriverName);
-
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- sprintf(lpOutString, "VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- // Otherwise, print success and close the driver
- } else {
- sprintf(lpOutString, "VWiFi.sys - CreateFile Success.\n");
- OutputDebugString(TEXT(lpOutString));
- b = DeviceIoControl(hDriver, // handle to a device, file, or directory
- dwIOControlCode, // control code of operation to perform
- lpInBuffer, //lpInBuffer, pointer to buffer to supply input data
- lpInBufferSize, //nInBufferSize, in bytes, of input buffer
- //lpOutBuffer, //lpOutBuffer, pointer to buffer to receive output data
- //lpOutBufferSize, //nOutBufferSize, in bytes, of output buffer
- (LPVOID)&recvdULong,
- sizeof(ULONG),
- &bytesreturned, // pointer to variable to receive byte count
- NULL // pointer to structure for asynchronous
- );
- sprintf(lpOutString, "IOCTL performed\n");
- OutputDebugString(TEXT(lpOutString));
- if (!b) {
- sprintf(lpOutString, "IOCTL FAILED! %s\n", GetLastError());
- OutputDebugString(TEXT(lpOutString));
- CloseHandle(hDriver); // Close the driver
- }
- else {
- sprintf(lpOutString, "IOCTL succeeded! long value is %ld, bytes received %d\n",
- recvdULong, bytesreturned);
- OutputDebugString(TEXT(lpOutString));
- CloseHandle(hDriver); // Close the driver
- }
- }
- return recvdULong;
- }
-
- ULONG ioctlGetSSIDFromAdapter(DWORD dwIOControlCode,
- LPVOID lpInBuffer,
- DWORD lpInBufferSize,
- LPVOID lpOutBuffer,
- DWORD lpOutBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the VWiFi.sys driver
- BOOL b;
- ULONG bytesreturned;
-
- //printf("Trying to open %s\n", DriverName);
-
- hDriver = CreateFile(DriverName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, // Default security
- OPEN_EXISTING,
- 0,
- 0); // No template
- if(hDriver == INVALID_HANDLE_VALUE) {
- if(Verbose)
- printf("VWiFi CreateFile- Error %ld - Maybe its not INSTALLED\n", GetLastError());
- // Otherwise, print success and close the driver
- } else {
- //printf("VWiFi.sys - CreateFile Success.\n");
- b = DeviceIoControl(hDriver, // handle to a device, file, or directory
- dwIOControlCode, // control code of operation to perform
- lpInBuffer, //lpInBuffer, pointer to buffer to supply input data
- lpInBufferSize, //nInBufferSize, in bytes, of input buffer
- lpOutBuffer, //lpOutBuffer, pointer to buffer to receive output data
- lpOutBufferSize, //nOutBufferSize, in bytes, of output buffer
- &bytesreturned, // pointer to variable to receive byte count
- NULL // pointer to structure for asynchronous
- );
- //printf("IOCTL performed\n");
- if (!b) {
- if(Verbose)
- printf("IOCTL FAILED!\n", GetLastError());
- CloseHandle(hDriver); // Close the driver
- }
- else {
- }
- }
- return bytesreturned;
- }
-
-