AlpcpFormatConnectionRequest

VOID __fastcall AlpcpFormatConnectionRequest(_KEVENT *Event, _EVENT_TYPE Type, UINT8 State){
  INT64 v3; 
  CHAR v4; 
  UINT16 *v5; 
  INT64 v6; 
  INT64 v7; 
  _KEVENT *v9; 
  int Message; 
  ULONG_PTR v11; 
  _WORD *v12; 
  UINT16 v13; 
  __int16 v14; 
  _PORT_VIEW *v15; 
  SIZE_T ViewSize; 
  void *v17; 
  ULONG_PTR BugCheckParameter2; 
  UINT16 *v20; 
  INT64 *v21; 
  _PORT_VIEW *ClientView; 
  _QWORD *v23; 
  CHAR v24; 
  CHAR v25; 
  v4 = v24;
  v5 = v20;
  v6 = v3;
  BugCheckParameter2 = 0i64;
  v7 = State;
  v9 = Event;
  if( !v3 || (int)AlpcpValidateConnectionMessage(**(_QWORD **)(State + 16i64), v20, v24) >= 0 )
  {
    Message = AlpcpAllocateMessage((__int64 *)&BugCheckParameter2, 0i64, 0i64);
    if( Message >= 0 )
    {
      v11 = BugCheckParameter2;
      if( v4 )
      {
        v15 = ClientView;
        if( ClientView )
        {
          Message = AlpcpMapLegacyPortView(
                      (_ALPC_PORT *)v7,
                      ClientView,
                      (_KALPC_MESSAGE_ATTRIBUTES *)(BugCheckParameter2 + 104));
          ViewSize = v15->ViewSize;
          v9 = Event;
          *(_QWORD *)(v11 + 272) = ViewSize;
        }
        else
        {
          v9 = Event;
          *(_QWORD *)(BugCheckParameter2 + 272) = 0i64;
        }
      }
      else
      {
        Message = AlpcpCaptureAttributes(v7, (unsigned int)Type, v21, BugCheckParameter2, BugCheckParameter2 + 104);
      }
      if( Message < 0 )
        goto LABEL_21;
      v12 = (_WORD *)BugCheckParameter2;
      *(_OWORD *)(BugCheckParameter2 + 248) = *(_OWORD *)((char *)KeGetCurrentThread() + 1144);
      v13 = *v5;
      v12[120] = *v5;
      v12[121] = v13 + 40;
      v14 = v12[122] & 0xFF00 | 0xA;
      v12[122] = v14;
      if( !*((_BYTE *)KeGetCurrentThread() + 562) )
        v12[122] = v14 | v5[2] & 0x8000;
      v11 = BugCheckParameter2;
      if( *v5
        && (int)AlpcpSetupMessageDataForDeferredCopy(BugCheckParameter2, v6, (unsigned int)Type, *v5, v4, v25) < 0 )
      {
LABEL_21:
        AlpcpUnlockMessage(v11);
      }
      else
      {
        if( v4 )
        {
          v17 = *(void **)(v11 + 144);
          if( v17 )
          {
            *v23 = v17;
            AlpcpReferenceBlob(v17);
          }
        }
        *(_QWORD *)&v9->Header.Lock = v11;
      }
    }
  }
}

Referenced by:

AlpcpProcessConnectionRequest
NtSecureConnectPort