RtlFindSetBits
UINT64 __stdcall RtlFindSetBits(RTL_BITMAP *BitMapHeader, UINT64 NumberToFind, UINT64 HINTIndex){
unsigned int SizeOfBitMap;
int v4;
unsigned int v5;
int v6;
unsigned int v7;
unsigned int *Buffer;
__int64 v9;
int v10;
unsigned int v11;
unsigned int v12;
char *v13;
unsigned int v14;
__int64 v15;
unsigned __int64 v16;
char *v17;
signed __int64 v18;
unsigned __int64 v19;
unsigned int v20;
bool v21;
unsigned int v22;
unsigned int v24;
int v25;
char *v26;
bool v27;
__int64 v28;
unsigned int v29;
unsigned __int64 v30;
__int64 v31;
int v32;
unsigned int v33;
__int64 v34;
unsigned __int64 v35;
int v36;
char v37;
char *v38;
__int64 v39;
unsigned int v40;
__int64 v41;
__int64 v42;
__int64 v43;
__int64 v44;
unsigned int *v45;
int v46;
SizeOfBitMap = BitMapHeader->SizeOfBitMap;
v4 = HINTIndex;
v5 = NumberToFind;
v6 = (unsigned int)HINTIndex < BitMapHeader->SizeOfBitMap ? HINTIndex : 0;
v7 = BitMapHeader->SizeOfBitMap - 1;
if( !(_DWORD)NumberToFind )
return v6 & 0xFFFFFFF8;
Buffer = BitMapHeader->Buffer;
v45 = Buffer;
v9 = (unsigned __int8)Buffer & 4;
v44 = v9;
v10 = v9 != 0 ? 0x20 : 0;
while( 1 )
{
v11 = v10 + v7;
v12 = v10 + v6;
v13 = (char *)Buffer - (v9 != 0 ? 4 : 0);
if( v7 - v6 + 1 < v5 )
{
LABEL_16:
v20 = -1;
goto LABEL_17;
}
v14 = v11 - v5 + 1;
v15 = (1i64 << (v12 & 0x3F)) - 1;
v16 = (unsigned __int64)&v13[8 * ((unsigned __int64)v14 >> 6)];
v17 = &v13[8 * ((unsigned __int64)v12 >> 6)];
v18 = ~*(_QWORD *)v17 | v15;
if( v5 > 0x7F )
{
v35 = v16 + 8;
if( (v14 & 0x3F) == 0 )
v35 = (unsigned __int64)&v13[8 * ((unsigned __int64)(v11 - v5 + 1) >> 6)];
if( !v18 )
{
v36 = 0;
goto LABEL_53;
}
v17 += 8;
if( *(_QWORD *)v17 != -1i64 )
goto LABEL_59;
v27 = !_BitScanReverse64((unsigned __int64 *)&v43, v18);
if( !v27 )
{
v36 = 63 - v43;
goto LABEL_53;
}
LABEL_78:
v36 = 64;
LABEL_53:
while( 1 )
{
v20 = ((unsigned int)((v17 - v13) >> 3) << 6) - v36;
if( v20 > v14 )
goto LABEL_16;
v37 = v5 - v36;
v38 = &v17[8 * ((unsigned __int64)(v5 - v36) >> 6)];
while( 1 )
{
v17 += 8;
if( v17 == v38 )
break;
if( *(_QWORD *)v17 != -1i64 )
goto LABEL_59;
}
v40 = v37 & 0x3F;
if( !v40 )
goto LABEL_12;
v27 = !_BitScanForward64((unsigned __int64 *)&v41, ~*(_QWORD *)v17);
if( v27 )
LODWORD(v41) = 64;
if( (unsigned int)v41 >= v40 )
goto LABEL_12;
do
{
LABEL_59:
if( (unsigned __int64)v17 > v35 )
goto LABEL_16;
v17 += 8;
}
while( *(_QWORD *)v17 != -1i64 );
v46 &= ~*(_DWORD *)v17;
v27 = !_BitScanReverse64((unsigned __int64 *)&v39, ~*((_QWORD *)v17 - 1));
if( v27 )
goto LABEL_78;
v36 = 63 - v39;
}
}
if( v5 >= 0x40 )
{
while( 1 )
{
while( 1 )
{
while( v18 < 0 )
{
v17 += 8;
if( (unsigned __int64)v17 > v16 )
goto LABEL_16;
v18 = ~*(_QWORD *)v17;
}
v27 = !_BitScanReverse64((unsigned __int64 *)&v31, v18);
if( v27 )
v32 = 64;
else
v32 = 63 - v31;
v20 = (((unsigned int)((v17 - v13) >> 3) + 1) << 6) - v32;
if( v20 > v14 )
goto LABEL_16;
v33 = v5 - v32;
if( v5 == v32 )
goto LABEL_12;
v17 += 8;
v18 = ~*(_QWORD *)v17;
if( v33 >= 0x40 )
break;
LABEL_45:
v27 = !_BitScanForward64((unsigned __int64 *)&v34, v18);
if( v27 )
LODWORD(v34) = 64;
if( (unsigned int)v34 >= v33 )
goto LABEL_12;
}
if( *(_QWORD *)v17 == -1i64 )
{
v33 -= 64;
if( !v33 )
goto LABEL_12;
v17 += 8;
v18 = ~*(_QWORD *)v17;
goto LABEL_45;
}
}
}
if( v5 > 1 )
{
v25 = 0;
v26 = &v13[8 * ((unsigned __int64)v11 >> 6)];
while( v18 != -1 )
{
LABEL_23:
v27 = !_BitScanForward64((unsigned __int64 *)&v28, v18);
if( v27 )
LODWORD(v28) = 64;
if( v25 + (int)v28 >= v5 )
{
LODWORD(v30) = -v25;
LABEL_30:
v20 = ((unsigned int)((v17 - v13) >> 3) << 6) + v30;
v21 = v20 <= v14;
goto LABEL_11;
}
v29 = v5;
v30 = ~v18;
while( 1 )
{
v30 &= v30 >> (v29 >> 1);
if( !v30 )
break;
v29 -= v29 >> 1;
if( v29 <= 1 )
{
_BitScanForward64(&v30, v30);
goto LABEL_30;
}
}
if( v17 == v26 )
goto LABEL_16;
v27 = !_BitScanReverse64((unsigned __int64 *)&v42, v18);
if( v27 )
v25 = 64;
else
v25 = 63 - v42;
v17 += 8;
v18 = ~*(_QWORD *)v17;
}
while( 1 )
{
v17 += 8;
if( (unsigned __int64)v17 > v16 )
goto LABEL_16;
v18 = ~*(_QWORD *)v17;
if( *(_QWORD *)v17 )
{
v25 = 0;
goto LABEL_23;
}
}
}
while( v18 == -1 )
{
v17 += 8;
if( (unsigned __int64)v17 > v16 )
goto LABEL_16;
v18 = ~*(_QWORD *)v17;
}
_BitScanForward64(&v19, ~v18);
v20 = v19 + ((unsigned int)((v17 - v13) >> 3) << 6);
v21 = v20 <= v14;
LABEL_11:
if( !v21 )
goto LABEL_16;
LABEL_12:
if( v20 != -1 )
break;
LABEL_17:
if( !v6 )
break;
v9 = v44;
v24 = v5 + v4;
Buffer = v45;
if( v5 + v4 > SizeOfBitMap )
v24 = SizeOfBitMap;
v7 = v24 - 1;
v6 = 0;
}
v22 = v20 - v10;
if( v20 == -1 )
return(unsigned int)-1;
return v22;
}Referenced by:
EtwQueryPerformanceTraceInformation
HvpFindFreeCell
HvpRemoveFreeCellHint
MiFindDriverNonPagedSections
SmcStorePlacementGet