NtSetThreadExecutionState

NTSTATUS __stdcall NtSetThreadExecutionState(UINT64 NewFlags, UINT64 *PreviousFlags){
  int v3; 
  CHAR v4; 
  _ETHREAD *CurrentThread; 
  __int64 v6; 
  void *v7; 
  NTSTATUS UserPowerRequest; 
  PVOID v9; 
  unsigned int LegacyPowerRequestFlags; 
  EVENT_DESCRIPTOR *v11; 
  UINT64 v13; 
  bool v14; 
  unsigned int SessionId; 
  UINT8 v16; 
  __int64 v17[7]; 
  UINT64 OldFlags; 
  PVOID P; 
  v3 = NewFlags;
  LODWORD(OldFlags) = 0;
  P = 0i64;
  v4 = *((_BYTE *)KeGetCurrentThread() + 562);
  if( !v4 )
    return -1073741637;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( (NewFlags & 0x7FFFFFBC) != 0 || (NewFlags & 0x40) != 0 && (NewFlags & 0x80000000) == 0i64 )
    return -1073741811;
  v6 = 0x7FFFFFFF0000i64;
  if( (unsigned __int64)PreviousFlags < 0x7FFFFFFF0000i64 )
    v6 = (__int64)PreviousFlags;
  *(_DWORD *)v6 = *(_DWORD *)v6;
  v7 = (void *)*((_QWORD *)CurrentThread + 156);
  v17[0] = (__int64)v7;
  if( v7 || v3 >= 0 )
    goto LABEL_11;
  UserPowerRequest = PoCaptureReasonContext(0i64, v4, 0i64, 1, 0i64, (INT64 *)&P);
  if( UserPowerRequest < 0 )
    return UserPowerRequest;
  v9 = P;
  UserPowerRequest = PopCreateUserPowerRequest(v17, 0, (INT64)P);
  if( UserPowerRequest >= 0 )
  {
    v7 = (void *)v17[0];
    *((_QWORD *)CurrentThread + 156) = v17[0];
LABEL_11:
    LegacyPowerRequestFlags = PopGetLegacyPowerRequestFlags(v7, (unsigned int)v3, &OldFlags);
    *(_DWORD *)PreviousFlags = OldFlags;
    if( v3 >= 0 )
    {
      PopDiagTraceSetThreadExecutionState((__int64)CurrentThread, v3, v11);
      if( (v3 & 1) != 0 )
      {
        PopAcquirePolicyLock();
        PopSystemRequiredSet(v13);
        PopReleasePolicyLock();
      }
      if( (v3 & 2) != 0 )
      {
        PoEnergyContextUpdateComponentPower(*((_QWORD **)KeGetCurrentThread() + 23), 12, 3i64);
        PopAcquirePolicyLock();
        v14 = 0;
        if( PopPlatformAoAc && !PopLidOpened )
          v14 = (_BYTE)PopConsoleExternalDisplayConnected == 0;
        PopReleasePolicyLock();
        SessionId = MmGetSessionIdEx(*((_QWORD *)KeGetCurrentThread() + 23));
        if( SessionIsInteractive(SessionId) && !v14 )
          PopNotifyConsoleUserPresent(1u, v16, MonitorRequestReasonSetThreadExecutionState);
      }
    }
    else
    {
      PopApplyLegacyPowerRequestFlags(v7, (unsigned int)v3, LegacyPowerRequestFlags);
    }
    return 0;
  }
  if( v9 )
    PoDestroyReasonContext(v9);
  return UserPowerRequest;
}

Referenced by:

No references.