AlpcpCaptureMessageDataSafe

void __fastcall AlpcpCaptureMessageDataSafe(__int64 a1){
  UINT8 *v2; 
  unsigned __int64 v3; 
  unsigned __int64 v4; 
  __int64 v5; 
  UINT64 v6; 
  void *v7; 
  ULONG_PTR v8; 
  ULONG_PTR v9; 
  void *v10; 
  unsigned __int64 v11; 
  VOID *PoolWithTag; 
  ULONG_PTR v13; 
  v2 = *(UINT8 **)(a1 + 176);
  v3 = *(unsigned __int16 *)(a1 + 240);
  v4 = AlpcpAvailableBufferSize(a1);
  v6 = v4;
  if( v3 <= v4 )
  {
    if( v2 )
      memmove((UINT8 *)(v5 + 280), v2, (unsigned int)v3);
    v7 = *(void **)(a1 + 224);
    if( v7 )
    {
      ExFreePoolWithTag(v7, 0x42456C41u);
      *(_QWORD *)(a1 + 224) = 0i64;
      v8 = *(_QWORD *)(a1 + 48);
      if( v8 )
        AlpcpReleasePagedPoolQuota(v8, *(_QWORD *)(a1 + 232));
      *(_QWORD *)(a1 + 232) = 0i64;
    }
    return;
  }
  if( v3 > 0xFFD7 )
    return;
  v9 = *(_QWORD *)(v5 + 232);
  if( v3 > v9 + v4 )
  {
    v10 = *(void **)(v5 + 224);
    if( v10 )
    {
      ExFreePoolWithTag(v10, 0x42456C41u);
      *(_QWORD *)(a1 + 232) = 0i64;
    }
    v11 = v3 - v6;
    PoolWithTag = ExAllocatePoolWithTag(PagedPool, v3 - v6, 0x42456C41ui64);
    *(_QWORD *)(a1 + 224) = PoolWithTag;
    v13 = *(_QWORD *)(a1 + 48);
    if( !PoolWithTag )
    {
      if( v13 )
        AlpcpReleasePagedPoolQuota(v13, v9);
      return;
    }
    *(_QWORD *)(a1 + 232) = v11;
    if( v13 && (int)AlpcpChargePagedPoolQuota(v13, v11 - v9) < 0 )
    {
      ExFreePoolWithTag(*(PVOID *)(a1 + 224), 0x42456C41u);
      *(_QWORD *)(a1 + 224) = 0i64;
      *(_QWORD *)(a1 + 232) = 0i64;
      AlpcpReleasePagedPoolQuota(*(_QWORD *)(a1 + 48), v9);
      return;
    }
  }
  if( v2 )
  {
    memmove((UINT8 *)(a1 + 280), v2, v6);
    memmove(*(UINT8 **)(a1 + 224), &v2[v6], v3 - v6);
  }
}

Referenced by:

AlpcpCompleteDispatchMessage
AlpcpDispatchReplyToWaitingThread