home *** CD-ROM | disk | FTP | other *** search
- /*
- * Author : Ranveer Chandra
- * Directory: VirtualWiFi_Root\Service
- * File Name: ioctls.cpp
- * Purpose : Defines the ioctls to be used by the Service
- */
-
- #include "VirtualWiFiservice.h"
-
- LPCTSTR DriverName = TEXT("\\\\.\\VWiFi");
-
- /*
- VOID Usage(char *binName)
- {
- printf("Usage: %s <adapter>\n", binName);
- printf("V. IMP! DO NOT SWITCH THIS SERVICE OFF BEFORE UNINSTALLING VirtualWiFi\n");
- exit(1);
- }
- */
-
- ULONG ioctlSet(DWORD dwIOControlCode,
- LPVOID lpInBuffer,
- DWORD lpInBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the Snap.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) {
- sprintf(lpOutString, "VWiFi.sys 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
- return 0;
- }
-
- VOID ioctlGet(DWORD dwIOControlCode,
- LPVOID lpOutBuffer,
- DWORD lpOutBufferSize)
- {
-
- HANDLE hDriver = NULL; // handle to the Snap.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) {
- sprintf(lpOutString, "VWiFi.sys 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 Snap.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.sys 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 Snap.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.sys 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 Snap.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) {
- printf("VWiFi.sys 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) {
- printf("IOCTL FAILED!\n", GetLastError());
- CloseHandle(hDriver); // Close the driver
- }
- else {
- }
- }
- return bytesreturned;
- }
-
-