用Visual studio11在Windows8上开发驱动实现内存填0杀进程

在Windows NT中,80386保护模式的“保护”比Windows 95中更坚固,这个“镀金的笼子”更加结实,更加难以打破。在Windows 95中,至少应用程序I/O操作是不受限制的,而在Windows NT中,我们的应用程序连这点权限都被剥夺了。在NT中几乎不太可能进入真正的ring0层。
在Windows NT中,存在三种Device Driver:

  1.“Virtual device Driver” (VDD)。通过VDD,16位应用程序,如DOS 和Win16应用程序可以访问特定的I/O端口(注意,不是直接访问,而是要通过VDD来实现访问)。

  2.“GDI Driver”,提供显示和打印所需的GDI函数。

  3.“Kernel Mode Driver”,实现对特定硬件的操作,比如说CreateFile, CloseHandle (对于文件对象而言), ReadFile, WriteFile, DeviceIoControl 等操作。“Kernel Mode Driver”还是Windows NT中唯一可以对硬件中断和DMA进行操作的Driver。SCSI 小端口驱动和 网卡NDIS 驱动都是Kernel Mode Driver的一种特殊形式。

Visual studio11与Windows8带来格外不同的新体验

1.启动Vs11

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第1张图片

2.看见满目的驱动开发模板

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第2张图片

3.选择一个驱动模式,有内核模式与用户模式两种的驱动

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第3张图片

4.创建一个驱动程序,KMDF DriverMVP

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第4张图片

5.我们选择的是内核模式的驱动程序,下面是创建成功后的界面,分别是驱动程序本身,与驱动安装包

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第5张图片

6.按下F5,选择驱动编译,

用Visual studio11在Windows8上开发驱动实现内存填0杀进程_第6张图片


插入下列代码实现内存填0杀进程,请见代码分析



[cpp] view plain copy print ?
  1. void WPOFF() 
  2.     __asm {   //去掉内存保护 
  3.         cli 
  4.         mov  eax,cr0 
  5.         and  eax,not 10000h 
  6.         mov  cr0,eax 
  7.     } 
  8.  
  9. void WPON() 
  10.     __asm {   //恢复内存保护   
  11.         mov  eax,cr0 
  12.         or   eax,10000h 
  13.         mov  cr0,eax 
  14.         sti 
  15.     }  
  16.  
  17.  
  18. ////////////////////////////////////////////////////////////////////////////////// 
  19. ////////////////////////////////////////////////////////////////////////////////// 
  20.  
  21. #ifdef __cplusplus 
  22. #endif 
  23.  
  24. #endif 
  25.  
  26. NTKERNELAPI 
  27. BOOLEAN 
  28. KeInsertQueueApc ( 
  29.    PRKAPC Apc, 
  30.    PVOID SystemArgument1, 
  31.     PVOID SystemArgument2, 
  32.     KPRIORITY Increment 
  33.     ); 
  34.  
  35. BOOLEAN  
  36. fake_KeInsertQueueApc(IN PKAPC Apc, 
  37.                  IN PVOID SystemArgument1, 
  38.                  IN PVOID SystemArgument2, 
  39.                  IN KPRIORITY PriorityBoost); 
  40.  
  41. BOOLEAN 
  42. Proxy_KeInsertQueueApc(IN PKAPC Apc, 
  43.                  IN PVOID SystemArgument1, 
  44.                  IN PVOID SystemArgument2, 
  45.                  IN KPRIORITY PriorityBoost); 
  46.  
  47.  
  48. ULONG g_uCr0; 
  49.  
  50. void WPOFF() 
  51.     ULONG uAttr; 
  52.     
  53.     _asm 
  54.     { 
  55.         push eax; 
  56.         mov eax, cr0; 
  57.         mov uAttr, eax; 
  58.         and eax, 0FFFEFFFFh; // CR0 16 BIT = 0 
  59.         mov cr0, eax; 
  60.         pop eax; 
  61.         cli 
  62.     }; 
  63.     g_uCr0 = uAttr; //保存原有的 CRO 屬性 
  64.  
  65. VOID WPON() 
  66.     _asm 
  67.     { 
  68.         sti 
  69.         push eax; 
  70.         mov eax, g_uCr0; //恢復原有 CR0 屬性 
  71.         mov cr0, eax; 
  72.         pop eax; 
  73.     }; 
  74. #include <ntddk.h> 
  75.     #include"ntifs.h" 
  76.      
  77. typedef unsigned long DWORD
  78. PHYSICAL_ADDRESS    g_PhysicalPage; 
  79.  
  80. void WPOFF() 
  81.     __asm {   //去掉内存保护 
  82.         cli 
  83.         mov  eax,cr0 
  84.         and  eax,not 10000h 
  85.         mov  cr0,eax 
  86.     } 
  87.  
  88. void WPON() 
  89.     __asm {   //恢复内存保护   
  90.         mov  eax,cr0 
  91.         or   eax,10000h 
  92.         mov  cr0,eax 
  93.         sti 
  94.     }  
  95.  
  96. VOID DestroyProcess(DWORD eproc) 
  97.    DWORD                VirtualAddr; 
  98.    PHYSICAL_ADDRESS    physical_addr; 
  99.    DWORD                AddrTmp; 
  100.    PVOID                ProcessHandle; 
  101.  
  102.    KeAttachProcess( (PEPROCESS)eproc ); 
  103.    for ( VirtualAddr = 0x1000; VirtualAddr < *(DWORD*)MmSystemRangeStart; VirtualAddr+=0x1000) 
  104.    { 
  105.        // 跳过不再内存里的 
  106.        physical_addr = MmGetPhysicalAddress( (PVOID)VirtualAddr); 
  107.        if ( physical_addr.HighPart > g_PhysicalPage.HighPart ) 
  108.            continue
  109.        if ( physical_addr.HighPart == g_PhysicalPage.HighPart && 
  110.             physical_addr.LowPart >= g_PhysicalPage.LowPart   ) 
  111.            continue
  112.        if ( (physical_addr.HighPart | physical_addr.LowPart) == 0 ) 
  113.            continue
  114.        AddrTmp = (DWORD)MmGetVirtualForPhysical( physical_addr); 
  115.        if ( AddrTmp != VirtualAddr) 
  116.            continue
  117.        WPOFF(); 
  118.        RtlZeroMemory( (PVOID)VirtualAddr, 0x1000); 
  119.        WPON(); 
  120.    } 
  121.    KeDetachProcess(); 
  122.  
  123.    if ( ObOpenObjectByPointer( (PVOID)eproc, 0, NULL, 0, NULL, KernelMode, &ProcessHandle) != STATUS_SUCCESS) 
  124.        return
  125.    ZwTerminateProcess( (HANDLE)ProcessHandle, STATUS_SUCCESS); 
  126.    ZwClose( (HANDLE)ProcessHandle ); 
  127.    return
  128.  
  129.  
  130. VOID OnUnload( IN PDRIVER_OBJECT DriverObject ) 
  131.    DbgPrint("My Driver UnLoad!"); 
  132. //================================================================================================ 
  133. NTSTATUS DriverEntry( IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath ) 
  134.     SYSTEM_BASIC_INFORMATION BasicInfo; 
  135.     ULONG ReturnedLength; 
  136.     PEPROCESS eproc; 
  137.      
  138.      
  139.   DbgPrint("My Driver Loaded!"); 
  140.   theDriverObject->DriverUnload = OnUnload; 
  141.    
  142.   ZwQuerySystemInformation( SystemBasicInformation, &BasicInfo,  
  143.                             sizeof(SYSTEM_BASIC_INFORMATION), &ReturnedLength); 
  144.  
  145.    __asm mov eax,BasicInfo.PhysicalPageSize; 
  146.    __asm mul BasicInfo.NumberOfPhysicalPages; 
  147.    __asm mov g_PhysicalPage.HighPart, edx; 
  148.    __asm mov g_PhysicalPage.LowPart, eax; 
  149.     
  150.     PsLookupProcessByProcessId((PVOID)1068,&eproc); 
  151.   DestroyProcess((DWORD)eproc); 
  152.   return STATUS_SUCCESS; 
  153. //================================================================================================ 
  154.  
  155. #include "pe.h" 
  156.  
  157. #ifndef GLOBAL_NATIVE_API_DEF_SUDAMI 
  158. #define GLOBAL_NATIVE_API_DEF_SUDAMI 
  159.  
  160. #ifdef __cplusplus 
  161. extern "C"
  162. #endif 
  163.  
  164. //////////////////////////////////////////////////////////////////////// 
  165. //////////////////////////////////////////////////////////////////////// 
  166.  
  167. typedef long NTSTATUS, *PNTSTATUS; 
  168.  
  169. typedef unsigned long DWORD
  170. typedef DWORD * PDWORD; 
  171. typedef unsigned long ULONG
  172. typedef unsigned long ULONG_PTR
  173. typedef ULONG *PULONG
  174. typedef unsigned short WORD
  175. typedef unsigned char BYTE;  
  176. typedef unsigned char UCHAR
  177. typedef unsigned short USHORT
  178. typedef void *PVOID
  179. typedef int BOOL
  180. typedef BYTE BOOLEAN
  181.  
  182. typedef CCHAR KPROCESSOR_MODE; 
  183.  
  184.  
  185.  
  186. #ifndef  LOWORD 
  187. #define LOWORD(l)           ((unsigned short)(unsigned int)(l)) 
  188. #endif 
  189.  
  190. #ifndef HIWORD 
  191. #define HIWORD(l)           ((unsigned short)((((unsigned int)(l)) >> 16) & 0xFFFF)) 
  192. #endif 
  193.  
  194. // 定义ioctl相关的,用于R3和R0间的通信 
  195. #ifndef MAKELONG 
  196. #define MAKELONG(a, b) ((LONG) (((WORD) (a)) | ((DWORD) ((WORD) (b))) << 16)) 
  197. #endif 
  198.  
  199. #define MY_DEVICE_TYPE       0x0000AA71   // 这地方可以自己改 
  200. #define DRIVER_IO(code)  CTL_CODE (MY_DEVICE_TYPE, code, METHOD_BUFFERED, FILE_ANY_ACCESS) 
  201.  
  202. typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; 
  203.  
  204. /**********************************************************
  205. #define NT_DEVICE_NAME              L"\\Device\\sKillTimeProtected"
  206. #define DOS_DEVICE_NAME             L"\\DosDevices\\sKillTimeProtected"
  207. //                                                                              --   
  208. #ifndef  ANSI_STRING
  209. typedef struct _STRING {
  210.   USHORT  Length;
  211.   USHORT  MaximumLength;
  212.   PCHAR  Buffer;
  213. } ANSI_STRING, *PANSI_STRING;
  214. #endif
  215. #ifndef  UNICODE_STRING
  216. typedef struct _UNICODE_STRING {
  217.   USHORT  Length;
  218.   USHORT  MaximumLength;
  219.   PWSTR  Buffer;
  220. } UNICODE_STRING, *PUNICODE_STRING;
  221. #endif
  222. /* SSDT */ 
  223. #pragma pack(1) 
  224. typedef struct ServiceDescriptorEntry { 
  225.     unsigned int    *ServiceTableBase; 
  226.     unsigned int    *ServiceCounterTableBase;  
  227.     unsigned int    NumberOfServices; 
  228.     unsigned char   *ParamTableBase; 
  229. } ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t; 
  230.  
  231. typedef struct ServiceDescriptorShadowEntry { 
  232.     unsigned int    *Win32kTableBase; 
  233.     unsigned int    *Win32kCounterTableBase; 
  234.     unsigned int    NumberofWin32kServices; 
  235.     unsigned char   *Win32kParamTableBase; 
  236. } ServiceDescriptorTableShadowEntry_t, *PServiceDescriptorTableShadowEntry_t; 
  237. #pragma pack() 
  238.  
  239. __declspec(dllimport)  ServiceDescriptorTableEntry_t    KeServiceDescriptorTable; 
  240. PServiceDescriptorTableShadowEntry_t                    KeServiceDescriptorTableShadow; 
  241.  
  242.  
  243.  
  244. struct _SYSTEM_THREADS 
  245.     LARGE_INTEGER       KernelTime; 
  246.     LARGE_INTEGER       UserTime; 
  247.     LARGE_INTEGER       CreateTime; 
  248.     ULONG               WaitTime; 
  249.     PVOID               StartAddress; 
  250.     CLIENT_ID           ClientIs; 
  251.     KPRIORITY           Priority; 
  252.     KPRIORITY           BasePriority; 
  253.     ULONG               ContextSwitchCount; 
  254.     ULONG               ThreadState; 
  255.     KWAIT_REASON        WaitReason; 
  256. }; 
  257.  
  258. struct _SYSTEM_PROCESSES 
  259.     ULONG               NextEntryDelta; 
  260.     ULONG               ThreadCount; 
  261.     ULONG               Reserved[6]; 
  262.     LARGE_INTEGER       CreateTime; 
  263.     LARGE_INTEGER       UserTime; 
  264.     LARGE_INTEGER       KernelTime; 
  265.     UNICODE_STRING      ProcessName; 
  266.     KPRIORITY           BasePriority; 
  267.     ULONG               ProcessId; 
  268.     ULONG               InheritedFromProcessId; 
  269.     ULONG               HandleCount; 
  270.     ULONG               Reserved2[2]; 
  271.     VM_COUNTERS         VmCounters; 
  272.     IO_COUNTERS         IoCounters; //windows 2000 only 
  273.     struct _SYSTEM_THREADS      Threads[1]; 
  274. }; 
  275.  
  276.  
  277. // PROCESS_BASIC_INFORMATION 
  278. #ifdef  PROCESS_BASIC_INFORMATION 
  279. #undef  PROCESS_BASIC_INFORMATION 
  280. typedef struct _PROCESS_BASIC_INFORMATION { 
  281.     NTSTATUS        ExitStatus; 
  282.     ULONG           PebBaseAddress; 
  283.     ULONG_PTR       AffinityMask; 
  284.     LONG            BasePriority; 
  285.     ULONG_PTR       UniqueProcessId; 
  286.     ULONG_PTR       InheritedFromUniqueProcessId; 
  287. } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; 
  288. #endif 
  289.  
  290.  
  291. // SYSTEM_HANDLE_INFORMATION 
  292. typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO { 
  293.      USHORT UniqueProcessId; 
  294.      USHORT CreatorBackTraceIndex; 
  295.      UCHAR ObjectTypeIndex; 
  296.      UCHAR HandleAttributes; 
  297.      USHORT HandleValue;   // 句柄 
  298.      PVOID Object;         // 若HANDLE类型为线程,则它是ETHREAD结构 
  299.      ULONG GrantedAccess; 
  300. } SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; 
  301.  
  302. typedef struct _SYSTEM_HANDLE_INFORMATION { 
  303.      ULONG NumberOfHandles; 
  304.      SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; 
  305. } SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION; 
  306.  
  307.  
  308. // SYSTEM_MODULE_INFORMATION 
  309. typedef struct _SYSTEM_MODULE_INFORMATION { 
  310.     ULONG   Reserved[2]; 
  311.     PVOID   Base; 
  312.     ULONG   Size; 
  313.     ULONG   Flags; 
  314.     USHORT  Index; 
  315.     USHORT  Unknown; 
  316.     USHORT  LoadCount; 
  317.     USHORT  ModuleNameOffset; 
  318.     CHAR    ImageName[256]; 
  319. } SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION; 
  320.  
  321.  
  322. typedef struct
  323.     ULONG   dwNumberOfModules; 
  324.     SYSTEM_MODULE_INFORMATION   smi; 
  325. } MODULES, *PMODULES; 
  326.  
  327.  
  328. // SYSTEM_BASIC_INFORMATION 
  329. typedef struct _SYSTEM_BASIC_INFORMATION { 
  330.     ULONG Unknown;                  //Always contains zero 
  331.     ULONG MaximumIncrement;         //一个时钟的计量单位 
  332.     ULONG PhysicalPageSize;         //一个内存页的大小 
  333.     ULONG NumberOfPhysicalPages;    //系统管理着多少个页 
  334.     ULONG LowestPhysicalPage;       //低端内存页 
  335.     ULONG HighestPhysicalPage;      //高端内存页 
  336.     ULONG AllocationGranularity; 
  337.     ULONG LowestUserAddress;        //地端用户地址 
  338.     ULONG HighestUserAddress;       //高端用户地址 
  339.     ULONG ActiveProcessors;         //激活的处理器 
  340.     UCHAR NumberProcessors;         //有多少个处理器 
  341. } SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION; 
  342.  
  343.  
  344. // SYSTEM_INFORMATION_CLASS 
  345. typedef enum _SYSTEM_INFORMATION_CLASS { 
  346.     SystemBasicInformation, 
  347.     SystemProcessorInformation, 
  348.     SystemPerformanceInformation, 
  349.     SystemTimeOfDayInformation, 
  350.     SystemPathInformation, 
  351.     SystemProcessInformation, 
  352.     SystemCallCountInformation, 
  353.     SystemDeviceInformation, 
  354.     SystemProcessorPerformanceInformation, 
  355.     SystemFlagsInformation, 
  356.     SystemCallTimeInformation, 
  357.     SystemModuleInformation,  // 11 
  358.     SystemLocksInformation, 
  359.     SystemStackTraceInformation, 
  360.     SystemPagedPoolInformation, 
  361.     SystemNonPagedPoolInformation, 
  362.     SystemHandleInformation,  // 0x10 -- 16 
  363.     SystemObjectInformation, 
  364.     SystemPageFileInformation, 
  365.     SystemVdmInstemulInformation, 
  366.     SystemVdmBopInformation, 
  367.     SystemFileCacheInformation, 
  368.     SystemPoolTagInformation, 
  369.     SystemInterruptInformation, 
  370.     SystemDpcBehaviorInformation, 
  371.     SystemFullMemoryInformation, 
  372.     SystemLoadGdiDriverInformation, 
  373.     SystemUnloadGdiDriverInformation, 
  374.     SystemTimeAdjustmentInformation, 
  375.     SystemSummaryMemoryInformation, 
  376.     SystemUnused1, 
  377.     SystemPerformanceTraceInformation, 
  378.     SystemCrashDumpInformation, 
  379.     SystemExceptionInformation, 
  380.     SystemCrashDumpStateInformation, 
  381.     SystemKernelDebuggerInformation, 
  382.     SystemContextSwitchInformation, 
  383.     SystemRegistryQuotaInformation, 
  384.     SystemExtendServiceTableInformation, 
  385.     SystemPrioritySeperation, 
  386.     SystemUnused3, 
  387.     SystemUnused4, 
  388.     SystemUnused5, 
  389.     SystemUnused6, 
  390.     SystemCurrentTimeZoneInformation, 
  391.     SystemLookasideInformation, 
  392.     SystemTimeSlipNotification, 
  393.     SystemSessionCreate, 
  394.     SystemSessionDetach, 
  395.     SystemSessionInformation 
  396. } SYSTEM_INFORMATION_CLASS; 
  397.  
  398.  
  399. #ifndef  SECTION_INHERIT 
  400. typedef enum _SECTION_INHERIT { 
  401.     ViewShare = 1, 
  402.     ViewUnmap = 2 
  403. } SECTION_INHERIT; 
  404. #endif 
  405.  
  406. #ifndef LUID 
  407. typedef struct _LUID { 
  408.     DWORD LowPart; 
  409.     LONG  HighPart; 
  410. } LUID, *PLUID; 
  411. #endif 
  412.  
  413.  
  414. #ifndef LARGE_INTEGER 
  415. typedef union _LARGE_INTEGER { 
  416.     struct
  417.         ULONG LowPart; 
  418.         LONG HighPart; 
  419.     }; 
  420.     struct
  421.         ULONG LowPart; 
  422.         LONG HighPart; 
  423.     } u; 
  424.     LONGLONG QuadPart; 
  425. } LARGE_INTEGER, *PLARGE_INTEGER; 
  426. #endif 
  427.  
  428. #ifndef TIME_FIELDS 
  429. typedef struct _TIME_FIELDS { 
  430.  
  431.   USHORT                  Year; 
  432.   USHORT                  Month; 
  433.   USHORT                  Day; 
  434.   USHORT                  Hour; 
  435.   USHORT                  Minute; 
  436.   USHORT                  Second; 
  437.   USHORT                  Milliseconds; 
  438.   USHORT                  Weekday; 
  439.  
  440. } TIME_FIELDS, *PTIME_FIELDS; 
  441. #endif 
  442.  
  443.  
  444.  
  445.  
  446. NTSTATUS 
  447. NTAPI 
  448. ZwQuerySystemInformation(     
  449.     DWORD    SystemInformationClass, 
  450.     PVOID    SystemInformation, 
  451.     ULONG    SystemInformationLength, 
  452.     PULONG    ReturnLength 
  453.     ); 
  454.  
  455. NTSYSAPI 
  456. NTSTATUS 
  457. NTAPI 
  458. NtOpenFile( 
  459.     OUT PHANDLE FileHandle, 
  460.     IN ACCESS_MASK DesiredAccess, 
  461.     IN POBJECT_ATTRIBUTES ObjectAttributes, 
  462.     OUT PIO_STATUS_BLOCK IoStatusBlock, 
  463.     IN ULONG ShareAccess, 
  464.     IN ULONG OpenOptions 
  465.     ); 
  466.  
  467.  
  468. NTSYSAPI  
  469. VOID  
  470. NTAPI  
  471. RtlInitUnicodeString(  
  472.      PUNICODE_STRING DestinationString,  
  473.      PCWSTR SourceString  
  474.      );  
  475.  
  476. NTSYSAPI  
  477. NTSTATUS  
  478. NTAPI  
  479. ZwOpenSection(  
  480.      OUT PHANDLE SectionHandle,  
  481.      IN ACCESS_MASK DesiredAccess,  
  482.      IN POBJECT_ATTRIBUTES objectAttributes  
  483.      );  
  484.  
  485.  
  486. NTSYSAPI  
  487. NTSTATUS  
  488. NTAPI  
  489. ZwMapViewOfSection(  
  490.      IN HANDLE SectionHandle,  
  491.      IN HANDLE ProcessHandle,  
  492.      IN OUT PVOID *BaseAddress,  
  493.      IN ULONG ZeroBits,  
  494.      IN ULONG CommitSize,  
  495.      IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,  
  496.      IN OUT PULONG ViewSize,  
  497.      IN SECTION_INHERIT InheritDisposition,  
  498.      IN ULONG AllocationType,  
  499.      IN ULONG Protect  
  500.      );  
  501.  
  502. NTSYSAPI 
  503. NTSTATUS 
  504. NTAPI 
  505. NtCreateSection( 
  506.     PHANDLE  SectionHandle, 
  507.     ACCESS_MASK  DesiredAccess, 
  508.     POBJECT_ATTRIBUTES  ObjectAttributes, 
  509.     PLARGE_INTEGER  MaximumSize OPTIONAL, 
  510.     ULONG  SectionPageProtection, 
  511.     ULONG  AllocationAttributes, 
  512.     HANDLE  FileHandle 
  513.     );  
  514.  
  515.  
  516. NTSYSAPI  
  517. NTSTATUS  
  518. NTAPI  
  519. ZwUnmapViewOfSection(  
  520.      IN HANDLE ProcessHandle,  
  521.      IN PVOID BaseAddress  
  522.      );  
  523.  
  524.  
  525. NTSYSAPI 
  526. NTSTATUS 
  527. NTAPI 
  528. NtReadFile( 
  529.     IN HANDLE FileHandle, 
  530.     IN HANDLE Event OPTIONAL, 
  531.     IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, 
  532.     IN PVOID ApcContext OPTIONAL, 
  533.     OUT PIO_STATUS_BLOCK IoStatusBlock, 
  534.     OUT PVOID Buffer, 
  535.     IN ULONG Length, 
  536.     IN PLARGE_INTEGER ByteOffset OPTIONAL, 
  537.     IN PULONG Key OPTIONAL 
  538.     ); 
  539.  
  540.  
  541. NTSYSAPI  
  542. VOID 
  543. NTAPI 
  544. RtlTimeToTimeFields( 
  545.   IN PLARGE_INTEGER       Time, 
  546.   OUT PTIME_FIELDS        TimeFields 
  547.   ); 
  548.  
  549. NTSYSAPI  
  550. BOOLEAN 
  551. NTAPI 
  552. RtlTimeFieldsToTime( 
  553.   IN PTIME_FIELDS         TimeFields, 
  554.   OUT PLARGE_INTEGER      Time 
  555.   ); 
  556.  
  557.  
  558. /*
  559. VOID
  560. NTAPI
  561. KeSetSystemTime(
  562.   IN PLARGE_INTEGER NewTime,
  563.   OUT PLARGE_INTEGER OldTime,
  564.   IN BOOLEAN FixInterruptTime,
  565.   IN PLARGE_INTEGER HalTime OPTIONAL
  566.   );
  567. */ 
  568.  
  569. NTSTATUS 
  570. NTAPI 
  571. NtQuerySystemTime ( 
  572.   OUT PLARGE_INTEGER SystemTime 
  573.   ); 
  574.  
  575.  
  576.  
  577.  
  578. // 写保护的开&关 
  579. void WPOFF() 
  580.     __asm {   //去掉内存保护 
  581.         cli 
  582.         mov  eax,cr0 
  583.         and  eax,not 10000h 
  584.         mov  cr0,eax 
  585.     } 
  586.  
  587. void WPON() 
  588.     __asm {   //恢复内存保护   
  589.         mov  eax,cr0 
  590.         or   eax,10000h 
  591.         mov  cr0,eax 
  592.         sti 
  593.     }  
  594.  
  595.  
  596. ////////////////////////////////////////////////////////////////////////////////// 
  597. ////////////////////////////////////////////////////////////////////////////////// 
  598.  
  599. #ifdef __cplusplus 
  600. #endif 
  601.  
  602. #endif 

 

原文地址:http://blog.csdn.net/yincheng01/article/details/8107336

你可能感兴趣的:(用Visual studio11在Windows8上开发驱动实现内存填0杀进程)