Unit DriverCommands;

Interface

Uses
  Windows;

Type
  _OBJVIEW_OPEN_IN = Record
    NameLength : DWORD;
    Name : Packed Array [0..1] Of WideChar;
    end;
  OBJVIEW_OPEN_IN = _OBJVIEW_OPEN_IN;
  POBJVIEW_OPEN_IN = ^OBJVIEW_OPEN_IN;

  _OBJVIEW_HANDLE_32 = Record
    Handle : Integer;
    end;
  OBJVIEW_HANDLE_32 = _OBJVIEW_HANDLE_32;
  POBJVIEW_HANDLE2_32 = ^OBJVIEW_HANDLE_32;

  _OBJVIEW_HANDLE_64 = Record
    Handle : Int64;
    end;
  OBJVIEW_HANDLE_64 = _OBJVIEW_HANDLE_64;
  POBJVIEW_HANDLE_64 = ^OBJVIEW_HANDLE_64;

  _OBJVIEW_GET_HEADER_OUT_32 = Record
    NameInfoOffset : DWORD;
    HandleInfoOffset : DWORD;
    QuotaInfoOffset : DWORD;
    CreatorInfoOffset : DWORD;
    ProcessInfoOffset : DWORD;
    InfoMask : DWORD;
    HandleCount : Integer;
    PointerCount : Integer;
    Flags : DWORD;
    ExclusiveProcessId : Integer;
    CreatorProcessId : Integer;
    end;
  OBJVIEW_GET_HEADER_OUT_32 = _OBJVIEW_GET_HEADER_OUT_32;
  POBJVIEW_GET_HEADER_OUT_32 = ^OBJVIEW_GET_HEADER_OUT_32;

  _OBJVIEW_GET_HEADER_OUT_64 = Record
    NameInfoOffset : DWORD;
    HandleInfoOffset : DWORD;
    QuotaInfoOffset : DWORD;
    CreatorInfoOffset : DWORD;
    ProcessInfoOffset : DWORD;
    InfoMask : DWORD;
    HandleCount : Int64;
    PointerCount : Int64;
    Flags : DWORD;
    ExclusiveProcessId : Int64;
    CreatorProcessId : Int64;
    end;
  OBJVIEW_GET_HEADER_OUT_64 = _OBJVIEW_GET_HEADER_OUT_64;
  POBJVIEW_GET_HEADER_OUT_64 = ^OBJVIEW_GET_HEADER_OUT_64;

  _OBJVIEW_GET_NAME_INFO_OUT_32 = Record
    NameLength : DWORD;
    NameOffset : DWORD;
    FullName : Packed Array [0..1] Of WideChar;
    end;
  OBJVIEW_GET_NAME_INFO_OUT_32 = _OBJVIEW_GET_NAME_INFO_OUT_32;
  POBJVIEW_GET_NAME_INFO_OUT_32 = ^OBJVIEW_GET_NAME_INFO_OUT_32;

  _OBJVIEW_GET_NAME_INFO_OUT_64 = OBJVIEW_GET_NAME_INFO_OUT_32;
  OBJVIEW_GET_NAME_INFO_OUT_64 = _OBJVIEW_GET_NAME_INFO_OUT_64;
  POBJVIEW_GET_NAME_INFO_OUT_64 = ^OBJVIEW_GET_NAME_INFO_OUT_64;

  _OBJVIEW_GET_QUOTA_INFO_OUT_32 = Record
    PagedPoolCharge : DWORD;
    NonPagedPoolCharge : DWORD;
    SecurityDescriptorCharge : DWORD;
    ExclusiveProcessId : Integer;
    end;
  OBJVIEW_GET_QUOTA_INFO_OUT_32 = _OBJVIEW_GET_QUOTA_INFO_OUT_32;
  POBJVIEW_GET_QUOTA_INFO_OUT_32 = ^OBJVIEW_GET_QUOTA_INFO_OUT_32;

  _OBJVIEW_GET_QUOTA_INFO_OUT_64 = Record
    PagedPoolCharge : DWORD;
    NonPagedPoolCharge : DWORD;
    SecurityDescriptorCharge : DWORD;
    ExclusiveProcessId : Int64;
    end;
  OBJVIEW_GET_QUOTA_INFO_OUT_64 = _OBJVIEW_GET_QUOTA_INFO_OUT_64;
  POBJVIEW_GET_QUOTA_INFO_OUT_64 = ^OBJVIEW_GET_QUOTA_INFO_OUT_64;

  _OBJVIEW_HANDLE_ENTRY_32 = Packed Record
    ProcessId : Integer;
    HandleCount : Integer;
    end;
  OBJVIEW_HANDLE_ENTRY_32 = _OBJVIEW_HANDLE_ENTRY_32;
  POBJVIEW_HANDLE_ENTRY_32 = ^OBJVIEW_HANDLE_ENTRY_32;

  _OBJVIEW_HANDLE_ENTRY_64 = Packed Record
    ProcessId : Int64;
    HandleCount : Int64;
    end;
  OBJVIEW_HANDLE_ENTRY_64 = _OBJVIEW_HANDLE_ENTRY_64;
  POBJVIEW_HANDLE_ENTRY_64 = ^OBJVIEW_HANDLE_ENTRY_64;

  _OBJVIEW_GET_HANDLE_INFO_OUT_32 = Record
    Count : Integer;
    Entries : Array [0..1] Of OBJVIEW_HANDLE_ENTRY_32;
    end;
  OBJVIEW_GET_HANDLE_INFO_OUT_32 = _OBJVIEW_GET_HANDLE_INFO_OUT_32;
  POBJVIEW_GET_HANDLE_INFO_OUT_32 = ^OBJVIEW_GET_HANDLE_INFO_OUT_32;

  _OBJVIEW_GET_HANDLE_INFO_OUT_64 = Record
    Count : Int64;
    Entries : Array [0..1] Of OBJVIEW_HANDLE_ENTRY_64;
    end;
  OBJVIEW_GET_HANDLE_INFO_OUT_64 = _OBJVIEW_GET_HANDLE_INFO_OUT_64;
  POBJVIEW_GET_HANDLE_INFO_OUT_64 = ^OBJVIEW_GET_HANDLE_INFO_OUT_64;

  _OBJVIEW_GET_CREATOR_INFO_OUT_32 = Record
    CreatorProcessId : Integer;
    end;
  OBJVIEW_GET_CREATOR_INFO_OUT_32 = _OBJVIEW_GET_CREATOR_INFO_OUT_32;
  POBJVIEW_GET_CREATOR_INFO_OUT_32 = ^OBJVIEW_GET_CREATOR_INFO_OUT_32;

  _OBJVIEW_GET_CREATOR_INFO_OUT_64 = Record
    CreatorProcessId : Int64;
    end;
  OBJVIEW_GET_CREATOR_INFO_OUT_64 = _OBJVIEW_GET_CREATOR_INFO_OUT_64;
  POBJVIEW_GET_CREATOR_INFO_OUT_64 = ^OBJVIEW_GET_CREATOR_INFO_OUT_64;

  OBJECT_INITIALIZER_FLAGS_32 = Record
    CaseSensitive : DWORD;
    UseDefaultObject : DWORD;
    MaintainHandleCount : DWORD;
    MaintainTypeList : DWORD;
    UnnamedObjectsOnly : DWORD;
    SupportsObjectCallbacks : DWORD;
    SecurityRequired : DWORD;
    end;

  OBJECT_INITIALIZER_FLAGS_64 = OBJECT_INITIALIZER_FLAGS_32;

  OBJECT_INITIALIZER_METHODS_32 = Record
    Open : Integer;
    Close : Integer;
    OkayToClose : Integer;
    Delete : Integer;
    Parse : Integer;
    QueryName : Integer;
    Security : Integer;
    Dump : Integer;
    end;

  OBJECT_INITIALIZER_METHODS_64 = Record
    Open : Int64;
    Close : Int64;
    OkayToClose : Int64;
    Delete : Int64;
    Parse : Int64;
    QueryName : Int64;
    Security : Int64;
    Dump : Int64;
    end;

  OBJECT_INITIALIZER_OTHER_INFO_32 = Record
    DefaultPagedPoolCharge : DWORD;
    DefaultNonPagedPoolCharge : DWORD;
    ObjectTypeCode : DWORD;
    ValidAccessMask : DWORD;
    InvalidAttributes : DWORD;
    RetainAccess : DWORD;
    GenericMapping : Packed Array [0..3] Of DWORD;
    PoolType : DWORD;
    end;

  OBJECT_INITIALIZER_OTHER_INFO_64 = OBJECT_INITIALIZER_OTHER_INFO_32;

  OBJECT_TYPE_STATISTICS_32 = Record
    TotalNumberOfObjects : DWORD;
    TotalNumberOfHandles : DWORD;
    HighWaterNumberOfObjects : DWORD;
    HighWaterNumberOfHandles : DWORD;
    end;

  OBJECT_TYPE_STATISTICS_64 = OBJECT_TYPE_STATISTICS_32;

  _OBJVIEW_GET_TYPE_INFO_OUT_32 = Record
    InitializerFlags : OBJECT_INITIALIZER_FLAGS_32;
    InitializerMethods : OBJECT_INITIALIZER_METHODS_32;
    InitializerOtherInfo : OBJECT_INITIALIZER_OTHER_INFO_32;
    TypeStatistics : OBJECT_TYPE_STATISTICS_32;
    Index : DWORD;
    Key : DWORD;
    DefaultObject : Integer;
    NameLength : DWORD;
    Name : Packed Array [0..1] Of WideChar;
    end;
  OBJVIEW_GET_TYPE_INFO_OUT_32 = _OBJVIEW_GET_TYPE_INFO_OUT_32;
  POBJVIEW_GET_TYPE_INFO_OUT_32 = ^OBJVIEW_GET_TYPE_INFO_OUT_32;

  _OBJVIEW_GET_TYPE_INFO_OUT_64 = Record
    InitializerFlags : OBJECT_INITIALIZER_FLAGS_64;
    InitializerMethods : OBJECT_INITIALIZER_METHODS_64;
    InitializerOtherInfo : OBJECT_INITIALIZER_OTHER_INFO_64;
    TypeStatistics : OBJECT_TYPE_STATISTICS_64;
    Index : DWORD;
    Key : DWORD;
    DefaultObject : Int64;
    NameLength : DWORD;
    Name : Packed Array [0..1] Of WideChar;
    end;
  OBJVIEW_GET_TYPE_INFO_OUT_64 = _OBJVIEW_GET_TYPE_INFO_OUT_64;
  POBJVIEW_GET_TYPE_INFO_OUT_64 = ^OBJVIEW_GET_TYPE_INFO_OUT_64;

   _OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32 = Record
     EventType : DWORD;
     Signaled : DWORD;
     end;
   OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32 = _OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32;
   POBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32 = ^OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32;

   _OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_32;
   OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_64;
   POBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_64 = ^OBJVIEW_GET_EVENT_SPECIFIC_INFO_OUT_64;

   _OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_32 = Record
     OwnerThreadId : Integer;
     Signaled : DWORD;
     Abandoned : Boolean;
     end;
   OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_32 = _OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_32;
   POBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_32 = ^OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_32;

   _OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_64 = Record
     OwnerThreadId : Int64;
     Signaled : DWORD;
     Abandoned : Boolean;
     end;
   OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_64;
   POBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_64 = ^OBJVIEW_GET_MUTANT_SPECIFIC_INFO_OUT_64;

   _OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32 = Record
     Counter : DWORD;
     Limit : DWORD;
     end;
   OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32 = _OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32;
   POBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32 = ^OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32;

   _OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_32;
   OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_64;
   POBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_64 = ^OBJVIEW_GET_SEMAPHORE_SPECIFIC_INFO_OUT_64;

   _OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_32 = _OBJVIEW_GET_TYPE_INFO_OUT_32;
   OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_32 = _OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_32;
   POBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_32 = ^OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_32;

   _OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_TYPE_INFO_OUT_64;
   OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_64 = _OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_64;
   POBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_64 = ^OBJVIEW_GET_TYPE_SPECIFIC_INFO_OUT_64;


Function ObjviewOpenObject32(ObjectName:WideString):Integer;
Function ObjviewCloseObject32(ObjectHandle:Integer):Boolean;
Function ObjviewGetObjectHeader32(ObjectHandle:Integer; ObjectHeader:POBJVIEW_GET_HEADER_OUT_32):Boolean;
Function ObjviewGetObjectQuotaInfo32(ObjectHandle:Integer; ObjectQuotaInfo:POBJVIEW_GET_QUOTA_INFO_OUT_32):Boolean;
Function ObjviewGetCreatorInfo32(ObjectHandle:Integer; ObjectCreatorInfo:POBJVIEW_GET_CREATOR_INFO_OUT_32):Boolean;
Function ObjviewGetNameInfo32(ObjectHandle:Integer; Var Name:WideString; Var FullName:WideString):Boolean;
Function ObjviewGetHandleInfo32(ObjectHandle:Integer; ObjectHandleInfo:POBJVIEW_GET_HANDLE_INFO_OUT_32; Length:DWORD):Boolean;
Function ObjviewGetTypeInfo32(ObjectHandle:Integer; ObjectTypeInfo:POBJVIEW_GET_TYPE_INFO_OUT_32; Length:DWORD):Boolean;
Function ObjviewGetSpecificInfo32(Objecthandle:Integer; ObjectInfo:Pointer; Length:DWORD):Boolean;

Function ObjviewOpenObject64(ObjectName:WideString):Int64;
Function ObjviewCloseObject64(ObjectHandle:Int64):Boolean;
Function ObjviewGetObjectHeader64(ObjectHandle:Int64; ObjectHeader:POBJVIEW_GET_HEADER_OUT_64):Boolean;
Function ObjviewGetObjectQuotaInfo64(ObjectHandle:Int64; ObjectQuotaInfo:POBJVIEW_GET_QUOTA_INFO_OUT_64):Boolean;
Function ObjviewGetCreatorInfo64(ObjectHandle:Int64; ObjectCreatorInfo:POBJVIEW_GET_CREATOR_INFO_OUT_64):Boolean;
Function ObjviewGetNameInfo64(ObjectHandle:Int64; Var Name:WideString; Var FullName:WideString):Boolean;
Function ObjviewGetHandleInfo64(ObjectHandle:Int64; ObjectHandleInfo:POBJVIEW_GET_HANDLE_INFO_OUT_64; Length:DWORD):Boolean;
Function ObjviewGetTypeInfo64(ObjectHandle:Int64; ObjectTypeInfo:POBJVIEW_GET_TYPE_INFO_OUT_64; Length:DWORD):Boolean;
Function ObjviewGetSpecificInfo64(Objecthandle:Int64; ObjectInfo:Pointer; Length:DWORD):Boolean;


Function ObjviewLoad:Boolean;
Function ObjViewUnload:Boolean;
Function ObjviewInit:Boolean;
Procedure ObjviewFinit;

Implementation

Uses
  Driver, Utils, SysUtils;

Const
  IOCTL_OBJVIEW_OPEN = $c07fc004;
  IOCTL_OBJVIEW_CLOSE = $c07fc008;
  IOCTL_OBJVIEW_GET_HEADER = $c07fc00C;
  IOCTL_OBJVIEW_GET_HANDLE_INFO = $c07fc010;
  IOCTL_OBJVIEW_GET_QUOTA_INFO = $c07fc014;
  IOCTL_OBJVIEW_GET_NAME_INFO = $c07fc018;
  IOCTL_OBJVIEW_GET_CREATOR_INFO = $c07fc01C;
  IOCTL_OBJVIEW_GET_SPECIFIC_INFO = $c07fc020;
  IOCTL_OBJVIEW_GET_TYPE_INFO = $c07fc024;

  IOCTL_OPEN_INDEX = 0;
  IOCTL_CLOSE_INDEX = 1;
  IOCTL_GET_HEADER_INDEX = 2;
  IOCTL_GET_HANDLE_INFO_INDEX = 3;
  IOCTL_GET_QUOTA_INFO_INDEX = 4;
  IOCTL_GET_NAME_INFO_INDEX = 5;
  IOCTL_GET_CREATOR_INFO_INDEX = 6;
  IOCTL_GET_SPECIFIC_INFO_INDEX = 7;
  IOCTL_GET_TYPE_INFO_INDEX = 8;

Function ObjviewOpenObject32(ObjectName:WideString):Integer;
Var
  NameLength : Integer;
  OpenIn : POBJVIEW_OPEN_IN;
  OpenInLength : Integer;
  OpenOut : Integer;
  Ret : Boolean;
begin
Result := 0;
NameLength := Length(ObjectName) * SizeOf(WideChar);
OpenInLength := SizeOf(OBJVIEW_OPEN_IN) + NameLength;
OpenIn := HeapAlloc(GetProcessHeap, 0, OpenInLength);
If Assigned(OpenIn) Then
  begin
  ZeroMemory(OpenIn, OpenInLength);
  OpenIn.NameLength := NameLength;
  CopyMemory(@OpenIn.Name, PWideChar(ObjectName), NameLength);
  Ret := DriverIOCTL(IOCTL_OPEN_INDEX, OpenIn, OpenInLength, @OpenOut, SizeOf(OpenOut));
  If Ret Then
    Result := OpenOut;

  HeapFree(GetProcessHeap, 0, OpenIn);
  end;
end;

Function ObjviewOpenObject64(ObjectName:WideString):Int64;
Var
  NameLength : Integer;
  OpenIn : POBJVIEW_OPEN_IN;
  OpenInLength : Integer;
  OpenOut : Int64;
  Ret : Boolean;
begin
Result := 0;
NameLength := Length(ObjectName) * SizeOf(WideChar);
OpenInLength := SizeOf(OBJVIEW_OPEN_IN) + NameLength;
OpenIn := HeapAlloc(GetProcessHeap, 0, OpenInLength);
If Assigned(OpenIn) Then
  begin
  ZeroMemory(OpenIn, OpenInLength);
  OpenIn.NameLength := NameLength;
  CopyMemory(@OpenIn.Name, PWideChar(ObjectName), NameLength);
  Ret := DriverIOCTL(IOCTL_OPEN_INDEX, OpenIn, OpenInLength, @OpenOut, SizeOf(OpenOut));
  If Ret Then
    Result := OpenOut;

  HeapFree(GetProcessHeap, 0, OpenIn);
  end;
end;

Function ObjviewCloseObject32(ObjectHandle:Integer):Boolean;
begin
Result := DriverIOCTL(IOCTL_CLOSE_INDEX, @ObjectHandle, SizeOf(ObjectHandle), Nil, 0);
end;

Function ObjviewCloseObject64(ObjectHandle:Int64):Boolean;
begin
Result := DriverIOCTL(IOCTL_CLOSE_INDEX, @ObjectHandle, SizeOf(ObjectHandle), Nil, 0);
end;

Function ObjviewGetObjectHeader32(ObjectHandle:Integer; ObjectHeader:POBJVIEW_GET_HEADER_OUT_32):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_HEADER_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectHeader, SizeOf(OBJVIEW_GET_HEADER_OUT_32));
end;

Function ObjviewGetObjectHeader64(ObjectHandle:Int64; ObjectHeader:POBJVIEW_GET_HEADER_OUT_64):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_HEADER_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectHeader, SizeOf(OBJVIEW_GET_HEADER_OUT_64));
end;

Function ObjviewGetObjectQuotaInfo32(ObjectHandle:Integer; ObjectQuotaInfo:POBJVIEW_GET_QUOTA_INFO_OUT_32):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_QUOTA_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectQuotaInfo, SizeOf(OBJVIEW_GET_QUOTA_INFO_OUT_32));
end;

Function ObjviewGetObjectQuotaInfo64(ObjectHandle:Int64; ObjectQuotaInfo:POBJVIEW_GET_QUOTA_INFO_OUT_64):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_QUOTA_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectQuotaInfo, SizeOf(OBJVIEW_GET_QUOTA_INFO_OUT_64));
end;

Function ObjviewGetCreatorInfo32(ObjectHandle:Integer; ObjectCreatorInfo:POBJVIEW_GET_CREATOR_INFO_OUT_32):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_CREATOR_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectCreatorInfo, SizeOf(OBJVIEW_GET_CREATOR_INFO_OUT_32));
end;

Function ObjviewGetCreatorInfo64(ObjectHandle:Int64; ObjectCreatorInfo:POBJVIEW_GET_CREATOR_INFO_OUT_64):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_CREATOR_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectCreatorInfo, SizeOf(OBJVIEW_GET_CREATOR_INFO_OUT_64));
end;

Function ObjviewGetNameInfo32(ObjectHandle:Integer; Var Name:WideString; Var FullName:WideString):Boolean;
Var
  Error : Boolean;
  NameOut : POBJVIEW_GET_NAME_INFO_OUT_32;
  NameOutLength : DWORD;
begin
NameOut := Nil;
Result := False;
NameOutLength := 128 * SizeOf(WideChar);
Error := True;
While Error Do
  begin
  NameOutLength := NameOutLength * 2;
  If Assigned(NameOut) Then
    HeapFree(GetProcessHeap, 0, NameOut);

  NameOut := HeapAlloc(GetProcessHeap, 0, NameOutLength);
  If Assigned(NameOut) Then
    begin
    Error := Not DriverIOCTL(IOCTL_GET_NAME_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), NameOut, NameOutLength);
    If (Error) And (GetLastError <> 122) Then
      begin
      Utils.Error(Format('Driver I/O error: %s (%d)', [SysErrorMessage(GetLastError), GetLastError]));
      Break;
      end;
    end
  Else Break;
  end;

Result := Not Error;
If Result Then
  begin
  FullName := Copy(PWideChar(@NameOut.FullName), 1, NameOut.NameLength Div SizeOf(WideChar));
  Name := Copy(PWideChar(@NameOut.FullName[NameOut.NameOffset]), 1, (NameOut.NameLength Div SizeOf(WideChar)) - NameOut.NameOffset);
  HeapFree(GetProcessHeap, 0, NameOut);
  end;
end;

Function ObjviewGetNameInfo64(ObjectHandle:Int64; Var Name:WideString; Var FullName:WideString):Boolean;
Var
  Error : Boolean;
  NameOut : POBJVIEW_GET_NAME_INFO_OUT_64;
  NameOutLength : DWORD;
begin
NameOut := Nil;
Result := False;
NameOutLength := 128 * SizeOf(WideChar);
Error := True;
While Error Do
  begin
  NameOutLength := NameOutLength * 2;
  If Assigned(NameOut) Then
    HeapFree(GetProcessHeap, 0, NameOut);

  NameOut := HeapAlloc(GetProcessHeap, 0, NameOutLength);
  If Assigned(NameOut) Then
    begin
    Error := Not DriverIOCTL(IOCTL_GET_NAME_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), NameOut, NameOutLength);
    If (Error) And (GetLastError <> 122) Then
      begin
      Utils.Error(Format('Driver I/O error: %s (%d)', [SysErrorMessage(GetLastError), GetLastError]));
      Break;
      end;
    end
  Else Break;
  end;

Result := Not Error;
If Result Then
  begin
  FullName := Copy(PWideChar(@NameOut.FullName), 1, NameOut.NameLength Div SizeOf(WideChar));
  Name := Copy(PWideChar(@NameOut.FullName[NameOut.NameOffset]), 1, (NameOut.NameLength Div SizeOf(WideChar)) - NameOut.NameOffset);
  HeapFree(GetProcessHeap, 0, NameOut);
  end;
end;

Function ObjviewGetHandleInfo32(ObjectHandle:Integer; ObjectHandleInfo:POBJVIEW_GET_HANDLE_INFO_OUT_32; Length:DWORD):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_HANDLE_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectHandleInfo, Length);
end;

Function ObjviewGetHandleInfo64(ObjectHandle:Int64; ObjectHandleInfo:POBJVIEW_GET_HANDLE_INFO_OUT_64; Length:DWORD):Boolean;
begin
Result := DriverIOCTL(IOCTL_GET_HANDLE_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectHandleInfo, Length);
end;

Function ObjviewGetTypeInfo32(ObjectHandle:Integer; ObjectTypeInfo:POBJVIEW_GET_TYPE_INFO_OUT_32; Length:DWORD):Boolean;
begin
ZeroMemory(ObjectTypeInfo, Length);
Result := DriverIOCTL(IOCTL_GET_TYPE_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectTypeInfo, Length);
end;

Function ObjviewGetTypeInfo64(ObjectHandle:Int64; ObjectTypeInfo:POBJVIEW_GET_TYPE_INFO_OUT_64; Length:DWORD):Boolean;
begin
ZeroMemory(ObjectTypeInfo, Length);
Result := DriverIOCTL(IOCTL_GET_TYPE_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectTypeInfo, Length);
end;

Function ObjviewGetSpecificInfo32(Objecthandle:Integer; ObjectInfo:Pointer; Length:DWORD):Boolean;
begin
ZeroMemory(ObjectInfo, Length);
Result := DriverIOCTL(IOCTL_GET_SPECIFIC_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectInfo, Length);
end;

Function ObjviewGetSpecificInfo64(Objecthandle:Int64; ObjectInfo:Pointer; Length:DWORD):Boolean;
begin
ZeroMemory(ObjectInfo, Length);
Result := DriverIOCTL(IOCTL_GET_SPECIFIC_INFO_INDEX, @ObjectHandle, SizeOf(ObjectHandle), ObjectInfo, Length);
end;

Function ObjviewLoad:Boolean;
begin
Result := DriverLoad;
If Result Then
  Result := DriverConnect;
end;

Function ObjViewUnload:Boolean;
begin
If DriverConnected Then
  DriverDisconnect;

Result := DriverUnload;
end;

Function ObjviewInit:Boolean;
begin
DriverInit('objview', ExtractFilePath(ParamStr(0)) + 'objview.sys', 'objview',
    [IOCTL_OBJVIEW_OPEN, IOCTL_OBJVIEW_CLOSE, IOCTL_OBJVIEW_GET_HEADER, IOCTL_OBJVIEW_GET_HANDLE_INFO,
     IOCTL_OBJVIEW_GET_QUOTA_INFO, IOCTL_OBJVIEW_GET_NAME_INFO, IOCTL_OBJVIEW_GET_CREATOR_INFO,
     IOCTL_OBJVIEW_GET_SPECIFIC_INFO, IOCTL_OBJVIEW_GET_TYPE_INFO]);
end;

Procedure ObjviewFinit;
begin
DriverFinit;
end;

End.

