FsRtlCreateSectionForDataScan

NTSTATUS __stdcall FsRtlCreateSectionForDataScan(
        PVOID *SectionHandle,
        PVOID *SectionObject,
        _LARGE_INTEGER *SectionFileSize,
        _FILE_OBJECT *FileObject,
        UINT64 DesiredAccess,
        _OBJECT_ATTRIBUTES *ObjectAttributes,
        _LARGE_INTEGER *MaximumSize,
        UINT64 SectionPageProtection,
        UINT64 AllocationAttributes,
        UINT64 Flags){
  PVOID *v12; 
  _ETHREAD *CurrentThread; 
  int v14; 
  int inserted; 
  LARGE_INTEGER *QuadPart; 
  NTSTATUS v17; 
  FILE_OBJECT *FileObjectForSection; 
  FILE_OBJECT *v19; 
  PVOID v20; 
  NTSTATUS result; 
  PVOID *NewObject; 
  UINT64 CompressionAlignment; 
  PVOID Object; 
  union _LARGE_INTEGER FileSize; 
  PVOID Handle; 
  v12 = SectionObject;
  FileSize.QuadPart = 0i64;
  Object = 0i64;
  Handle = 0i64;
  CompressionAlignment = 0i64;
  if( (SectionPageProtection & 0xFFFFFFF9) != 0 || !(_DWORD)SectionPageProtection )
    return -1073741578;
  if( (AllocationAttributes & 0xFF7FFFFF) != 0x8000000 )
    return -1073741577;
  if( !FileObject->SectionObjectPointer )
    return -1073741792;
  *((_QWORD *)KeGetCurrentThread() + 152) = 1i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  --*((_WORD *)CurrentThread + 242);
  NewObject = (PVOID *)((char *)&CompressionAlignment + 4);
  v14 = FsRtlAcquireToCreateMappedSection(
          FileObject,
          (unsigned int)SectionPageProtection,
          (UINT64 *)1,
          &CompressionAlignment);
  if( v14 < 0 )
  {
    KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
    result = v14;
    *((_QWORD *)KeGetCurrentThread() + 152) = 0i64;
  }
  else
  {
    inserted = FsRtlGetFileSize(FileObject, &FileSize);
    if( inserted >= 0 )
    {
      QuadPart = (LARGE_INTEGER *)FileSize.QuadPart;
      if( FileSize.QuadPart )
      {
        while( 1 )
        {
          LODWORD(NewObject) = AllocationAttributes;
          v17 = MmCreateSectionEx(
                  &Object,
                  ObjectAttributes,
                  QuadPart,
                  (unsigned int)SectionPageProtection,
                  (UINT64)NewObject,
                  0i64,
                  (UINT64)FileObject);
          inserted = v17;
          if( v17 != -1073741740 )
            break;
          KeDelayExecutionThread(0, 0, (PLARGE_INTEGER)FsRtlHalfSecond);
        }
        if( v17 >= 0 )
        {
          FileObjectForSection = MmGetFileObjectForSection(Object);
          v19 = FileObjectForSection;
          if( FileObjectForSection )
          {
            CcZeroEndOfLastPage(FileObjectForSection);
            ObfDereferenceObjectWithTag(v19, 0x746C6644ui64);
          }
        }
        v12 = SectionObject;
      }
      else
      {
        inserted = -1073741807;
      }
    }
    FsRtlReleaseFile(FileObject);
    KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
    *((_QWORD *)KeGetCurrentThread() + 152) = 0i64;
    if( inserted >= 0 )
    {
      v20 = Object;
      ObfReferenceObjectWithTag(Object, 0x746C6644u);
      inserted = ObInsertObject(v20, 0i64, (unsigned int)DesiredAccess, 0i64, 0i64, &Handle);
      if( inserted < 0 )
      {
        ObfDereferenceObjectWithTag(v20, 0x746C6644ui64);
      }
      else
      {
        *SectionHandle = Handle;
        *v12 = v20;
        if( SectionFileSize )
          *SectionFileSize = FileSize;
      }
    }
    return inserted;
  }
  return result;
}

Referenced by:

No references.