IopOpenLinkOrRenameTarget

NTSTATUS __stdcall IopOpenLinkOrRenameTarget(
        PVOID *TargetHandle,
        _IRP *Irp,
        PVOID RenameBuffer,
        _FILE_OBJECT *FileObject){
  bool v4; 
  unsigned int v8; 
  VOID *v10; 
  NTSTATUS result; 
  VOID *v12; 
  _IO_STACK_LOCATION *CurrentStackLocation; 
  char v14; 
  char v15; 
  void **FileObjectExtension; 
  _FILE_OBJECT *v17; 
  VOID **v18; 
  UINT64 v19; 
  int v20; 
  PVOID v21; 
  __int64 v22; 
  __int64 v23; 
  __int64 v24; 
  UINT64 FileAttributes; 
  UINT64 ShareAccess; 
  UINT64 Disposition; 
  UINT64 CreateOptions; 
  UINT64 EaLength; 
  UINT64 Options; 
  PVOID FileHandle; 
  VOID *KernelHandle; 
  PVOID Object; 
  __int16 v34[2]; 
  int v35; 
  __int64 v36; 
  _IO_DRIVER_CREATE_CONTEXT DriverContext; 
  _OBJECT_HANDLE_INFORMATION HandleInformation; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  _FILE_BASIC_INFORMATION BasicInformationBuffer; 

  FileHandle = 0i64;
  v4 = (FileObject->Flags & 0x800) == 0;
  KernelHandle = 0i64;
  *(&ObjectAttributes.Length + 1) = 0;
  v8 = 2;
  *(&ObjectAttributes.Attributes + 1) = 0;
  v35 = 0;
  IoStatusBlock = 0i64;
  v10 = 0i64;
  HandleInformation = 0i64;
  memset(&BasicInformationBuffer, 0, sizeof(BasicInformationBuffer));
  memset(&DriverContext.Size + 1, 0, 22);
  if( v4 )
  {
    result = IopGetBasicInformationFile(FileObject, &BasicInformationBuffer);
    if( result < 0 )
      return result;
    if( (BasicInformationBuffer.FileAttributes & 0x10) != 0 )
      v8 = 4;
  }
  v12 = (VOID *)*((_QWORD *)RenameBuffer + 1);
  if( v12 )
  {
    if( KeGetCurrentThread()->PreviousMode == 1 )
    {
      result = IoConvertFileHandleToKernelHandle(v12, 1, 0i64, 0, &KernelHandle);
      if( result < 0 )
        return result;
      v10 = KernelHandle;
    }
    else
    {
      v10 = (VOID *)*((_QWORD *)RenameBuffer + 1);
      KernelHandle = v10;
    }
  }
  CurrentStackLocation = Irp->Tail.CurrentStackLocation;
  v34[0] = *((_WORD *)RenameBuffer + 8);
  v34[1] = v34[0];
  v36 = (__int64)RenameBuffer + 20;
  v14 = ~(unsigned __int8)(FileObject->Flags >> 11);
  ObjectAttributes.Length = 48;
  ObjectAttributes.RootDirectory = v10;
  v15 = ~CurrentStackLocation[-1].Flags;
  DriverContext.SiloContext = (_EJOB *)1;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)v34;
  ObjectAttributes.Attributes = v14 & 0x40 | ((v15 & 1) << 10) | 0x200;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  DriverContext.Size = 40;
  memset(&DriverContext.Size + 1, 0, 22);
  FileObjectExtension = (void **)IopGetFileObjectExtension(FileObject, FoExtTypeInternal, 0i64);
  if( FileObjectExtension )
    DriverContext.DeviceObjectHint = *FileObjectExtension;
  DriverContext.TxnParameters = (_TXN_PARAMETER_BLOCK *)IopGetFileObjectExtension(v17, FoExtTypeTransactionParams, v18);
  v19 = v8;
  LODWORD(v19) = v8 | 0x100000;
  LODWORD(Options) = ((CurrentStackLocation[-1].Flags & 1) == 0) | 0x104;
  LODWORD(EaLength) = 0;
  LODWORD(CreateOptions) = 0x4000;
  LODWORD(Disposition) = 1;
  LODWORD(ShareAccess) = 3;
  LODWORD(FileAttributes) = 0;
  v20 = IoCreateFileEx(
          &FileHandle,
          v19,
          &ObjectAttributes,
          &IoStatusBlock,
          0i64,
          FileAttributes,
          ShareAccess,
          Disposition,
          CreateOptions,
          0i64,
          EaLength,
          CreateFileTypeNone,
          0i64,
          Options,
          &DriverContext);
  if( v20 >= 0 )
  {
    Object = 0i64;
    v20 = ObReferenceObjectByHandle(FileHandle, v8, (_OBJECT_TYPE *)IoFileObjectType, 0, &Object, &HandleInformation);
    if( v20 < 0 )
    {
      ObCloseHandle(FileHandle, 0);
    }
    else
    {
      v21 = Object;
      HalPutDmaAdapter((PADAPTER_OBJECT)Object);
      LODWORD(v22) = IoGetRelatedDeviceObject((INT64)FileObject);
      v23 = v22;
      LODWORD(v24) = IoGetRelatedDeviceObject((INT64)v21);
      if( v24 == v23 )
      {
        *(_QWORD *)&CurrentStackLocation[-1].Parameters.FileAttributes = v21;
        v20 = 0;
        *TargetHandle = FileHandle;
      }
      else
      {
        ObCloseHandle(FileHandle, 0);
        v20 = -1073741612;
      }
    }
  }
  if( v10 )
  {
    if( KeGetCurrentThread()->PreviousMode == 1 )
      ObCloseHandle(KernelHandle, 0);
  }
  return v20;
}

Referenced by:

IoSetInformation
NtSetInformationFile