function _DriverEntry(DriverObject:PDriverObject;RegistryPath:PUnicodeString):NTSTATUS; stdcall;
implementation
procedure DriverUnload(DriverObject:PDriverObject); stdcall; begin DbgPrint('DriverUnload(DriverObject:0x%.8X)',[DriverObject]); DbgPrint('DriverUnload(-)',[]); end;
function _DriverEntry(DriverObject:PDriverObject;RegistryPath:PUnicodeString):NTSTATUS; stdcall; begin DbgPrint('DriverEntry(DriverObject:0x%.8X;RegistryPath:0x%.8X)',[DriverObject,RegistryPath]);
function _DriverEntry(DriverObject:PDriverObject;pusRegistryPath:PUnicodeString):NTSTATUS; stdcall;
implementation
function _DriverEntry(DriverObject:PDriverObject;pusRegistryPath:PUnicodeString):NTSTATUS; stdcall; var status:NTSTATUS; oa:OBJECT_ATTRIBUTES; hKey:HANDLE; kvpi:KEY_VALUE_PARTIAL_INFORMATION; pIopm:PVOID; pProcess: PVOID; iRet: NTSTATUS; resultLen: ULONG; KeyValue: TUnicodeString; begin DbgPrint('giveio: Entering DriverEntry',[]); status := STATUS_DEVICE_CONFIGURATION_ERROR; InitializeObjectAttributes(oa, pusRegistryPath, 0, 0, nil); iRet := ZwOpenKey(hKey, KEY_READ, @oa); if iRet = STATUS_SUCCESS then begin RtlInitUnicodeString(KeyValue, 'ProcessId'); if (ZwQueryValueKey(hKey, @KeyValue, KeyValuePartialInformation, PVOID(@kvpi), sizeof(kvpi), resultLen) <> STATUS_OBJECT_NAME_NOT_FOUND) and (resultLen <> 0) then begin DbgPrint('giveio: Process ID: %X', [kvpi.dData]); {Allocate a buffer for the I/O permission map} pIopm := MmAllocateNonCachedMemory(IOPM_SIZE); if pIopm <> nil then begin if PsLookupProcessByProcessId(kvpi.dData, pProcess) = STATUS_SUCCESS then begin DbgPrint('giveio: PTR KPROCESS: %08X', [@pProcess]); iRet := Ke386QueryIoAccessMap(0, pIopm); if iRet and $ff <> 0 then begin {I/O access for 70h port} asm pushad mov ecx, pIopm add ecx, 70h / 8 mov eax, [ecx] btr eax, 70h MOD 8 mov [ecx], eax
iRet := Ke386SetIoAccessMap(1, pIopm); if iRet and $FF <> 0 then begin iRet := Ke386IoSetAccessProcess(pProcess, 1); if iRet and $FF <> 0 then begin DbgPrint('giveio: I/O permission is successfully given',[]); end else begin DbgPrint('giveio: I/O permission is failed',[]); status := STATUS_IO_PRIVILEGE_FAILED; end; end else begin status := STATUS_IO_PRIVILEGE_FAILED; end; end else begin status := STATUS_IO_PRIVILEGE_FAILED; end; ObfDereferenceObject(pProcess); end else begin status := STATUS_OBJECT_TYPE_MISMATCH; end; MmFreeNonCachedMemory(pIopm, IOPM_SIZE); end else begin DbgPrint('giveio: Call to MmAllocateNonCachedMemory failed',[]); status := STATUS_INSUFFICIENT_RESOURCES; end; end; ZwClose(hKey); end; DbgPrint('giveio: Leaving DriverEntry',[]); result := status; end;