RtlCopySidAndAttributesArray

NTSTATUS __stdcall RtlCopySidAndAttributesArray(
        UINT64 ArrayLength,
        _SID_AND_ATTRIBUTES *Source,
        UINT64 TargetSufferSize,
        _SID_AND_ATTRIBUTES *TargetArrayElement,
        VOID *TargetSid,
        VOID **NextTargetSid,
        UINT64 *RemainingTargetSufferSize){
  unsigned int v8; 
  unsigned int v9; 
  unsigned int v10; 
  unsigned int *p_Attributes; 
  signed __int64 v12; 
  unsigned int v13; 
  unsigned __int8 *v14; 
  size_t v15; 

  v8 = 0;
  v9 = TargetSufferSize;
  v10 = ArrayLength;
  if( (_DWORD)ArrayLength )
  {
    p_Attributes = &TargetArrayElement->Attributes;
    v12 = (char *)Source - (char *)TargetArrayElement;
    while( 1 )
    {
      v13 = 4 * *(unsigned __int8 *)(*(_QWORD *)((char *)p_Attributes + v12 - 8) + 1i64) + 8;
      if( v13 > v9 )
        return -1073741789;
      *((_QWORD *)p_Attributes - 1) = TargetSid;
      v9 -= v13;
      *p_Attributes = *(unsigned int *)((char *)p_Attributes + v12);
      v14 = *(unsigned __int8 **)((char *)p_Attributes + v12 - 8);
      v15 = 4 * v14[1] + 8;
      if( v15 <= v13 )
        memmove(TargetSid, v14, v15);
      ++v8;
      TargetSid = (char *)TargetSid + v13;
      p_Attributes += 4;
      if( v8 >= v10 )
        goto LABEL_7;
    }
  }
  else
  {
LABEL_7:
    *NextTargetSid = TargetSid;
    *(_DWORD *)RemainingTargetSufferSize = v9;
    return 0;
  }
}

Referenced by:

CmpBuildAdminInformation
NtQueryInformationToken
SeQueryInformationToken
SepCopyTokenAccessInformation
SepCreateTokenEx
SepFilterToken