IopSetFileObjectIosbRange

INT64 __stdcall IopSetFileObjectIosbRange(FILE_OBJECT *FileObject, IRP *Irp){
  _QWORD *i; 
  _QWORD *v3; 
  NTSTATUS FileObjectExtension; 
  _QWORD *v5; 
  char **v6; 
  __int64 v7; 
  char *v9; 
  _QWORD *inserted; 
  PMDL Mdl; 
  char v12; 
  __int64 v13; 
  __int16 v14; 
  PVOID MappedSystemVa; 
  _QWORD *PoolWithTag; 
  _FILE_OBJECT_EXTENSION_TYPE v17; 
  _QWORD *v18; 
  _QWORD *v19; 
  _QWORD *v20; 
  signed __int64 v21; 
  signed __int64 v22; 
  PMDL MemoryDescriptorList; 
  PVOID BaseAddress; 
  _QWORD *v25; 
  PVOID Object; 
  PVOID FoExt[6]; 
  __int64 Buffer[9]; 
  char v31; 
  unsigned __int8 NewElement; 
  FoExt[0] = 0i64;
  v31 = 0;
  NewElement = 0;
  i = 0i64;
  Buffer[1] = 0i64;
  v3 = 0i64;
  FoExt[2] = 0i64;
  MemoryDescriptorList = 0i64;
  BaseAddress = 0i64;
  FileObjectExtension = 0;
  v5 = (_QWORD *)*((_QWORD *)KeGetCurrentThread() + 23);
  Object = v5;
  FoExt[5] = v5;
  v6 = (char **)*((_QWORD *)Irp + 3);
  v7 = *((unsigned int *)v6 + 2);
  if( !(_DWORD)v7 )
    return 3221225485i64;
  v9 = *v6;
  FoExt[3] = v9;
  ExAcquireFastMutex(&IoStatusBlockRangeTableLock);
  Buffer[0] = (__int64)v5;
  inserted = RtlInsertElementGenericTableAvl((RTL_AVL_TABLE *)IoStatusBlockRangeTable, Buffer, 0x10ui64, &NewElement);
  v25 = inserted;
  if( !inserted )
  {
    FileObjectExtension = -1073741670;
    Mdl = 0i64;
    v12 = 0;
LABEL_57:
    if( Mdl )
    {
      if( BaseAddress )
        MmUnmapLockedPages(BaseAddress, Mdl);
      MmUnlockPages(Mdl);
      IoFreeMdl(Mdl);
    }
    if( v3 )
    {
      ObfDereferenceObjectWithTag(Object, 0x70436F49ui64);
      ExFreePoolWithTag(v3, 0);
    }
    if( NewElement == 1 )
      RtlDeleteElementGenericTableAvl((RTL_AVL_TABLE *)IoStatusBlockRangeTable, Buffer);
    if( v12 == 1 )
      ExFreePoolWithTag(i, 0);
    goto LABEL_67;
  }
  if( !NewElement )
  {
    for( i = (_QWORD *)inserted[1]; i && ((char *)i[1] != v9 || (char *)i[2] != &v9[v7]); i = (_QWORD *)i[5] )
      ;
  }
  if( i )
  {
    Mdl = 0i64;
  }
  else
  {
    i = ExAllocatePoolWithTag(PagedPool, 0x30ui64, 0x65546F49ui64);
    FoExt[1] = i;
    if( !i )
    {
      FileObjectExtension = -1073741670;
      Mdl = 0i64;
      v12 = 0;
      goto LABEL_57;
    }
    v31 = 1;
    v13 = v5[176];
    if( v13 && ((v14 = *(_WORD *)(v13 + 8), v14 == 332) || v14 == 452) )
    {
      if( ((unsigned __int8)v9 & 3) != 0 )
        ExRaiseDatatypeMisalignment();
    }
    else if( ((unsigned __int8)v9 & 7) != 0 )
    {
      ExRaiseDatatypeMisalignment();
    }
    if( (unsigned __int64)&v9[v7] > 0x7FFFFFFF0000i64 || &v9[v7] < v9 )
      MEMORY[0x7FFFFFFF0000] = 0;
    Mdl = IoAllocateMdl(v9, v7, 0, 1u, 0i64);
    MemoryDescriptorList = Mdl;
    if( !Mdl )
      RtlRaiseStatus(-1073741670);
    MmProbeAndLockPages(Mdl, *((_BYTE *)Irp + 64), IoWriteAccess);
    if( (Mdl->MdlFlags & 5) != 0 )
      MappedSystemVa = Mdl->MappedSystemVa;
    else
      MappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl, 0, MmCached, 0i64, 0, 0x40000010u);
    BaseAddress = MappedSystemVa;
    if( MappedSystemVa )
    {
      i[3] = Mdl;
      i[1] = v9;
      i[2] = &v9[(unsigned int)v7];
      *(_DWORD *)i = 1;
      i[5] = 0i64;
      i[4] = MappedSystemVa;
    }
    else
    {
      FileObjectExtension = -1073741670;
    }
  }
  if( FileObjectExtension < 0 )
    goto LABEL_55;
  PoolWithTag = ExAllocatePoolWithTag(NonPagedPoolNx, 0x30ui64, 0x65546F49ui64);
  v3 = PoolWithTag;
  if( !PoolWithTag )
  {
    FileObjectExtension = -1073741670;
    v12 = v31;
    goto LABEL_57;
  }
  PoolWithTag[2] = 0i64;
  PoolWithTag[3] = 0i64;
  PoolWithTag[4] = 0i64;
  PoolWithTag[5] = 0i64;
  *PoolWithTag = v9;
  PoolWithTag[1] = &v9[(unsigned int)v7];
  PoolWithTag[3] = &v9[i[4] - i[1]];
  PoolWithTag[2] = i[3];
  PoolWithTag[5] = 0i64;
  ObfReferenceObjectWithTag(Object, 0x70436F49u);
  v3[4] = Object;
  FileObjectExtension = IopAllocateFileObjectExtension(FileObject, FoExt);
  if( FileObjectExtension < 0 )
  {
LABEL_55:
    v12 = v31;
  }
  else
  {
    FileObjectExtension = IopSetTypeSpecificFoExtension((_IOP_FILE_OBJECT_EXTENSION *)FoExt[0], FoExtTypeIosbRange, v3);
    if( FileObjectExtension == -1073741823 )
    {
      v18 = IopGetFileObjectExtension(FileObject, v17, 0i64);
      v19 = v18;
      if( (PVOID)v3[4] == Object )
      {
        v20 = v18;
        if( v18 )
        {
          while( *v3 != *v20 || v3[1] != v20[1] )
          {
            v20 = (_QWORD *)v20[5];
            if( !v20 )
              goto LABEL_43;
          }
          ObfDereferenceObjectWithTag(Object, 0x70436F49ui64);
          ExFreePoolWithTag(v3, 0);
          FileObjectExtension = 0;
          goto LABEL_67;
        }
LABEL_43:
        v21 = v18[5];
        v3[5] = v21;
        if( _InterlockedCompareExchange64(v19 + 5, (signed __int64)v3, v21) != v3[5] )
        {
          _m_prefetchw(v19 + 5);
          do
          {
            v22 = v19[5];
            v3[5] = v22;
          }
          while( _InterlockedCompareExchange64(v19 + 5, (signed __int64)v3, v22) != v3[5] );
        }
        FileObjectExtension = 0;
        Mdl = MemoryDescriptorList;
      }
    }
    v12 = v31;
    if( FileObjectExtension < 0 )
      goto LABEL_57;
    if( v31 == 1 )
    {
      if( NewElement == 1 )
        *v25 = Object;
      else
        i[5] = v25[1];
      v25[1] = i;
    }
    else
    {
      ++*(_DWORD *)i;
    }
  }
  if( FileObjectExtension < 0 )
    goto LABEL_57;
LABEL_67:
  KeReleaseGuardedMutex(&IoStatusBlockRangeTableLock);
  return(unsigned int)FileObjectExtension;
}

Referenced by:

NtSetInformationFile