/// <include file='Windows.xml' path='doc/member[@name="Windows.DeviceDsmInitializeInput"]/*' /> public static void DeviceDsmInitializeInput([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("PDEVICE_DSM_INPUT")] DEVICE_MANAGE_DATA_SET_ATTRIBUTES *Input, [NativeTypeName("DWORD")] uint InputLength, [NativeTypeName("DWORD")] uint Flags, [NativeTypeName("PVOID")] void *Parameters, [NativeTypeName("DWORD")] uint ParameterBlockLength) { uint Bytes = 28; Unsafe.InitBlockUnaligned((Input), 0, (InputLength)); Input->Size = unchecked (Bytes); Input->Action = Definition->Action; Input->Flags = Flags; if (ParameterBlockLength == 0) { goto Cleanup; } unchecked (Bytes) = unchecked (((Bytes) + ((Definition->ParameterBlockAlignment) - 1)) / (Definition->ParameterBlockAlignment) * (Definition->ParameterBlockAlignment)); Input->ParameterBlockOffset = unchecked (Bytes); Input->ParameterBlockLength = ParameterBlockLength; if (Parameters == null) { goto Cleanup; } Unsafe.CopyBlockUnaligned((DeviceDsmParameterBlock(Input)), (Parameters), (Input->ParameterBlockLength)); Cleanup: return; }
public static uint DeviceDsmGetOutputLength([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("DWORD")] uint OutputBlockLength) { uint Bytes = 0; if (Definition->HasOutput == 0) { goto Cleanup; } Bytes = unchecked ((uint)(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES_OUTPUT))); if (Definition->OutputBlockLength == 0) { goto Cleanup; } if (Definition->OutputBlockLength > OutputBlockLength) { OutputBlockLength = Definition->OutputBlockLength; } Bytes = (((Bytes) + ((Definition->OutputBlockAlignment) - 1)) / (Definition->OutputBlockAlignment) * (Definition->OutputBlockAlignment)); Bytes += OutputBlockLength; Cleanup: return(Bytes); }
public static void DeviceDsmInitializeOutput([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("PDEVICE_DSM_OUTPUT")] DEVICE_MANAGE_DATA_SET_ATTRIBUTES_OUTPUT *Output, [NativeTypeName("DWORD")] uint OutputLength, [NativeTypeName("DWORD")] uint Flags) { uint Bytes = 36; Unsafe.InitBlockUnaligned((Output), 0, (OutputLength)); Output->Size = unchecked (Bytes); Output->Action = Definition->Action; Output->Flags = Flags; if (Definition->OutputBlockLength != 0) { unchecked (Bytes) = unchecked (((Bytes) + ((Definition->OutputBlockAlignment) - 1)) / (Definition->OutputBlockAlignment) * (Definition->OutputBlockAlignment)); Output->OutputBlockOffset = unchecked (Bytes); Output->OutputBlockLength = unchecked (OutputLength - Bytes); } return; }
public static byte DeviceDsmValidateOutput([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("PDEVICE_DSM_OUTPUT")] DEVICE_MANAGE_DATA_SET_ATTRIBUTES_OUTPUT *Output, [NativeTypeName("DWORD")] uint OutputLength) { uint Max = 0; uint Min = 0; byte Valid = 0; if (Definition->Action != Output->Action) { goto Cleanup; } if (Definition->HasOutput == 0) { goto Cleanup; } if (Definition->OutputBlockLength != 0) { Min = unchecked ((uint)(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES_OUTPUT))); Max = OutputLength; if (Output->OutputBlockOffset < Min || Output->OutputBlockOffset > Max || (Output->OutputBlockOffset % Definition->OutputBlockAlignment) != 0) { goto Cleanup; } Min = Definition->OutputBlockLength; Max = OutputLength - Output->OutputBlockOffset; if (Output->OutputBlockLength < Min || Output->OutputBlockLength > Max) { goto Cleanup; } } else { if (Output->OutputBlockOffset != 0 || Output->OutputBlockLength != 0) { goto Cleanup; } } Valid = 1; Cleanup: return(Valid); }
public static byte DeviceDsmValidateInput([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("PDEVICE_DSM_INPUT")] DEVICE_MANAGE_DATA_SET_ATTRIBUTES *Input, [NativeTypeName("DWORD")] uint InputLength) { uint Max = 0; uint Min = 0; byte Valid = 0; if (Definition->Action != Input->Action) { goto Cleanup; } if (Definition->ParameterBlockLength != 0) { Min = unchecked ((uint)(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES))); Max = InputLength; if (Input->ParameterBlockOffset < Min || Input->ParameterBlockOffset > Max || (Input->ParameterBlockOffset % Definition->ParameterBlockAlignment) != 0) { goto Cleanup; } Min = Definition->ParameterBlockLength; Max = InputLength - Input->ParameterBlockOffset; if (Input->ParameterBlockLength < Min || Input->ParameterBlockLength > Max) { goto Cleanup; } } if ((Input->Flags & 0x00000001) == 0) { Min = unchecked ((uint)(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES))); Max = InputLength; if (Input->DataSetRangesOffset < Min || Input->DataSetRangesOffset > Max || (Input->DataSetRangesOffset % 8) != 0) { goto Cleanup; } Min = unchecked ((uint)(sizeof(DEVICE_DATA_SET_RANGE))); Max = InputLength - Input->DataSetRangesOffset; if (Input->DataSetRangesLength < Min || Input->DataSetRangesLength > Max || (Input->DataSetRangesLength % Min) != 0) { goto Cleanup; } if ((Definition->SingleRange) != 0 && Input->DataSetRangesLength != Min) { goto Cleanup; } } else { if (Input->DataSetRangesOffset != 0 || Input->DataSetRangesLength != 0) { goto Cleanup; } } if (Input->ParameterBlockOffset < Input->DataSetRangesOffset && Input->ParameterBlockOffset + Input->ParameterBlockLength > Input->DataSetRangesOffset) { goto Cleanup; } if (Input->DataSetRangesOffset < Input->ParameterBlockOffset && Input->DataSetRangesOffset + Input->DataSetRangesLength > Input->ParameterBlockOffset) { goto Cleanup; } Valid = 1; Cleanup: return(Valid); }
public static byte DeviceDsmValidateOutputLength([NativeTypeName("PDEVICE_DSM_DEFINITION")] DEVICE_DSM_DEFINITION *Definition, [NativeTypeName("DWORD")] uint OutputLength) { uint Bytes = DeviceDsmGetOutputLength(Definition, 0); return((byte)((OutputLength >= Bytes) ? 1 : 0)); }