⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fspyuser.c

📁 文件过滤驱动
💻 C
字号:
/*++Copyright (c) 1989-1999  Microsoft CorporationModule Name:    fspyUser.cAbstract:    This file contains the implementation for the main function of the     user application piece of FileSpy.  This function is responsible for    controlling the command mode available to the user to control the     kernel mode driver.    Author:    George Jenkins (GeorgeJe)                       Environment:    User modeRevision History:    Molly Brown (MollyBro) 21-Apr-1999        Broke out the logging code and added command mode functionality.        --*/#include <windows.h>                #include <stdlib.h>#include <stdio.h>#include <winioctl.h>#include <string.h>#include <crtdbg.h>#include "..\kenerl\MyFileSpy.h"#include "fspyLog.h"#include "..\Install\FspyServ.h"#define SUCCESS              0#define USAGE_ERROR          1#define EXIT_INTERPRETER     2#define EXIT_PROGRAM         4#define INTERPRETER_EXIT_COMMAND1 "go"#define INTERPRETER_EXIT_COMMAND2 "g"#define PROGRAM_EXIT_COMMAND      "exit"int _cdecl main(int argc, char *argv[]){    SC_HANDLE               hSCManager = NULL;    SC_HANDLE               hService = NULL;    SERVICE_STATUS_PROCESS  serviceInfo;    DWORD                   bytesNeeded;    HANDLE                  hDevice = NULL;    BOOL                    bResult;    DWORD                   result;    ULONG                   threadId;
	ULONG                   nBytes;    HANDLE                  thread = NULL;    INT                     inputChar;

	CHAR					buffer[BUFFER_SIZE];
    DWORD					bufferLength;
	DWORD					bytesReturned;

	BOOL                    Exit = FALSE;
	INT                    A;
    //    // Initialize handle in case of error    //    //    // Start the kernel mode driver through the service manager    //        hSCManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS) ;    hService = OpenService( hSCManager,                            FILESPY_SERVICE_NAME,                            FILESPY_SERVICE_ACCESS);    if (!QueryServiceStatusEx( hService,                               SC_STATUS_PROCESS_INFO,                               (UCHAR *)&serviceInfo,                               sizeof(serviceInfo),                               &bytesNeeded)) {        result = GetLastError();        goto Main_Exit;    }    if(serviceInfo.dwCurrentState != SERVICE_RUNNING) {        //        // Service hasn't been started yet, so try to start service        //        if (!StartService(hService, 0, NULL)) {            result = GetLastError();            printf("ERROR starting FileSpy...\n");            goto Main_Exit;        }    }       printf("Hit [Enter] to begin command mode...\n");    //    //  Open the device that is used to talk to FileSpy.    //    printf("FileSpy:  Opening device...\n");        hDevice = CreateFile( FILESPY_W32_DEVICE_NAME,                          GENERIC_READ | GENERIC_WRITE,                          0,                          NULL,                          OPEN_EXISTING,                          FILE_ATTRIBUTE_NORMAL,                          NULL);    if (hDevice == INVALID_HANDLE_VALUE) {        result = GetLastError();        printf("ERROR opening device...\n");        goto Main_Exit;    };

	while(!Exit)
	{
		printf("Please enter a CHAR to Run...\n");
		A = getchar();
		switch(A)
		{
		case 'a':
		case 'A':
			bufferLength = MultiByteToWideChar(
                    CP_ACP,
                    MB_ERR_INVALID_CHARS,
                    "D:\\study",
                    -1,
                    (LPWSTR)buffer,
                    BUFFER_SIZE/sizeof(WCHAR));
                
			bResult = DeviceIoControl(
                    hDevice,
                    FILESPY_Attach,
                    buffer,
                    bufferLength * sizeof(WCHAR),
                    NULL,
                    0,
                    &bytesReturned,
                    NULL);
             if (!bResult) {
                    result = GetLastError();
                    printf("ERROR attaching to device...\n");
                  }
			 break;

		case 'd':
		case 'D':
			bufferLength = MultiByteToWideChar(
                    CP_ACP,
                    MB_ERR_INVALID_CHARS,
                    "D:\\study",
                    -1,
                    (LPWSTR)buffer,
                    BUFFER_SIZE/sizeof(WCHAR));
                
                bResult = DeviceIoControl(
                    hDevice,
                    FILESPY_Detach,
                    buffer,
                    bufferLength * sizeof(WCHAR),
                    NULL,
                    0,
                    &bytesReturned,
                    NULL);
                
                if (!bResult) {
                    result = GetLastError();
                    printf("ERROR detaching to device...\n");
                }
			break;

		case 'x':
		case 'X':
			Exit = TRUE;
			break;
		}
	}


Main_Exit:    if(hSCManager) {        CloseServiceHandle(hSCManager);    }    if(hService) {        CloseServiceHandle(hService);    }    if (hDevice) {        CloseHandle(hDevice);    }        printf("FileSpy:  All done\n");    return 0;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -