MiCreateImageOrDataSection

VOID __stdcall MiCreateImageOrDataSection(FILE_OBJECT *File){
  unsigned int v2; 
  CHAR v3; 
  int Vpb; 
  void *PrivateCacheMap; 
  unsigned __int8 LockOperation; 
  __int64 v7; 
  NTSTATUS v8; 
  FILE_OBJECT *v9; 
  int v10; 
  INT64 *FileMemoryPartitionInformation; 
  _ETHREAD *CurrentThread; 
  _MMSUPPORT_INSTANCE *v13; 
  UINT64 v14; 
  UINT64 v15; 
  int v16; 
  _FILE_OBJECT *v17; 
  int v18; 
  _CONTROL_AREA **v19; 
  _DEVICE_OBJECT *DeviceObject; 
  int v21; 
  bool v22; 
  _CONTROL_AREA **v23; 
  _CONTROL_AREA *v24; 
  __int64 v25; 
  _FILE_OBJECT *v26; 
  char FsContext; 
  int v28; 
  _QWORD *v29; 
  UINT64 v30; 
  _IO_COMPLETION_CONTEXT *v31; 
  __int64 v32; 
  __int64 v33; 
  signed __int64 v34; 
  PVOID *Object; 
  POBJECT_HANDLE_INFORMATION HandleInformation; 
  INT64 result[7]; 
  int v38; 
  FILE_OBJECT *v39; 
  _CONTROL_AREA *ControlArea; 
  _FILE_OBJECT **v41; 
  PVOID v42; 
  v41 = 0i64;
  ControlArea = 0i64;
  memset((INT64)result, 0i64);
  v2 = 0;
  v3 = 1;
  if( !LOBYTE(File->IrpList.Flink) )
  {
    Vpb = (int)File->Vpb;
    if( (Vpb & 0x80000) == 0 )
    {
      PrivateCacheMap = File->PrivateCacheMap;
      if( PrivateCacheMap )
      {
        v9 = (FILE_OBJECT *)File->PrivateCacheMap;
        goto LABEL_7;
      }
      if( Vpb >= 0 )
      {
        LockOperation = File->LockOperation;
        v7 = (__int64)File->FsContext2 & 7;
        v42 = 0i64;
        v8 = ObReferenceObjectByHandle(
               File->SectionObjectPointer,
               *((_DWORD *)MmMakeFileAccess + v7),
               (POBJECT_TYPE)IoFileObjectType,
               LockOperation,
               &v42,
               0i64);
        v9 = (FILE_OBJECT *)v42;
        v10 = v8;
        if( v8 < 0 )
          goto LABEL_21;
        v2 = 1;
        if( !*((_QWORD *)v42 + 5) )
        {
LABEL_23:
          ObDereferenceObjectEx(v9, v2);
          return;
        }
LABEL_7:
        FileMemoryPartitionInformation = (INT64 *)IoGetFileMemoryPartitionInformation((INT64)v9);
        if( FileMemoryPartitionInformation )
        {
          if( !PsReferencePartitionSafe(*FileMemoryPartitionInformation) )
            goto LABEL_22;
          File->CompletionContext = v31;
          if( (*(_DWORD *)(v32 + 8) & 1) != 0 )
            *(_DWORD *)&File->Type |= 0x800000u;
        }
        if( !PrivateCacheMap )
        {
          ObfReferenceObject(v9);
          ++v2;
LABEL_10:
          *(_QWORD *)&File->FinalStatus = v9;
          v38 = 2;
          if( v9 )
            v39 = v9;
          else
            v39 = 0i64;
          if( ((__int64)File->Vpb & 0x1000000) != 0 )
          {
            if( (*(_DWORD *)&File->Type & 0x400) != 0 && !IoAllowExecution(v9) )
              goto LABEL_22;
            CcWaitForUninitializeCacheMap(v9);
            if( (*(_DWORD *)&File->Type & 0x400) != 0 )
            {
              FsContext = (char)File->FsContext;
              if( (FsContext & 0x10) != 0 )
              {
                v28 = *(_DWORD *)&File->Type | 0x10;
                *(_DWORD *)&File->Type = v28;
                if( (FsContext & 0x30) == 48 )
                  *(_DWORD *)&File->Type = v28 | 0x1000;
                LOBYTE(File->FsContext) = FsContext & 0xF;
              }
            }
            v3 = 2;
          }
          CurrentThread = (_ETHREAD *)KeGetCurrentThread();
          --*((_WORD *)CurrentThread + 242);
          while( 1 )
          {
            v10 = MiCallCreateSectionFilters((INT64 *)&File->Type);
            if( v10 < 0 )
              goto LABEL_41;
            if( (*(_DWORD *)&File->Type & 1) == 0 )
            {
              File->IrpListLock = (unsigned __int64)IoGetTopLevelIrp();
              IoSetTopLevelIrp(
                (_MI_PARTITION *)1,
                v13,
                v14,
                v15,
                (UINT64)Object,
                (UINT64)HandleInformation,
                (UINT64 *)result[0]);
              *(_DWORD *)&File->Type |= 2u;
            }
            v16 = MiReferenceControlArea((__int64)File, (__int64)result, (__int64 *)&ControlArea);
            if( v16 >= 0 )
              break;
            if( v16 == -1073740277 )
            {
              KeLeaveCriticalRegionThread((__int64)CurrentThread);
              goto LABEL_22;
            }
            if( v16 == -1073740682 )
            {
              KeLeaveCriticalRegionThread((__int64)CurrentThread);
              goto LABEL_75;
            }
          }
          v17 = (_FILE_OBJECT *)ControlArea;
          File->RelatedFileObject = (_FILE_OBJECT *)ControlArea;
          if( (v17->FinalStatus & 2) != 0 )
          {
            v10 = MiCreateNewSection(File, &v41);
            if( v10 >= 0 )
            {
              v26 = *v41;
              File->RelatedFileObject = *v41;
              _InterlockedIncrement64((volatile signed __int64 *)MiGetControlAreaPartition((_CONTROL_AREA *)v26) + 169);
              v2 -= 2;
LABEL_41:
              KeLeaveCriticalRegionThread((__int64)CurrentThread);
              goto LABEL_21;
            }
            if( v41 )
            {
              v17 = *v41;
              ControlArea = (_CONTROL_AREA *)v17;
              File->RelatedFileObject = v17;
            }
            v29 = (_QWORD *)MiZeroSectionObjectPointer((__int64)v9, (__int64)v17, (int)File->Vpb);
            --v2;
            if( v17 == (_FILE_OBJECT *)result )
            {
              HalPutDmaAdapter((PADAPTER_OBJECT)v9);
              v9 = (FILE_OBJECT *)ObFastReplaceObject((_EX_FAST_REF *)&v17->RelatedFileObject, 0i64, v30);
            }
            else
            {
              _InterlockedIncrement64((volatile signed __int64 *)MiGetControlAreaPartition((_CONTROL_AREA *)v17) + 169);
              MiDereferenceControlAreaBySection(ControlArea, 1ui64);
            }
            MiReleaseControlAreaWaiters(v29);
            KeLeaveCriticalRegionThread((__int64)CurrentThread);
          }
          else
          {
            KeLeaveCriticalRegionThread((__int64)CurrentThread);
            v10 = MiShareExistingControlArea((INT64)File);
            if( v10 < 0 )
              MiDereferenceFailedControlArea((INT64 *)&File->Type);
            else
              --v2;
          }
          goto LABEL_21;
        }
        v18 = (__int64)File->Vpb & 0x1000000;
        if( v18 && ((*(_DWORD *)&File->Type & 1) != 0 || *(_QWORD *)&File->Event.Header.Lock) )
          goto LABEL_22;
        v19 = (_CONTROL_AREA **)*((_QWORD *)PrivateCacheMap + 5);
        if( !v19 )
          goto LABEL_22;
        DeviceObject = File->DeviceObject;
        if( DeviceObject && (*((_DWORD *)DeviceObject + 6) & 0x200) != 0 )
        {
          File->LockOperation = 0;
          v19 = (_CONTROL_AREA **)*((_QWORD *)PrivateCacheMap + 5);
        }
        if( v18 )
          v19 += 2;
        v10 = -1073741823;
        ControlArea = *v19;
        if( !ControlArea || (v10 = MiReferenceExistingControlArea((INT64)File), v10 < 0) )
        {
          ObReferenceObjectExWithTag(v9, 2ui64);
          v2 += 2;
          if( v10 == -1073740682 )
          {
LABEL_75:
            if( (*(_DWORD *)&File->Type & 1) == 0 )
              CcWaitForUninitializeCacheMap(v9);
            if( (unsigned int)MiForceSectionClosed(&v9->SectionObjectPointer->DataSectionObject, v3) > 1
              && (*(_DWORD *)&File->Type & 0x1000000) != 0 )
            {
              ++dword_140C4E398;
            }
LABEL_22:
            if( !v2 )
              return;
            goto LABEL_23;
          }
          goto LABEL_10;
        }
        v21 = *(_DWORD *)&File->Type | 4;
        v22 = ((__int64)File->Vpb & 0x1000000) == 0;
        *(_DWORD *)&File->Type = v21;
        v23 = (_CONTROL_AREA **)*((_QWORD *)PrivateCacheMap + 5);
        if( v22 )
        {
          v24 = *v23;
          v25 = *(_QWORD *)&File->Event.Header.Lock;
          *(_QWORD *)&File->Lock.Header.Lock = v25;
          ControlArea = v24;
          if( (v21 & 1) != 0 || v25 )
            goto LABEL_38;
          v33 = *(_QWORD *)v24;
        }
        else
        {
          ControlArea = v23[2];
          v33 = *(_QWORD *)ControlArea;
        }
        v34 = _InterlockedCompareExchange64((volatile signed __int64 *)(v33 + 24), -1i64, -1i64);
        v24 = ControlArea;
        *(_QWORD *)&File->Lock.Header.Lock = v34;
LABEL_38:
        File->RelatedFileObject = (_FILE_OBJECT *)v24;
LABEL_21:
        if( v10 != -1073740682 )
          goto LABEL_22;
        goto LABEL_75;
      }
    }
  }
}

Referenced by:

MiCreateSection