AlpcpCaptureMessageData

INT64 __fastcall AlpcpCaptureMessageData(INT64 a1, UINT64 a2, CHAR *a3){
  unsigned __int64 v6; 
  UINT64 v7; 
  __int64 v8; 
  __int64 v9; 
  UINT64 v10; 
  void *v11; 
  ULONG_PTR v12; 
  ULONG_PTR v14; 
  void *v15; 
  UINT64 v16; 
  VOID *PoolWithTag; 
  ULONG_PTR v18; 
  int v19; 
  ULONG_PTR v20; 
  v6 = AlpcpAvailableBufferSize(a1);
  v10 = v6;
  if( v7 <= v6 )
  {
    if( v9 )
      memmove((UINT8 *)(v8 + 280), (UINT8 *)a3, v7);
    v11 = *(void **)(a1 + 224);
    if( v11 )
    {
      ExFreePoolWithTag(v11, 0x42456C41u);
      v12 = *(_QWORD *)(a1 + 48);
      *(_QWORD *)(a1 + 224) = 0i64;
      if( v12 )
        AlpcpReleasePagedPoolQuota(v12, *(_QWORD *)(a1 + 232));
      *(_QWORD *)(a1 + 232) = 0i64;
    }
    return 0i64;
  }
  if( a2 > 0xFFD7 )
    return 2147483653i64;
  v14 = *(_QWORD *)(v8 + 232);
  if( a2 <= v14 + v6 )
  {
LABEL_20:
    if( a3 )
    {
      memmove((UINT8 *)(a1 + 280), (UINT8 *)a3, v10);
      memmove(*(UINT8 **)(a1 + 224), (UINT8 *)&a3[v10], a2 - v10);
    }
    return 0i64;
  }
  v15 = *(void **)(v8 + 224);
  if( v15 )
  {
    ExFreePoolWithTag(v15, 0x42456C41u);
    *(_QWORD *)(a1 + 232) = 0i64;
  }
  v16 = a2 - v10;
  PoolWithTag = ExAllocatePoolWithTag(PagedPool, a2 - v10, 0x42456C41ui64);
  v18 = *(_QWORD *)(a1 + 48);
  *(_QWORD *)(a1 + 224) = PoolWithTag;
  if( PoolWithTag )
  {
    *(_QWORD *)(a1 + 232) = v16;
    if( v18 )
    {
      v19 = AlpcpChargePagedPoolQuota(v18, v16 - v14);
      if( v19 < 0 )
      {
        ExFreePoolWithTag(*(PVOID *)(a1 + 224), 0x42456C41u);
        v20 = *(_QWORD *)(a1 + 48);
        *(_QWORD *)(a1 + 224) = 0i64;
        *(_QWORD *)(a1 + 232) = 0i64;
        AlpcpReleasePagedPoolQuota(v20, v14);
        return(unsigned int)v19;
      }
    }
    goto LABEL_20;
  }
  if( v18 )
    AlpcpReleasePagedPoolQuota(v18, v14);
  return 3221225626i64;
}

Referenced by:

AlpcpCreateReserve
AlpcpReplyLegacySynchronousRequest
AlpcpSendLegacySynchronousRequest
AlpcpSendMessage
AlpcpSetupMessageDataForDeferredCopy