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;
NTSTATUS NewSection;
INT64 *v11;
_IO_COMPLETION_CONTEXT *v12;
_ETHREAD *CurrentThread;
UINT64 v14;
NTSTATUS v15;
UINT64 v16;
UINT64 v17;
_FILE_OBJECT *v18;
int v19;
_FILE_OBJECT **v20;
_DEVICE_OBJECT *DeviceObject;
int v22;
bool v23;
__int64 v24;
_CONTROL_AREA *v25;
__int64 v26;
_EPROCESS *v27;
_FILE_OBJECT *v28;
char v29;
char FsContext;
int v31;
_EPROCESS *v32;
_MI_CONTROL_AREA_WAIT_BLOCK *v33;
UINT64 v34;
__int64 v35;
_SEGMENT *Segment;
signed __int64 v37;
_CONTROL_AREA **Object;
POBJECT_HANDLE_INFORMATION HandleInformation;
_BYTE v40[184];
_FILE_OBJECT *v41;
_FILE_OBJECT **v42;
_FILE_OBJECT *v43;
v42 = 0i64;
v41 = 0i64;
memset(v40, 0i64, 0x80u);
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;
v43 = 0i64;
v8 = ObReferenceObjectByHandle(
File->SectionObjectPointer,
*((unsigned int *)MmMakeFileAccess + v7),
(_OBJECT_TYPE *)IoFileObjectType,
LockOperation,
(VOID **)&v43,
0i64);
v9 = v43;
NewSection = v8;
if( v8 < 0 )
goto LABEL_21;
v2 = 1;
if( !v43->SectionObjectPointer )
{
LABEL_23:
ObDereferenceObjectEx(v9, v2);
return;
}
LABEL_7:
LODWORD(v11) = IoGetFileMemoryPartitionInformation((INT64)v9);
if( v11 )
{
if( !PsReferencePartitionSafe(*v11) )
goto LABEL_22;
File->CompletionContext = v12;
if( (*(_DWORD *)(v35 + 8) & 1) != 0 )
*(_DWORD *)&File->Type |= 0x800000u;
}
if( !PrivateCacheMap )
{
ObfReferenceObject(v9);
++v2;
LABEL_10:
*(_QWORD *)&File->FinalStatus = v9;
*(_DWORD *)&v40[56] = 2;
if( v9 )
*(_QWORD *)&v40[64] = v9;
else
*(_QWORD *)&v40[64] = 0i64;
if( ((__int64)File->Vpb & 0x1000000) != 0 )
{
if( (*(_DWORD *)&File->Type & 0x400) != 0 )
{
IoAllowExecution(v9);
if( !v29 )
goto LABEL_22;
}
CcWaitForUninitializeCacheMap(v9);
if( (*(_DWORD *)&File->Type & 0x400) != 0 )
{
FsContext = (char)File->FsContext;
if( (FsContext & 0x10) != 0 )
{
v31 = *(_DWORD *)&File->Type | 0x10;
*(_DWORD *)&File->Type = v31;
if( (FsContext & 0x30) == 48 )
*(_DWORD *)&File->Type = v31 | 0x1000;
LOBYTE(File->FsContext) = FsContext & 0xF;
}
}
v3 = 2;
}
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
--CurrentThread->Tcb.KernelApcDisable;
while( 1 )
{
NewSection = MiCallCreateSectionFilters((int *)&File->Type);
if( NewSection < 0 )
goto LABEL_41;
if( (*(_DWORD *)&File->Type & 1) == 0 )
{
File->IrpListLock = (unsigned __int64)IoGetTopLevelIrp();
IoSetTopLevelIrp((_IRP *)1);
*(_DWORD *)&File->Type |= 2u;
}
v15 = MiReferenceControlArea((UINT64)File, (_FILE_OBJECT *)v40, (_CONTROL_AREA *)&v41, v14, Object);
if( v15 >= 0 )
break;
if( v15 == -1073740277 )
{
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
goto LABEL_22;
}
if( v15 == -1073740682 )
{
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
goto LABEL_75;
}
}
v18 = v41;
File->RelatedFileObject = v41;
if( (v18->FinalStatus & 2) != 0 )
{
NewSection = MiCreateNewSection(
File,
(UINT64)&v42,
v16,
v17,
(UINT64)Object,
HandleInformation,
*(UINT8 **)v40,
*(UINT64 **)&v40[8],
*(_MI_CREATE_SECTION_FLAGS **)&v40[16],
*(_SEGMENT ***)&v40[24],
*(UINT64 **)&v40[32]);
if( NewSection >= 0 )
{
v28 = *v42;
File->RelatedFileObject = *v42;
_InterlockedIncrement64(&MiGetControlAreaPartition(v28, v27)->Segments.FsControlAreaCount);
v2 -= 2;
LABEL_41:
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
goto LABEL_21;
}
if( v42 )
{
v18 = *v42;
v41 = v18;
File->RelatedFileObject = v18;
}
v33 = MiZeroSectionObjectPointer(v9, (_CONTROL_AREA *)v18, LODWORD(File->Vpb));
--v2;
if( v18 == (_FILE_OBJECT *)v40 )
{
HalPutDmaAdapter((PADAPTER_OBJECT)v9);
v9 = (_FILE_OBJECT *)ObFastReplaceObject((_EX_FAST_REF *)&v18->RelatedFileObject, 0i64, v34);
}
else
{
_InterlockedIncrement64(&MiGetControlAreaPartition(v18, v32)->Segments.FsControlAreaCount);
MiDereferenceControlAreaBySection((_CONTROL_AREA *)v41, 1ui64);
}
MiReleaseControlAreaWaiters(v33);
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
}
else
{
KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
NewSection = MiShareExistingControlArea((INT64)File);
if( NewSection < 0 )
MiDereferenceFailedControlArea((INT64 *)&File->Type);
else
--v2;
}
goto LABEL_21;
}
v19 = (__int64)File->Vpb & 0x1000000;
if( v19 && ((*(_DWORD *)&File->Type & 1) != 0 || *(_QWORD *)&File->gap80[24]) )
goto LABEL_22;
v20 = (_FILE_OBJECT **)*((_QWORD *)PrivateCacheMap + 5);
if( !v20 )
goto LABEL_22;
DeviceObject = File->DeviceObject;
if( DeviceObject && ((__int64)DeviceObject->AttachedDevice & 0x200) != 0 )
{
File->LockOperation = 0;
v20 = (_FILE_OBJECT **)*((_QWORD *)PrivateCacheMap + 5);
}
if( v19 )
v20 += 2;
NewSection = -1073741823;
v41 = *v20;
if( !v41 || (NewSection = MiReferenceExistingControlArea((INT64)File), NewSection < 0) )
{
ObReferenceObjectExWithTag(v9, 2ui64, (UINT64)v12);
v2 += 2;
if( NewSection == -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 )
{
++*(&stru_140C4DB30 + 538);
}
LABEL_22:
if( !v2 )
return;
goto LABEL_23;
}
goto LABEL_10;
}
v22 = *(_DWORD *)&File->Type | 4;
v23 = ((__int64)File->Vpb & 0x1000000) == 0;
*(_DWORD *)&File->Type = v22;
v24 = *((_QWORD *)PrivateCacheMap + 5);
if( v23 )
{
v25 = *(_CONTROL_AREA **)v24;
v26 = *(_QWORD *)&File->gap80[24];
*(_QWORD *)File->gap80 = v26;
v41 = (_FILE_OBJECT *)v25;
if( (v22 & 1) != 0 || v26 )
goto LABEL_38;
Segment = v25->Segment;
}
else
{
v41 = *(_FILE_OBJECT **)(v24 + 16);
Segment = *(_SEGMENT **)&v41->Type;
}
v37 = _InterlockedCompareExchange64((volatile signed __int64 *)&Segment->SizeOfSegment, -1i64, -1i64);
v25 = (_CONTROL_AREA *)v41;
*(_QWORD *)File->gap80 = v37;
LABEL_38:
File->RelatedFileObject = (_FILE_OBJECT *)v25;
LABEL_21:
if( NewSection != -1073740682 )
goto LABEL_22;
goto LABEL_75;
}
}
}
}Referenced by:
MiCreateSection