MalwareSourceCode/MSIL/Virus/Win32/E/Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07/Microsoft/InfoCards/LifeTimeMonitor.cs

96 lines
2.9 KiB
C#
Raw Normal View History

2022-08-18 11:28:56 +00:00
// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.LifeTimeMonitor
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe
using Microsoft.InfoCards.Diagnostics;
using Microsoft.Win32;
using System;
using System.ServiceProcess;
using System.Timers;
namespace Microsoft.InfoCards
{
internal class LifeTimeMonitor
{
private const int DefaultShutdownInterval = 3600000;
private const int MinimumShutdownInterval = 60000;
private const string ServiceIdleTimeValue = "ServiceIdleTime";
private int m_activeCount;
private bool m_isShuttingDown;
private Timer m_shutdownTimer;
private object m_syncRoot = new object();
public LifeTimeMonitor()
{
int interval = 3600000;
using (new SystemIdentity(false))
{
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(InfoCardConstants.RegistryKey, false))
{
if (registryKey != null)
{
object obj = registryKey.GetValue("ServiceIdleTime", (object) 3600000);
if (obj is int num)
{
if (num >= 60000)
interval = (int) obj;
}
}
}
}
this.m_activeCount = 0;
this.m_shutdownTimer = new Timer((double) interval);
this.m_shutdownTimer.Elapsed += new ElapsedEventHandler(this.OnShutdown);
this.m_shutdownTimer.AutoReset = false;
this.m_isShuttingDown = false;
this.StartShutdownTimer();
}
public void AddClient()
{
lock (this.m_syncRoot)
{
InfoCardTrace.Assert(this.m_activeCount >= 0, "incorrect active count");
if (this.m_isShuttingDown)
throw InfoCardTrace.ThrowHelperError((Exception) new ServiceBusyException());
++this.m_activeCount;
if (1 != this.m_activeCount)
return;
this.StopShutdownTimer();
}
}
public void RemoveClient()
{
lock (this.m_syncRoot)
{
InfoCardTrace.Assert(this.m_activeCount > 0, "invalid active count");
--this.m_activeCount;
if (this.m_activeCount != 0)
return;
this.StartShutdownTimer();
}
}
private void OnShutdown(object sender, ElapsedEventArgs args)
{
lock (this.m_syncRoot)
{
if (this.m_activeCount > 0)
return;
this.m_shutdownTimer.Enabled = false;
this.m_isShuttingDown = true;
InfoCardTrace.Audit(EventCode.AUDIT_SERVICE_IDLE_STOP);
}
using (new SystemIdentity(false))
new ServiceController("idsvc").Stop();
}
private void StartShutdownTimer() => this.m_shutdownTimer.Start();
private void StopShutdownTimer() => this.m_shutdownTimer.Stop();
}
}