PopEtEnergyTrackerCreate

INT64 __fastcall PopEtEnergyTrackerCreate(INT64 *a1, VOID **a2){
  int v2; 
  bool v5; 
  int inserted; 
  PADAPTER_OBJECT v7; 
  PADAPTER_OBJECT v8; 
  UINT64 UnbiasedInterruptTime; 
  _POP_RW_LOCK *v10; 
  __int64 v11; 
  _DMA_OPERATIONS *v12; 
  int v13; 
  PVOID v14; 
  __int64 Flags; 
  UINT64 Flagsa; 
  __int128 v18; 
  __int128 v19; 
  int v20[2]; 
  __int64 v21; 
  __int64 v22; 
  int v23; 
  int v24; 
  __int128 v25; 
  PADAPTER_OBJECT DmaAdapter; 
  PVOID Handle; 
  v2 = *(_DWORD *)a1;
  DmaAdapter = 0i64;
  Handle = 0i64;
  v20[1] = 0;
  v24 = 0;
  v18 = 0i64;
  v19 = 0i64;
  if( (unsigned int)(v2 - 1) > 0x3FFFF )
    *(_DWORD *)a1 = 0x40000;
  if( PopEtGlobals )
  {
    v20[0] = 48;
    v21 = 0i64;
    v5 = *((_BYTE *)KeGetCurrentThread() + 562) != 0;
    v22 = 0i64;
    v25 = 0i64;
    v23 = v5 ? 0 : 0x200;
    inserted = ObCreateObjectEx(
                 0,
                 *(_DWORD **)(PopEtGlobals + 32),
                 (__int64)v20,
                 *((_BYTE *)KeGetCurrentThread() + 562),
                 Flags,
                 640,
                 0,
                 0,
                 &DmaAdapter,
                 0i64);
    if( inserted < 0 )
    {
      v8 = DmaAdapter;
    }
    else
    {
      v7 = DmaAdapter;
      memset((INT64)DmaAdapter, 0i64);
      v7[1] = 0i64;
      *(_QWORD *)&v7[1].Version = 0i64;
      *(_QWORD *)&v7[4].Version = 0i64;
      v7[4].DmaOperations = 0i64;
      *(_QWORD *)&v7[3].Version = 0i64;
      v7[3].DmaOperations = 0i64;
      memset((INT64)&v7[5], 0i64);
      *(_QWORD *)&v7[6].Version = PopEtGlobals + 848;
      *(_QWORD *)&v7[2].Version = *a1;
      LODWORD(v7[2].DmaOperations) = *((_DWORD *)a1 + 2);
      HIDWORD(v7[39].DmaOperations) |= 1u;
      v8 = DmaAdapter;
      *(_DWORD *)&DmaAdapter[37].Version = (KUSER_SHARED_DATA.TickCountQuad * KUSER_SHARED_DATA.TickCountMultiplier) >> 24;
      UnbiasedInterruptTime = KiQueryUnbiasedInterruptTime(1u);
      v10 = (_POP_RW_LOCK *)(PopEtGlobals + 16);
      *(_DWORD *)(&v8[37].Size + 1) = UnbiasedInterruptTime / 0x2710;
      LODWORD(v8[37].DmaOperations) = 1;
      PopAcquireRwLockExclusive(v10);
      v11 = PopEtGlobals;
      v12 = *(_DMA_OPERATIONS **)(PopEtGlobals + 8);
      if( *(_QWORD *)&v12->Size != PopEtGlobals )
        __fastfail(3u);
      *(_QWORD *)&v8->Version = PopEtGlobals;
      v8->DmaOperations = v12;
      *(_QWORD *)&v12->Size = v8;
      *(_QWORD *)(v11 + 8) = v8;
      PopReleaseRwLock(v11 + 16);
      v18 = 1ui64;
      v19 = (unsigned __int64)v8;
      inserted = PsEnumProcesses(
                   (__int64(__fastcall *)(unsigned __int64, __int64))PopEtProcessEnumSnapshotCallback,
                   (__int64)&v18);
      if( inserted >= 0 )
      {
        PopAcquireRwLockExclusive((_POP_RW_LOCK *)&v7[1]);
        v13 = *(_DWORD *)(&v8[38].Size + 1);
        if( !v13 )
          HIDWORD(v7[39].DmaOperations) &= ~1u;
        PopReleaseRwLock((UINT64)&v7[1]);
        if( v13 )
        {
          inserted = -1073741670;
        }
        else
        {
          LODWORD(Flagsa) = 0;
          inserted = ObInsertObjectEx(v8, 0i64, 1ui64, 1ui64, Flagsa, 0i64, &Handle);
          if( inserted < 0 )
          {
            v14 = Handle;
            v8 = 0i64;
          }
          else
          {
            v14 = 0i64;
            *a2 = Handle;
            inserted = 0;
          }
          if( v14 )
            NtClose(v14);
        }
      }
    }
    if( v8 )
      HalPutDmaAdapter(v8);
  }
  else
  {
    return(unsigned int)-1073741637;
  }
  return(unsigned int)inserted;
}

Referenced by:

NtPowerInformation