MalwareSourceCode/MSIL/Virus/Win32/E/Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07/Microsoft/InfoCards/ProcessMonitor.cs
2022-08-18 06:28:56 -05:00

60 lines
1.7 KiB
C#

// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.ProcessMonitor
// 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 System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Microsoft.InfoCards
{
internal class ProcessMonitor
{
private static ProcessMonitor s_current = new ProcessMonitor();
private Dictionary<int, Process> m_cache;
private object m_sync;
private ProcessMonitor()
{
this.m_sync = new object();
this.m_cache = new Dictionary<int, Process>();
}
public static Process GetProcessById(int id) => ProcessMonitor.s_current.InnerGetProcessById(id);
private Process InnerGetProcessById(int id)
{
Process process = (Process) null;
lock (this.m_sync)
{
if (!this.m_cache.TryGetValue(id, out process))
{
process = Process.GetProcessById(id);
if (!process.HasExited)
{
this.InitializeProcessObject(process);
this.m_cache.Add(process.Id, process);
}
}
}
return process;
}
private void InitializeProcessObject(Process process)
{
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(this.Process_Exited);
}
private void Process_Exited(object sender, EventArgs e)
{
Process process = (Process) sender;
lock (this.m_sync)
this.m_cache.Remove(process.Id);
process.Exited -= new EventHandler(this.Process_Exited);
}
}
}