PnprAddMemoryResources

INT64 __stdcall PnprAddMemoryResources(_DEVICE_OBJECT *DeviceObject, _PNP_REPLACE_MEMORY_LIST **MemoryListOut){
  _PNP_REPLACE_MEMORY_LIST *v3; 
  _PNP_REPLACE_MEMORY_LIST *v4; 
  __int64 v5; 
  unsigned int *v6; 
  UINT64 v7; 
  int v8; 
  int v9; 
  unsigned int v10; 
  unsigned int v12; 
  _DWORD *v13; 
  __int64 v14; 
  ULONG Count; 
  UINT8 *PoolWithTag; 
  _PNP_REPLACE_MEMORY_LIST *v17; 
  UINT64 v18; 
  UINT64 v19; 
  int v20; 
  int v21; 
  ULONG v22; 
  unsigned __int64 Start; 
  UINT8 *v24; 
  PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor; 
  Start = 0i64;
  v3 = *MemoryListOut;
  v4 = *MemoryListOut;
  if( DeviceObject )
    v5 = *(_QWORD *)(*((_QWORD *)DeviceObject + 39) + 40i64);
  else
    v5 = 0i64;
  v6 = *(unsigned int **)(v5 + 416);
  if( !v6 )
  {
    v7 = PnprContext;
    v8 = *(_DWORD *)(PnprContext + 20984);
    if( !v8 )
      v8 = 632;
    *(_DWORD *)(PnprContext + 20984) = v8;
    v9 = *(_DWORD *)(v7 + 20988);
    if( !v9 )
      v9 = 6;
    *(_DWORD *)(v7 + 20988) = v9;
    goto LABEL_10;
  }
  v12 = 0;
  v13 = v6 + 1;
  if( !*v6 )
  {
LABEL_10:
    *MemoryListOut = v3;
    if( v3 != v4 )
      ExFreePoolWithTag(v4, 0x51706E50u);
    return 0;
  }
  while( 1 )
  {
    v14 = 0i64;
    if( v13[3] )
      break;
LABEL_24:
    ++v12;
    v13 = (_DWORD *)((char *)v13 + (unsigned int)(v14 + 36));
    if( v12 >= *v6 )
      goto LABEL_10;
  }
  while( 1 )
  {
    Descriptor = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)&v13[4 * v14 + 4 + v14];
    if( ((*(_BYTE *)Descriptor - 3) & 0xFB) == 0 )
      break;
LABEL_23:
    v14 = (unsigned int)(v14 + 1);
    if( (unsigned int)v14 >= v13[3] )
      goto LABEL_24;
  }
  Count = v3->Count;
  if( Count != v3->AllocatedCount )
  {
LABEL_22:
    v18 = RtlCmDecodeMemIoResource(Descriptor, &Start);
    v3->Ranges[v3->Count].Address.QuadPart = Start;
    v3->Ranges[v3->Count].Length = v18;
    v3->TotalLength += v18;
    ++v3->Count;
    goto LABEL_23;
  }
  v22 = Count + 4;
  PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(NonPagedPoolNx, 16 * (Count + 5), 0x51706E50ui64);
  v24 = PoolWithTag;
  if( PoolWithTag )
  {
    memmove(PoolWithTag, (UINT8 *)v3, 16 * (Count + 1));
    v17 = (_PNP_REPLACE_MEMORY_LIST *)v24;
    *(_DWORD *)v24 = v22;
    if( v3 != v4 )
      ExFreePoolWithTag(v3, 0x51706E50u);
    v3 = v17;
    goto LABEL_22;
  }
  v19 = PnprContext;
  v10 = -1073741670;
  v20 = *(_DWORD *)(PnprContext + 20984);
  if( !v20 )
    v20 = 672;
  *(_DWORD *)(PnprContext + 20984) = v20;
  v21 = *(_DWORD *)(v19 + 20988);
  if( !v21 )
    v21 = 10;
  *(_DWORD *)(v19 + 20988) = v21;
  *MemoryListOut = v4;
  if( v3 != v4 )
    ExFreePoolWithTag(v3, 0x51706E50u);
  return v10;
}

Referenced by:

PnprAddDeviceResources