PspPrepareSystemDllInitBlock

INT64 __fastcall PspPrepareSystemDllInitBlock(INT64 a1, INT64 a2){
  __int64 v3; 
  UINT64 CfgBitMapInformation; 
  UINT64 v5; 
  INT64 v6; 
  __int64 v7; 
  unsigned int ProcessNtdllType; 
  _QWORD *v9; 
  int v10; 
  unsigned __int8 i; 
  int v13; 
  _QWORD *SharedInformation; 
  __int16 v15; 
  __int128 v16; 
  __int64 v17; 
  __int128 v18; 
  __int64 v19; 
  MMPTE *v20; 
  MMPTE *v21; 
  v3 = 0i64;
  CfgBitMapInformation = 0i64;
  v20 = 0i64;
  v5 = 0i64;
  v21 = 0i64;
  v6 = *((_QWORD *)KeGetCurrentThread() + 23);
  if( (_DWORD)a1 )
  {
    v13 = a1 - 1;
    if( v13 )
    {
      if( v13 != 1 )
        goto LABEL_3;
      SharedInformation = PspWow64GetSharedInformation(2i64);
    }
    else
    {
      SharedInformation = PspWow64GetSharedInformation(1i64);
    }
    v3 = SharedInformation[7];
    CfgBitMapInformation = MmGetCfgBitMapInformation(1i64, &v20);
    goto LABEL_3;
  }
  v3 = PspSystemDllInitBlock;
  CfgBitMapInformation = MmGetCfgBitMapInformation(a1, &v20);
  v7 = *(_QWORD *)(v6 + 1408);
  if( v7 )
  {
    v15 = *(_WORD *)(v7 + 8);
    if( v15 == 332 || v15 == 452 )
      v5 = MmGetCfgBitMapInformation(1i64, &v21);
  }
LABEL_3:
  if( a2 )
  {
    v16 = *(_OWORD *)(a2 + 360);
    v17 = *(_QWORD *)(a2 + 376);
    v18 = *(_OWORD *)(a2 + 488);
    v19 = *(_QWORD *)(a2 + 504);
  }
  else
  {
    v16 = 0i64;
    v17 = 0i64;
    v18 = 0i64;
    v19 = 0i64;
  }
  if( *(_DWORD *)v3 != 240 )
    return 3221225561i64;
  *(_QWORD *)(v3 + 16) = PspSystemDlls[8];
  ProcessNtdllType = PsWow64GetProcessNtdllType(v6);
  if( !ProcessNtdllType )
    ProcessNtdllType = 1;
  v9 = PspWow64GetSharedInformation(ProcessNtdllType);
  *(_QWORD *)(v3 + 8) = (&PspSystemDlls)[v10][8];
  for( i = 0; i < 0x10u; ++i )
    *(_QWORD *)(v3 + 8i64 * i + 24) = v9[i];
  *(_DWORD *)(v3 + 152) = ExGenRandom(1i64);
  *(_DWORD *)(v3 + 156) = 0;
  if( a2 )
  {
    if( (*(_BYTE *)(a2 + 9) & 2) != 0 )
      *(_DWORD *)(v3 + 156) |= 1u;
  }
  *(_OWORD *)(v3 + 160) = v16;
  *(_QWORD *)(v3 + 176) = v17;
  *(_OWORD *)(v3 + 216) = v18;
  *(_QWORD *)(v3 + 232) = v19;
  *(_QWORD *)(v3 + 184) = CfgBitMapInformation;
  *(_QWORD *)(v3 + 192) = v20;
  *(_QWORD *)(v3 + 200) = v5;
  *(_QWORD *)(v3 + 208) = v21;
  return 0i64;
}

Referenced by:

PspAllocateProcess
PspSetupUserProcessAddressSpace