Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ntddk.h>
- #include "main.h"
- /* Device and symbolic link */
- NTSTATUS
- __stdcall
- InitializeDeviceAndSLink(IN PDRIVER_OBJECT DriverObject)
- {
- DbgPrint("InitializeDeviceAndSLink() start");
- // Store device & symbolic link as unicode in UNICODE_STRING structs
- RtlInitUnicodeString(&g_unicode_DeviceName, g_wchar_DeviceName);
- RtlInitUnicodeString(&g_unicode_SymbolicLinkName, g_wchar_SymbolicLinkName);
- // Create device & symbolic link
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff548397(v=vs.85).aspx
- if( STATUS_SUCCESS != IoCreateDevice(DriverObject, // Pointer to Device
- 0, // Additional memory
- &g_unicode_DeviceName, // Device name
- FILE_DEVICE_NULL,
- 0, // Device characteristic
- FALSE, // Not exclusive
- &g_DeviceObject) )
- {
- return ( STATUS_FAILED_DRIVER_ENTRY );
- }
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff549043(v=vs.85).aspx
- if( STATUS_SUCCESS != IoCreateSymbolicLink(&g_unicode_SymbolicLinkName,
- &g_unicode_DeviceName) )
- {
- return ( STATUS_FAILED_DRIVER_ENTRY );
- }
- DbgPrint("InitializeDeviceAndSLink() end");
- return ( STATUS_SUCCESS );
- }
- VOID
- __stdcall
- UnInitializeDeviceAndSLink()
- {
- DbgPrint("InitializeDeviceAndSLink() start");
- IoDeleteSymbolicLink(&g_unicode_SymbolicLinkName);
- IoDeleteDevice(g_DeviceObject);
- DbgPrint("InitializeDeviceAndSLink() end");
- }
- /* IRP routines */
- // IRP_MJ_DEVICE_CONTROL call
- NTSTATUS DeviceControlRoutine( IN PDEVICE_OBJECT fdo, IN PIRP pIrp )
- {
- /*
- * Query manager process all IRP.
- * IRP will be completed by Query manager.
- */
- // return gQueryMng.ProcessIrp(pIrp);
- return ( STATUS_SUCCESS );
- }
- // IRP_MJ_CREATE call.
- NTSTATUS DeviceOpenHandleRoutine(IN PDEVICE_OBJECT fdo,IN PIRP Irp)
- {
- DbgPrint("-HideDriver- IRP_MJ_CREATE\n");
- // return utils::CompleteIrp(Irp,STATUS_SUCCESS,0);
- return ( STATUS_SUCCESS );
- }
- // IRP_MJ_CLOSE call
- NTSTATUS DeviceCloseHandleRoutine(IN PDEVICE_OBJECT fdo,IN PIRP Irp)
- {
- DbgPrint("-HideDriver- IRP_MJ_CLOSE\n");
- // return utils::CompleteIrp(Irp,STATUS_SUCCESS,0);
- return ( STATUS_SUCCESS );
- }
Advertisement
Add Comment
Please, Sign In to add comment