AlpcpProcessConnectionRequest

INT64 __fastcall AlpcpProcessConnectionRequest(
        _ALPC_PORT *ClientPort,
        UINT64 Flags,
        _PORT_MESSAGE *ConnectionMessage,
        UINT64 *BufferLength,
        _ALPC_MESSAGE_ATTRIBUTES *SendMessageAttributes,
        _ALPC_MESSAGE_ATTRIBUTES *ReceiveMessageAttributes,
        _LARGE_INTEGER *Timeout,
        INT64 ProbeMode,
        CHAR WaitMode){
  unsigned int v11; 
  _ALPC_PORT *v12; 
  INT64 v13; 
  INT64 v14; 
  __int64 v15; 
  _ALPC_MESSAGE_ATTRIBUTES *v16; 
  char v17; 
  __int64 v18; 
  INT64 result; 
  _KALPC_MESSAGE *v20; 
  UINT64 v21; 
  unsigned int v22; 
  unsigned int v23; 
  unsigned int v24; 
  ULONG_PTR v25; 
  int v26; 
  int v27; 
  UINT64 v28; 
  _ALPC_PORT *v29; 
  char *v30; 
  __int16 v31; 
  __int16 v32; 
  UINT64 v33; 
  PLARGE_INTEGER v34; 
  INT64 v35; 
  INT64 v36; 
  INT64 v37; 
  unsigned int ReceiveAttributes; 
  _KEVENT BugCheckParameter2; 
  LONGLONG v40; 
  __int128 v41; 
  __int128 v42; 
  __int64 v43; 
  _ALPC_DISPATCH_CONTEXT v44; 
  unsigned int MessageId; 
  unsigned int MessageIda; 
  v11 = Flags;
  v12 = ClientPort;
  memset((INT64)&v44, 0i64);
  *(_QWORD *)&BugCheckParameter2.Header.Lock = 0i64;
  v41 = 0i64;
  v42 = 0i64;
  v43 = 0i64;
  v40 = 0i64;
  if( (v11 & 0x10000) != 0 )
    return 3221225485i64;
  ReceiveAttributes = 0;
  BugCheckParameter2.Header.WaitListHead.Blink = (_LIST_ENTRY *)-1i64;
  if( (_BYTE)ProbeMode )
  {
    if( ConnectionMessage )
    {
      AlpcpProbeForWriteMessageHeader((UINT64)ConnectionMessage, v11);
      AlpcpProbeAndCaptureMessageHeader(ConnectionMessage, (_PORT_MESSAGE *)&v41, v11);
    }
    v15 = 0x7FFFFFFF0000i64;
    if( BufferLength )
    {
      v18 = 0x7FFFFFFF0000i64;
      if( (unsigned __int64)BufferLength < 0x7FFFFFFF0000i64 )
        v18 = (__int64)BufferLength;
      BugCheckParameter2.Header.WaitListHead.Blink = *(_LIST_ENTRY **)v18;
      *(_QWORD *)v18 = *(_QWORD *)v18;
    }
    v16 = ReceiveMessageAttributes;
    v17 = 1;
    if( ReceiveMessageAttributes )
    {
      LOBYTE(v13) = 1;
      ReceiveAttributes = AlpcpProbeMessageAttributes(
                            v11,
                            ReceiveMessageAttributes,
                            v13,
                            v14,
                            (INT64)v34,
                            v35,
                            v36,
                            v37);
    }
    if( Timeout )
    {
      if( (unsigned __int64)Timeout < 0x7FFFFFFF0000i64 )
        v15 = (__int64)Timeout;
      v40 = *(_QWORD *)v15;
      Timeout = (_LARGE_INTEGER *)&v40;
    }
    v12 = ClientPort;
  }
  else
  {
    if( ConnectionMessage )
    {
      v41 = *(_OWORD *)ConnectionMessage;
      v42 = *((_OWORD *)ConnectionMessage + 1);
      v43 = *((_QWORD *)ConnectionMessage + 4);
    }
    if( BufferLength )
      BugCheckParameter2.Header.WaitListHead.Blink = (_LIST_ENTRY *)*BufferLength;
    v16 = ReceiveMessageAttributes;
    v17 = 1;
    if( ReceiveMessageAttributes )
      ReceiveAttributes = ReceiveMessageAttributes->AllocatedAttributes;
  }
  AlpcpFormatConnectionRequest(&BugCheckParameter2, (_EVENT_TYPE)v11, (UINT8)v12);
  if( (int)result < 0 )
    return result;
  v20 = *(_KALPC_MESSAGE **)&BugCheckParameter2.Header.Lock;
  MessageId = *(_DWORD *)(*(_QWORD *)&BugCheckParameter2.Header.Lock + 264i64);
  if( AlpcpLogEnabled )
    AlpcpLogConnectRequest(*(UINT64 *)&BugCheckParameter2.Header.Lock);
  v44.PortObject = v12;
  v44.Message = v20;
  v44.Flags = v11;
  v22 = AlpcpDispatchConnectionRequest((INT64)&v44);
  if( (v22 & 0x80000000) != 0 )
  {
    if( AlpcpLogEnabled )
      AlpcpLogConnectFail(MessageId, v22);
    AlpcpUnlockMessage((ULONG_PTR)v20);
    return v22;
  }
  if( (v11 & 0x20000) == 0 )
    return v22;
  if( (v11 & 0x100000) == 0 )
    v17 = *((_BYTE *)KeGetCurrentThread() + 562);
  *(_QWORD *)&BugCheckParameter2.Header.Lock = 0i64;
  LOBYTE(v21) = v17;
  v23 = AlpcpReceiveSynchronousReply(&v44, v21, (_KALPC_MESSAGE **)&BugCheckParameter2, ReceiveAttributes, Timeout);
  v24 = v23;
  if( v23 )
  {
    if( AlpcpLogEnabled )
      AlpcpLogConnectFail(MessageId, v23);
    if( (*((_BYTE *)ClientPort + 416) & 0x10) != 0 )
      return(unsigned int)-1073741759;
  }
  else
  {
    if( AlpcpLogEnabled )
      AlpcpLogConnectSuccess(MessageId);
    v25 = *(_QWORD *)&BugCheckParameter2.Header.Lock;
    v26 = *(unsigned __int16 *)(*(_QWORD *)&BugCheckParameter2.Header.Lock + 240i64);
    v27 = 24;
    if( (v11 & 0xC0000000) != 0x80000000 )
      v27 = 40;
    v28 = (unsigned int)(v26 + v27);
    MessageIda = v28;
    if( BufferLength )
    {
      v33 = (unsigned int)v28;
      if( (_LIST_ENTRY *)(unsigned int)v28 > BugCheckParameter2.Header.WaitListHead.Blink )
      {
        AlpcpUnlockMessage(*(ULONG_PTR *)&BugCheckParameter2.Header.Lock);
        *BufferLength = v33;
        return 3221225507i64;
      }
    }
    if( ConnectionMessage )
    {
      LODWORD(BugCheckParameter2.Header.WaitListHead.Flink) = 0;
      if( (v11 & 0xC0000000) == 0x80000000 )
      {
        *(_WORD *)ConnectionMessage = v26;
        LODWORD(BugCheckParameter2.Header.WaitListHead.Flink) = *(unsigned __int16 *)(v25 + 240) + 24;
        *((_WORD *)ConnectionMessage + 1) = BugCheckParameter2.Header.WaitListHead.Flink;
        v31 = *(_WORD *)(v25 + 246);
        if( v31 )
          *((_WORD *)ConnectionMessage + 3) = v31 - 16;
        else
          *((_WORD *)ConnectionMessage + 3) = 0;
        v32 = *(_WORD *)(v25 + 244) | 0x1000;
        *((_WORD *)ConnectionMessage + 2) = v32;
        *((_DWORD *)ConnectionMessage + 2) = *(_DWORD *)(v25 + 248);
        *((_DWORD *)ConnectionMessage + 3) = *(_DWORD *)(v25 + 256);
        *((_DWORD *)ConnectionMessage + 4) = *(_DWORD *)(v25 + 264);
        *((_DWORD *)ConnectionMessage + 5) = *(_DWORD *)(v25 + 272);
        *((_DWORD *)ConnectionMessage + 5) = *(_DWORD *)(v25 + 272);
        v29 = ClientPort;
        if( (*((_DWORD *)ClientPort + 64) & 0x1000) != 0 )
          *((_WORD *)ConnectionMessage + 2) = v32 & 0xC00F;
        v30 = (char *)ConnectionMessage + 24;
      }
      else
      {
        *(_OWORD *)ConnectionMessage = *(_OWORD *)(*(_QWORD *)&BugCheckParameter2.Header.Lock + 240i64);
        *((_OWORD *)ConnectionMessage + 1) = *(_OWORD *)(v25 + 256);
        *((_QWORD *)ConnectionMessage + 4) = *(_QWORD *)(v25 + 272);
        v29 = ClientPort;
        if( (*((_DWORD *)ClientPort + 64) & 0x1000) != 0 )
          *((_WORD *)ConnectionMessage + 2) &= 0xC00Fu;
        LODWORD(BugCheckParameter2.Header.WaitListHead.Flink) = *(unsigned __int16 *)(v25 + 242);
        v30 = (char *)ConnectionMessage + 40;
      }
      if( *(_QWORD *)(v25 + 176) )
        AlpcpGetDataFromUserVaSafe(v25, v30);
      else
        AlpcpReadMessageData(v25, v30);
      v28 = MessageIda;
    }
    else
    {
      v29 = ClientPort;
    }
    if( BufferLength )
      *BufferLength = v28;
    if( v16 )
      AlpcpExposeAttributes((INT64)v29, v11, v25, ReceiveAttributes, (INT64)v16);
    AlpcpUnlockMessage(v25);
  }
  return v24;
}

Referenced by:

AlpcpConnectPort