RtlpValidRelativeAttribute

UINT8 __fastcall RtlpValidRelativeAttribute(
        _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 *RelativeAttribute,
        UINT64 RelativeAttributeSize){
  unsigned int v2; 
  __int64 Name; 
  int v5; 
  ULONG ValueCount; 
  unsigned __int64 v7; 
  USHORT ValueType; 
  unsigned int v9; 
  union _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::$F8600A37A74FD5E8A633BFFD12DED29B *i; 
  union _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::$F8600A37A74FD5E8A633BFFD12DED29B *m; 
  __int64 v13; 
  union _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::$F8600A37A74FD5E8A633BFFD12DED29B *k; 
  __int64 v15; 
  int v16; 
  union _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1::$F8600A37A74FD5E8A633BFFD12DED29B *j; 
  __int64 v18; 
  unsigned int v19; 
  int v20; 
  __int64 v21; 
  size_t pcbLength; 
  v2 = RelativeAttributeSize;
  if( RelativeAttribute )
  {
    if( (unsigned int)RelativeAttributeSize >= 0x14
      && !RelativeAttribute->Reserved
      && (RelativeAttribute->Flags & 0xFFC0) == 0 )
    {
      if( RelativeAttribute->ValueCount )
      {
        Name = RelativeAttribute->Name;
        if( (unsigned int)RelativeAttributeSize >= (unsigned int)Name
          && (unsigned int)(RelativeAttributeSize - Name) >= 4
          && (int)RtlStringCbLengthW(
                    (const WCHAR *)((char *)RelativeAttribute + Name),
                    (unsigned int)(RelativeAttributeSize - Name),
                    &pcbLength) >= 0 )
        {
          ValueCount = RelativeAttribute->ValueCount;
          v7 = 4i64 * ValueCount;
          if( v7 <= 0xFFFFFFFF && v2 - 16 >= (unsigned int)v7 )
          {
            ValueType = RelativeAttribute->ValueType;
            if( ValueType )
            {
              v9 = v5 + 2;
              if( ValueType <= (unsigned __int16)(v5 + 2) )
              {
                if( ValueCount )
                {
                  for( i = &RelativeAttribute->Values; v2 >= i->pInt64[0] && v2 - i->pInt64[0] >= 8; ++i )
                  {
                    if( ++v5 >= ValueCount )
                      return 1;
                  }
                  return 0;
                }
                return 1;
              }
              switch( ValueType )
              {
                case 3u:
                  v20 = v5;
                  if( ValueCount )
                  {
                    while( 1 )
                    {
                      v21 = RelativeAttribute->Values.pInt64[v20];
                      if( v2 < (unsigned int)v21
                        || v2 - (unsigned int)v21 < v9
                        || (int)RtlStringCbLengthW(
                                  (const WCHAR *)((char *)RelativeAttribute + v21),
                                  v2 - (unsigned int)v21,
                                  &pcbLength) < 0 )
                      {
                        break;
                      }
                      if( ++v20 >= RelativeAttribute->ValueCount )
                        return 1;
                    }
                    return 0;
                  }
                  return 1;
                case 5u:
                  v16 = v5;
                  if( ValueCount )
                  {
                    for( j = &RelativeAttribute->Values; ; ++j )
                    {
                      v18 = j->pInt64[0];
                      if( v2 < (unsigned int)v18 )
                        break;
                      if( v2 - (unsigned int)v18 < 4 )
                        break;
                      v19 = *(ULONG *)((char *)&RelativeAttribute->Name + v18);
                      if( !v19 || (int)v18 + 4 < (unsigned int)v18 || v2 - ((_DWORD)v18 + 4) < v19 )
                        break;
                      if( ++v16 >= ValueCount )
                        return 1;
                    }
                    return 0;
                  }
                  return 1;
                case 6u:
                  if( ValueCount )
                  {
                    for( k = &RelativeAttribute->Values; ; ++k )
                    {
                      v15 = k->pInt64[0];
                      if( v2 < (unsigned int)v15
                        || v2 - (unsigned int)v15 < 8
                        || *(_QWORD *)((char *)&RelativeAttribute->Name + v15) > 1ui64 )
                      {
                        break;
                      }
                      if( ++v5 >= ValueCount )
                        return 1;
                    }
                    return 0;
                  }
                  return 1;
                case 0x10u:
                  if( ValueCount )
                  {
                    for( m = &RelativeAttribute->Values; ; ++m )
                    {
                      v13 = m->pInt64[0];
                      if( v2 < (unsigned int)v13
                        || v2 - (unsigned int)v13 < 4
                        || (int)v13 + 4 < (unsigned int)v13
                        || v2 - ((_DWORD)v13 + 4) < *(ULONG *)((char *)&RelativeAttribute->Name + v13) )
                      {
                        break;
                      }
                      if( ++v5 >= ValueCount )
                        return 1;
                    }
                    return 0;
                  }
                  return 1;
              }
            }
          }
        }
      }
    }
  }
  return 0;
}

Referenced by:

RtlpValidAttributeAce