SepVerifyDesktopAppxPackageName

NTSTATUS __stdcall SepVerifyDesktopAppxPackageName(VOID *Token, VOID *SecurityDescriptor, _BYTE *PackageNameVerified){
  int v5; 
  _UNICODE_STRING *v7; 
  VOID **PoolWithTag; 
  _AUTHZBASEP_SECURITY_ATTRIBUTES_INFORMATION *SecurityAttributesList; 
  _AUTHZBASEP_SECURITY_ATTRIBUTES_INFORMATION *v10; 
  __int16 v11; 
  __int64 v12; 
  _ACL *v13; 
  UINT8 *AceByType; 
  UINT8 *v15; 
  int v17; 
  UINT64 BufferLength; 
  UINT64 BufferLengtha; 
  UINT64 ConditionSize; 
  UINT64 pIndex; 
  INT64 Result; 
  _UNICODE_STRING DestinationString; 
  char pBuffer[512]; 

  Result = 0x200000000i64;
  pIndex = 0i64;
  *PackageNameVerified = 0;
  v5 = 0;
  DestinationString = 0i64;
  RtlInitUnicodeString(&DestinationString, L"WIN:
  if( !SeSecurityAttributePresent(Token, &DestinationString, v7) )
    return v5;
  LODWORD(BufferLength) = 512;
  PoolWithTag = (VOID **)pBuffer;
  v5 = SeQuerySecurityAttributesToken(Token, &DestinationString, 1ui64, pBuffer, BufferLength, &pIndex);
  if( v5 == -1073741789 )
  {
    v17 = pIndex;
    PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)pIndex, 538994003i64);
    if( !PoolWithTag )
      return -1073741801;
    LODWORD(BufferLengtha) = v17;
    v5 = SeQuerySecurityAttributesToken(Token, &DestinationString, 1ui64, PoolWithTag, BufferLengtha, &pIndex);
  }
  if( v5 < 0 )
    goto LABEL_16;
  if( !PoolWithTag )
    return -1073739509;
  SecurityAttributesList = AuthzBasepAllocateSecurityAttributesList();
  v10 = SecurityAttributesList;
  if( !SecurityAttributesList )
  {
    v5 = -1073741670;
    goto LABEL_16;
  }
  v5 = AuthzBasepSetSecurityAttributesToken(
         (_FADT *)SecurityAttributesList,
         (_TOKEN_SECURITY_ATTRIBUTE_OPERATION *)&Result + 1,
         (_TOKEN_SECURITY_ATTRIBUTES_INFORMATION *)PoolWithTag);
  if( v5 < 0 )
    goto LABEL_15;
  do
  {
    v11 = *((_WORD *)SecurityDescriptor + 1);
    if( (v11 & 4) == 0 )
      goto LABEL_27;
    if( v11 >= 0 )
    {
      v13 = (_ACL *)*((_QWORD *)SecurityDescriptor + 4);
      goto LABEL_11;
    }
    v12 = *((unsigned int *)SecurityDescriptor + 4);
    if( (_DWORD)v12 )
      v13 = (_ACL *)((char *)SecurityDescriptor + v12);
    else
LABEL_27:
      v13 = 0i64;
LABEL_11:
    AceByType = (UINT8 *)RtlFindAceByType(v13, 9ui64, (UINT64 *)((char *)&pIndex + 4));
    v15 = AceByType;
    if( AceByType )
    {
      LODWORD(ConditionSize) = *((unsigned __int16 *)AceByType + 1) - (4 * AceByType[9] + 8) - 8;
      v5 = AuthzBasepEvaluateAceCondition(
             Token,
             v10,
             0i64,
             0i64,
             0i64,
             0i64,
             0i64,
             &AceByType[4 * AceByType[9] + 16],
             ConditionSize,
             0,
             0,
             &Result);
      if( v5 < 0 )
        break;
      if( (_DWORD)Result == 1 )
        goto LABEL_14;
    }
    ++HIDWORD(pIndex);
  }
  while( v15 );
  if( (_DWORD)Result == 1 )
LABEL_14:
    *PackageNameVerified = 1;
LABEL_15:
  AuthzBasepFreeSecurityAttributesList(v10);
LABEL_16:
  if( PoolWithTag && PoolWithTag != (VOID **)pBuffer )
    ExFreePoolWithTag(PoolWithTag, 0);
  return v5;
}

Referenced by:

SepVerifyDesktopAppxImage