📄 init.c
字号:
NulMRxDeviceObject,
RX_CONTEXT_FLAG_IN_FSP);
if (RxContext != NULL) {
Status = RxStopMinirdr(
RxContext,
&RxContext->PostRequest);
if (Status == STATUS_SUCCESS) {
NULMRX_STATE State;
State = (NULMRX_STATE)InterlockedCompareExchange(
(LONG *)&NulMRxState,
NULMRX_STARTABLE,
NULMRX_STARTED);
if (State != NULMRX_STARTABLE) {
Status = STATUS_REDIRECTOR_STARTED;
}
}
RxDereferenceAndDeleteRxContext(RxContext);
} else {
Status = STATUS_INSUFFICIENT_RESOURCES;
}
RtlInitUnicodeString(&UserModeDeviceName, DD_NULMRX_USERMODE_SHADOW_DEV_NAME_U);
Status = IoDeleteSymbolicLink( &UserModeDeviceName);
if (Status!=STATUS_SUCCESS) {
DbgPrint("NulMRx: Could not delete Symbolic Link\n");
}
RxUnload(DriverObject);
DbgPrint("+++ NULMRX Driver %08lx Unoaded +++\n", DriverObject);
}
NTSTATUS
NulMRxInitializeTables(
void
)
/*++
Routine Description:
This routine sets up the mini redirector dispatch vector and also calls
to initialize any other tables needed.
Return Value:
RXSTATUS - The return status for the operation
--*/
{
//
// Ensure that the Exchange mini redirector context satisfies the size constraints
//
//ASSERT(sizeof(NULMRX_RX_CONTEXT) <= MRX_CONTEXT_SIZE);
//
// Build the local minirdr dispatch table and initialize
//
ZeroAndInitializeNodeType( &NulMRxDispatch, RDBSS_NTC_MINIRDR_DISPATCH, sizeof(MINIRDR_DISPATCH));
//
// null mini redirector extension sizes and allocation policies.
//
NulMRxDispatch.MRxFlags = (RDBSS_MANAGE_NET_ROOT_EXTENSION |
RDBSS_MANAGE_FCB_EXTENSION);
NulMRxDispatch.MRxSrvCallSize = 0; // srvcall extension is not handled in rdbss
NulMRxDispatch.MRxNetRootSize = sizeof(NULMRX_NETROOT_EXTENSION);
NulMRxDispatch.MRxVNetRootSize = 0;
NulMRxDispatch.MRxFcbSize = sizeof(NULMRX_FCB_EXTENSION);
NulMRxDispatch.MRxSrvOpenSize = 0;
NulMRxDispatch.MRxFobxSize = 0;
// Mini redirector cancel routine ..
NulMRxDispatch.MRxCancel = NULL;
//
// Mini redirector Start/Stop. Each mini-rdr can be started or stopped
// while the others continue to operate.
//
NulMRxDispatch.MRxStart = NulMRxStart;
NulMRxDispatch.MRxStop = NulMRxStop;
NulMRxDispatch.MRxDevFcbXXXControlFile = NulMRxDevFcbXXXControlFile;
//
// Mini redirector name resolution.
//
NulMRxDispatch.MRxCreateSrvCall = NulMRxCreateSrvCall;
NulMRxDispatch.MRxSrvCallWinnerNotify = NulMRxSrvCallWinnerNotify;
NulMRxDispatch.MRxCreateVNetRoot = NulMRxCreateVNetRoot;
NulMRxDispatch.MRxUpdateNetRootState = NulMRxUpdateNetRootState;
NulMRxDispatch.MRxExtractNetRootName = NulMRxExtractNetRootName;
NulMRxDispatch.MRxFinalizeSrvCall = NulMRxFinalizeSrvCall;
NulMRxDispatch.MRxFinalizeNetRoot = NulMRxFinalizeNetRoot;
NulMRxDispatch.MRxFinalizeVNetRoot = NulMRxFinalizeVNetRoot;
//
// File System Object Creation/Deletion.
//
NulMRxDispatch.MRxCreate = NulMRxCreate;
NulMRxDispatch.MRxCollapseOpen = NulMRxCollapseOpen;
NulMRxDispatch.MRxShouldTryToCollapseThisOpen = NulMRxShouldTryToCollapseThisOpen;
NulMRxDispatch.MRxExtendForCache = NulMRxExtendFile;
NulMRxDispatch.MRxExtendForNonCache = NulMRxExtendFile;
NulMRxDispatch.MRxTruncate = NulMRxTruncate;
NulMRxDispatch.MRxCleanupFobx = NulMRxCleanupFobx;
NulMRxDispatch.MRxCloseSrvOpen = NulMRxCloseSrvOpen;
NulMRxDispatch.MRxFlush = NulMRxFlush;
NulMRxDispatch.MRxForceClosed = NulMRxForcedClose;
NulMRxDispatch.MRxDeallocateForFcb = NulMRxDeallocateForFcb;
NulMRxDispatch.MRxDeallocateForFobx = NulMRxDeallocateForFobx;
//
// File System Objects query/Set
//
NulMRxDispatch.MRxQueryDirectory = NulMRxQueryDirectory;
NulMRxDispatch.MRxQueryVolumeInfo = NulMRxQueryVolumeInformation;
NulMRxDispatch.MRxQueryEaInfo = NulMRxQueryEaInformation;
NulMRxDispatch.MRxSetEaInfo = NulMRxSetEaInformation;
NulMRxDispatch.MRxQuerySdInfo = NulMRxQuerySecurityInformation;
NulMRxDispatch.MRxSetSdInfo = NulMRxSetSecurityInformation;
NulMRxDispatch.MRxQueryFileInfo = NulMRxQueryFileInformation;
NulMRxDispatch.MRxSetFileInfo = NulMRxSetFileInformation;
NulMRxDispatch.MRxSetFileInfoAtCleanup = NulMRxSetFileInformationAtCleanup;
//
// Buffering state change
//
NulMRxDispatch.MRxComputeNewBufferingState = NulMRxComputeNewBufferingState;
//
// File System Object I/O
//
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_READ] = NulMRxRead;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_WRITE] = NulMRxWrite;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_SHAREDLOCK] = NulMRxLocks;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_EXCLUSIVELOCK] = NulMRxLocks;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK] = NulMRxLocks;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK_MULTIPLE] = NulMRxLocks;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_FSCTL] = NulMRxFsCtl;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_IOCTL] = NulMRxIoCtl;
NulMRxDispatch.MRxLowIOSubmit[LOWIO_OP_NOTIFY_CHANGE_DIRECTORY] = NulMRxNotifyChangeDirectory;
//
// Miscellanous
//
NulMRxDispatch.MRxCompleteBufferingStateChangeRequest = NulMRxCompleteBufferingStateChangeRequest;
return(STATUS_SUCCESS);
}
NTSTATUS
NulMRxStart(
PRX_CONTEXT RxContext,
IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject
)
/*++
Routine Description:
This routine completes the initialization of the mini redirector fromn the
RDBSS perspective. Note that this is different from the initialization done
in DriverEntry. Any initialization that depends on RDBSS should be done as
part of this routine while the initialization that is independent of RDBSS
should be done in the DriverEntry routine.
Arguments:
RxContext - Supplies the Irp that was used to startup the rdbss
Return Value:
RXSTATUS - The return status for the operation
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
return Status;
}
NTSTATUS
NulMRxStop(
PRX_CONTEXT RxContext,
IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject
)
/*++
Routine Description:
This routine is used to activate the mini redirector from the RDBSS perspective
Arguments:
RxContext - the context that was used to start the mini redirector
pContext - the null mini rdr context passed in at registration time.
Return Value:
RXSTATUS - The return status for the operation
--*/
{
NTSTATUS Status;
//DbgPrint("Entering NulMRxStop \n");
return(STATUS_SUCCESS);
}
NTSTATUS
NulMRxFsdDispatch (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This routine implements the FSD dispatch for the mini DRIVER object.
Arguments:
DeviceObject - Supplies the device object for the packet being processed.
Irp - Supplies the Irp being processed
Return Value:
RXSTATUS - The Fsd status for the Irp
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
ASSERT(DeviceObject==(PDEVICE_OBJECT)NulMRxDeviceObject);
if (DeviceObject!=(PDEVICE_OBJECT)NulMRxDeviceObject) {
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT );
return (STATUS_INVALID_DEVICE_REQUEST);
}
Status = RxFsdDispatch((PRDBSS_DEVICE_OBJECT)NulMRxDeviceObject,Irp);
return Status;
}
NTSTATUS
NulMRxGetUlongRegistryParameter(
HANDLE ParametersHandle,
PWCHAR ParameterName,
PULONG ParamUlong,
BOOLEAN LogFailure
)
/*++
Routine Description:
This routine is called to read a ULONG param from t he registry.
Arguments:
ParametersHandle - the handle of the containing registry "folder"
ParameterName - name of the parameter to be read
ParamUlong - where to store the value, if successful
LogFailure - if TRUE and the registry stuff fails, log an error
Return Value:
RXSTATUS - STATUS_SUCCESS
--*/
{
ULONG Storage[16];
PKEY_VALUE_PARTIAL_INFORMATION Value;
ULONG ValueSize;
UNICODE_STRING UnicodeString;
NTSTATUS Status;
ULONG BytesRead;
PAGED_CODE(); //INIT
Value = (PKEY_VALUE_PARTIAL_INFORMATION)Storage;
ValueSize = sizeof(Storage);
RtlInitUnicodeString(&UnicodeString, ParameterName);
Status = ZwQueryValueKey(ParametersHandle,
&UnicodeString,
KeyValuePartialInformation,
Value,
ValueSize,
&BytesRead);
if (NT_SUCCESS(Status)) {
if (Value->Type == REG_DWORD) {
PULONG ConfigValue = (PULONG)&Value->Data[0];
*ParamUlong = *((PULONG)ConfigValue);
DbgPrint("readRegistryvalue %wZ = %08lx\n",&UnicodeString,*ParamUlong);
return(STATUS_SUCCESS);
} else {
Status = STATUS_INVALID_PARAMETER;
}
}
if (LogFailure)
{
// log the failure...
}
return Status;
}
VOID
NulMRxReadRegistryParameters()
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING ParametersRegistryKeyName;
HANDLE ParametersHandle;
ULONG Temp = 0;
RtlInitUnicodeString(&ParametersRegistryKeyName, NULL_MINIRDR_PARAMETERS);
InitializeObjectAttributes(
&ObjectAttributes,
&ParametersRegistryKeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
);
Status = ZwOpenKey (&ParametersHandle, KEY_READ, &ObjectAttributes);
if (NT_SUCCESS(Status)) {
Status = NulMRxGetUlongRegistryParameter(ParametersHandle,
L"LogRate",
(PULONG)&Temp,
FALSE
);
if (NT_SUCCESS(Status)) {
LogRate = Temp;
// Check for bogus parameters.
if(LogRate > 10) {
LogRate = 10;
}
}
ZwClose(ParametersHandle);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -