IopSetFileObjectIosbRange

NTSTATUS __stdcall IopSetFileObjectIosbRange(const VOID *FileObject, _IRP *Irp){
  VOID **i; 
  VOID **v3; 
  int v4; 
  _EPROCESS *Process; 
  union {_IRP *MasterIrp;int IrpCount;void *SystemBuffer;} v6; 
  __int64 MdlAddress_low; 
  char *v9; 
  VOID *inserted; 
  _QWORD *v11; 
  INT64 v12; 
  _MDL *Mdl; 
  char v14; 
  _EWOW64PROCESS *WoW64Process; 
  unsigned __int16 Machine; 
  _KPROCESSOR_MODE v17; 
  VOID *MappedSystemVa; 
  VOID **PoolWithTag; 
  int v20; 
  _FILE_OBJECT_EXTENSION_TYPE v21; 
  _QWORD *FileObjectExtension; 
  _QWORD *v23; 
  signed __int64 v24; 
  signed __int64 v25; 
  UINT64 v26; 
  UINT64 Priority; 
  _MDL *MemoryDescriptorList; 
  VOID *BaseAddress; 
  _EPROCESS **v30; 
  _EPROCESS *Object; 
  VOID *FoExt[6]; 
  __int64 Buffer[9]; 
  char v36; 
  UINT8 NewElement; 

  FoExt[0] = 0i64;
  v36 = 0;
  NewElement = 0;
  i = 0i64;
  Buffer[1] = 0i64;
  v3 = 0i64;
  FoExt[2] = 0i64;
  MemoryDescriptorList = 0i64;
  BaseAddress = 0i64;
  v4 = 0;
  Process = KeGetCurrentThread()->ApcState.Process;
  Object = Process;
  FoExt[5] = Process;
  v6.MasterIrp = (_IRP *)Irp->AssociatedIrp;
  MdlAddress_low = LODWORD(v6.MasterIrp->MdlAddress);
  if( !(_DWORD)MdlAddress_low )
    return -1073741811;
  v9 = *(char **)&v6.MasterIrp->Type;
  FoExt[3] = v9;
  ExAcquireFastMutex((PFAST_MUTEX)((char *)&stru_140C452E0 + 2784));
  Buffer[0] = (__int64)Process;
  inserted = RtlInsertElementGenericTableAvl(
               (_RTL_AVL_TABLE *)((char *)&stru_140C452E0 + 2656),
               Buffer,
               0x10ui64,
               &NewElement);
  v30 = (_EPROCESS **)inserted;
  if( !inserted )
  {
    v4 = -1073741670;
    Mdl = 0i64;
    v14 = 0;
LABEL_58:
    if( Mdl )
    {
      if( BaseAddress )
        MmUnmapLockedPages(BaseAddress, Mdl);
      MmUnlockPages((INT64)Mdl, (INT64)v11, v12);
      IoFreeMdl(Mdl);
    }
    if( v3 )
    {
      ObfDereferenceObjectWithTag(Object, 0x70436F49ui64);
      ExFreePoolWithTag(v3, 0);
    }
    if( NewElement == 1 )
      RtlDeleteElementGenericTableAvl((PRTL_AVL_TABLE)((char *)&stru_140C452E0 + 2656), Buffer);
    if( v14 == 1 )
      ExFreePoolWithTag(i, 0);
    goto LABEL_68;
  }
  if( !NewElement )
  {
    for( i = (VOID **)*((_QWORD *)inserted + 1); i && (i[1] != v9 || i[2] != &v9[MdlAddress_low]); i = (VOID **)i[5] )
      ;
  }
  if( i )
  {
    Mdl = 0i64;
  }
  else
  {
    i = ExAllocatePoolWithTag(1ui64, 0x30ui64, 1700032329i64);
    FoExt[1] = i;
    if( !i )
    {
      v4 = -1073741670;
      Mdl = 0i64;
      v14 = 0;
      goto LABEL_58;
    }
    v36 = 1;
    WoW64Process = Process->WoW64Process;
    if( WoW64Process && ((Machine = WoW64Process->Machine, Machine == 332) || Machine == 452) )
    {
      if( ((unsigned __int8)v9 & 3) != 0 )
        ExRaiseDatatypeMisalignment();
    }
    else if( ((unsigned __int8)v9 & 7) != 0 )
    {
      ExRaiseDatatypeMisalignment();
    }
    if( (unsigned __int64)&v9[MdlAddress_low] > 0x7FFFFFFF0000i64 || &v9[MdlAddress_low] < v9 )
      MEMORY[0x7FFFFFFF0000] = 0;
    Mdl = IoAllocateMdl(v9, (unsigned int)MdlAddress_low, 0, 1u, 0i64);
    MemoryDescriptorList = Mdl;
    if( !Mdl )
      RtlRaiseStatus(-1073741670);
    LOBYTE(v17) = Irp->RequestorMode;
    MmProbeAndLockPages(Mdl, v17, IoWriteAccess);
    if( (Mdl->MdlFlags & 5) != 0 )
    {
      MappedSystemVa = Mdl->MappedSystemVa;
    }
    else
    {
      LODWORD(Priority) = 1073741840;
      LODWORD(v26) = 0;
      MappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl, 0, MmCached, 0i64, v26, Priority);
    }
    BaseAddress = MappedSystemVa;
    if( MappedSystemVa )
    {
      i[3] = Mdl;
      i[1] = v9;
      i[2] = &v9[(unsigned int)MdlAddress_low];
      *(_DWORD *)i = 1;
      i[5] = 0i64;
      i[4] = MappedSystemVa;
    }
    else
    {
      v4 = -1073741670;
    }
  }
  if( v4 < 0 )
    goto LABEL_56;
  PoolWithTag = ExAllocatePoolWithTag(0x200ui64, 0x30ui64, 1700032329i64);
  v3 = PoolWithTag;
  if( !PoolWithTag )
  {
    v4 = -1073741670;
    v14 = v36;
    goto LABEL_58;
  }
  PoolWithTag[2] = 0i64;
  PoolWithTag[3] = 0i64;
  PoolWithTag[4] = 0i64;
  PoolWithTag[5] = 0i64;
  *PoolWithTag = v9;
  PoolWithTag[1] = &v9[(unsigned int)MdlAddress_low];
  PoolWithTag[3] = &v9[(_BYTE *)i[4] - (_BYTE *)i[1]];
  PoolWithTag[2] = i[3];
  PoolWithTag[5] = 0i64;
  ObfReferenceObjectWithTag(Object, 0x70436F49ui64);
  v3[4] = Object;
  IopAllocateFileObjectExtension((_FILE_OBJECT *)FileObject, FoExt);
  v4 = v20;
  if( v20 < 0 )
  {
LABEL_56:
    v14 = v36;
  }
  else
  {
    v4 = IopSetTypeSpecificFoExtension((_IOP_FILE_OBJECT_EXTENSION *)FoExt[0], FoExtTypeIosbRange, v3);
    if( v4 == -1073741823 )
    {
      FileObjectExtension = IopGetFileObjectExtension((_FILE_OBJECT *)FileObject, v21, 0i64);
      v23 = FileObjectExtension;
      if( v3[4] == Object )
      {
        v11 = FileObjectExtension;
        if( FileObjectExtension )
        {
          v12 = (INT64)*v3;
          while( v12 != *v11 || v3[1] != (VOID *)v11[1] )
          {
            v11 = (_QWORD *)v11[5];
            if( !v11 )
              goto LABEL_44;
          }
          ObfDereferenceObjectWithTag(Object, 0x70436F49ui64);
          ExFreePoolWithTag(v3, 0);
          v4 = 0;
          goto LABEL_68;
        }
LABEL_44:
        v24 = FileObjectExtension[5];
        v3[5] = (VOID *)v24;
        if( (VOID *)_InterlockedCompareExchange64(v23 + 5, (signed __int64)v3, v24) != v3[5] )
        {
          _m_prefetchw(v23 + 5);
          do
          {
            v25 = v23[5];
            v3[5] = (VOID *)v25;
          }
          while( (VOID *)_InterlockedCompareExchange64(v23 + 5, (signed __int64)v3, v25) != v3[5] );
        }
        v4 = 0;
        Mdl = MemoryDescriptorList;
      }
    }
    v14 = v36;
    if( v4 < 0 )
      goto LABEL_58;
    if( v36 == 1 )
    {
      if( NewElement == 1 )
        *v30 = Object;
      else
        i[5] = v30[1];
      v30[1] = (_EPROCESS *)i;
    }
    else
    {
      ++*(_DWORD *)i;
    }
  }
  if( v4 < 0 )
    goto LABEL_58;
LABEL_68:
  KeReleaseGuardedMutex((PKGUARDED_MUTEX)((char *)&stru_140C452E0 + 2784));
  return v4;
}

Referenced by:

NtSetInformationFile