Guest User

Untitled

a guest
Jan 6th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <ntddk.h>
  2.  
  3. #include "main.h"
  4.  
  5.  
  6. /* Device and symbolic link */
  7.  
  8. NTSTATUS
  9. __stdcall
  10. InitializeDeviceAndSLink(IN PDRIVER_OBJECT DriverObject)
  11. {
  12. DbgPrint("InitializeDeviceAndSLink() start");
  13.  
  14. // Store device & symbolic link as unicode in UNICODE_STRING structs
  15. RtlInitUnicodeString(&g_unicode_DeviceName, g_wchar_DeviceName);
  16. RtlInitUnicodeString(&g_unicode_SymbolicLinkName, g_wchar_SymbolicLinkName);
  17.  
  18. // Create device & symbolic link
  19.  
  20. // https://msdn.microsoft.com/en-us/library/windows/hardware/ff548397(v=vs.85).aspx
  21. if( STATUS_SUCCESS != IoCreateDevice(DriverObject, // Pointer to Device
  22. 0, // Additional memory
  23. &g_unicode_DeviceName, // Device name
  24. FILE_DEVICE_NULL,
  25. 0, // Device characteristic
  26. FALSE, // Not exclusive
  27. &g_DeviceObject) )
  28. {
  29. return ( STATUS_FAILED_DRIVER_ENTRY );
  30. }
  31.  
  32. // https://msdn.microsoft.com/en-us/library/windows/hardware/ff549043(v=vs.85).aspx
  33. if( STATUS_SUCCESS != IoCreateSymbolicLink(&g_unicode_SymbolicLinkName,
  34. &g_unicode_DeviceName) )
  35. {
  36. return ( STATUS_FAILED_DRIVER_ENTRY );
  37. }
  38.  
  39. DbgPrint("InitializeDeviceAndSLink() end");
  40.  
  41. return ( STATUS_SUCCESS );
  42. }
  43.  
  44. VOID
  45. __stdcall
  46. UnInitializeDeviceAndSLink()
  47. {
  48. DbgPrint("InitializeDeviceAndSLink() start");
  49.  
  50. IoDeleteSymbolicLink(&g_unicode_SymbolicLinkName);
  51. IoDeleteDevice(g_DeviceObject);
  52.  
  53.  
  54. DbgPrint("InitializeDeviceAndSLink() end");
  55. }
  56.  
  57.  
  58. /* IRP routines */
  59.  
  60. // IRP_MJ_DEVICE_CONTROL call
  61. NTSTATUS DeviceControlRoutine( IN PDEVICE_OBJECT fdo, IN PIRP pIrp )
  62. {
  63. /*
  64. * Query manager process all IRP.
  65. * IRP will be completed by Query manager.
  66. */
  67. // return gQueryMng.ProcessIrp(pIrp);
  68.  
  69. return ( STATUS_SUCCESS );
  70. }
  71.  
  72. // IRP_MJ_CREATE call.
  73. NTSTATUS DeviceOpenHandleRoutine(IN PDEVICE_OBJECT fdo,IN PIRP Irp)
  74. {
  75. DbgPrint("-HideDriver- IRP_MJ_CREATE\n");
  76.  
  77. // return utils::CompleteIrp(Irp,STATUS_SUCCESS,0);
  78.  
  79. return ( STATUS_SUCCESS );
  80. }
  81.  
  82. // IRP_MJ_CLOSE call
  83. NTSTATUS DeviceCloseHandleRoutine(IN PDEVICE_OBJECT fdo,IN PIRP Irp)
  84. {
  85. DbgPrint("-HideDriver- IRP_MJ_CLOSE\n");
  86.  
  87. // return utils::CompleteIrp(Irp,STATUS_SUCCESS,0);
  88.  
  89. return ( STATUS_SUCCESS );
  90. }
Advertisement
Add Comment
Please, Sign In to add comment