SepInsertOrReferenceSharedSidEntries
INT64 __stdcall SepInsertOrReferenceSharedSidEntries(
_SID_AND_ATTRIBUTES *InputSids,
_SID_AND_ATTRIBUTES *OutputSids,
UINT64 SidArrayCount){
_ETHREAD *CurrentThread;
unsigned int v4;
unsigned int v5;
__int64 v8;
signed __int64 v9;
signed __int64 v10;
PRTL_DYNAMIC_HASH_TABLE_ENTRY SharedSidEntry;
_LIST_ENTRY *Blink;
RTL_DYNAMIC_HASH_TABLE_ENTRY *PoolWithTag;
RTL_DYNAMIC_HASH_TABLE_ENTRY *v14;
__int64 v15;
UINT64 v16;
PRTL_DYNAMIC_HASH_TABLE_ENTRY v17;
__int64 v18;
volatile INT64 *v19;
unsigned int v21;
int v22;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v4 = 0;
v5 = SidArrayCount;
--*((_WORD *)CurrentThread + 242);
ExAcquirePushLockExclusiveEx(g_SepSidMapping, 0i64);
v8 = 0i64;
if( !v5 )
goto LABEL_24;
v9 = (char *)InputSids - (char *)OutputSids;
v10 = (char *)OutputSids - (char *)InputSids;
while( 1 )
{
*(unsigned int *)((char *)&InputSids->Attributes + v10) = *(unsigned int *)((char *)&InputSids->Attributes + v10 + v9);
SharedSidEntry = SepFindSharedSidEntry(InputSids->Sid);
if( SharedSidEntry )
{
if( _InterlockedIncrement64((volatile signed __int64 *)&SharedSidEntry[1]) <= 1 )
__fastfail(0xEu);
Blink = SharedSidEntry[1].Linkage.Blink;
goto LABEL_12;
}
v21 = 8 * *((unsigned __int8 *)InputSids->Sid + 1) + 96;
PoolWithTag = (RTL_DYNAMIC_HASH_TABLE_ENTRY *)ExAllocatePoolWithTag(PagedPool, v21, 0x73536553ui64);
v14 = PoolWithTag;
if( !PoolWithTag )
break;
PoolWithTag[1].Linkage.Blink = (_LIST_ENTRY *)&PoolWithTag[1].Signature;
PoolWithTag[1].Linkage.Flink = (_LIST_ENTRY *)1;
RtlCopySid(v21 - 40, &PoolWithTag[1].Signature, InputSids->Sid);
v15 = (unsigned int)*((unsigned __int8 *)InputSids->Sid + 1) - 1;
v16 = *((unsigned int *)InputSids->Sid + v15 + 2);
if( !*((_DWORD *)InputSids->Sid + v15 + 2) )
v16 = 1i64;
if( !RtlInsertEntryHashTable(*(RTL_DYNAMIC_HASH_TABLE **)(g_SepSidMapping + 8), v14, v16, 0i64) )
{
v4 = -1073741823;
v22 = -1073741823;
ExFreePoolWithTag(v14, 0x73536553u);
goto LABEL_16;
}
Blink = v14[1].Linkage.Blink;
LABEL_12:
*(void **)((char *)&InputSids->Sid + v10) = Blink;
v8 = (unsigned int)(v8 + 1);
++InputSids;
if( (unsigned int)v8 >= v5 )
{
v4 = 0;
goto LABEL_24;
}
}
v4 = -1073741801;
v22 = -1073741801;
LABEL_16:
if( (_DWORD)v8 )
{
do
{
v17 = SepFindSharedSidEntry(OutputSids->Sid);
v18 = _InterlockedDecrement64((volatile signed __int64 *)&v17[1]);
if( v18 <= 0 )
{
if( v18 )
__fastfail(0xEu);
if( RtlRemoveEntryHashTable(*(RTL_DYNAMIC_HASH_TABLE **)(g_SepSidMapping + 8), v17, 0i64) )
ExFreePoolWithTag(v17, 0);
}
++OutputSids;
--v8;
}
while( v8 );
v4 = v22;
}
LABEL_24:
v19 = (volatile INT64 *)g_SepSidMapping;
if( (_InterlockedExchangeAdd64((volatile signed __int64 *)g_SepSidMapping, 0xFFFFFFFFFFFFFFFFui64) & 6) == 2 )
ExfTryToWakePushLock(v19);
KeAbPostRelease((PVOID)v19);
KeLeaveCriticalRegion();
return v4;
}Referenced by:
SepSetTokenCapabilities