v0.1.1
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// File: Models/ConcurrentDTO.cs
|
||||
|
||||
namespace WebmrAPI.Models
|
||||
{
|
||||
public class ConcurrentDTO
|
||||
{
|
||||
internal readonly object _lock = new object();
|
||||
|
||||
public void LockedSet<T>(ref T dst, T value)
|
||||
{
|
||||
lock (_lock) dst = value;
|
||||
}
|
||||
|
||||
public T LockedGet<T>(ref T src)
|
||||
{
|
||||
lock (_lock) return src;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// File: Models/MemoryRegion.cs
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WebmrAPI.Models
|
||||
{
|
||||
public class MemoryRegion : ConcurrentDTO
|
||||
{
|
||||
private long _addr = 0;
|
||||
private ulong _size = 0;
|
||||
|
||||
[JsonIgnore]
|
||||
public long MemoryAddress
|
||||
{
|
||||
get => LockedGet(ref _addr);
|
||||
set => LockedSet(ref _addr, value);
|
||||
}
|
||||
public ulong MemorySize
|
||||
{
|
||||
get => LockedGet(ref _size);
|
||||
set => LockedSet(ref _size, value);
|
||||
}
|
||||
public string? BaseAddress
|
||||
{
|
||||
get => (MemoryAddress > 0) ? $"0x{MemoryAddress:X12}" : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,27 @@
|
||||
// File: Models/MemoryRegionInfo.cs
|
||||
|
||||
namespace WebmrAPI.Models
|
||||
{
|
||||
public class MemoryRegionInfo
|
||||
public class MemoryRegionInfo : MemoryRegion
|
||||
{
|
||||
public string BaseAddress { get; set; } = string.Empty;
|
||||
public long RegionSize { get; set; }
|
||||
public string State { get; set; } = string.Empty;
|
||||
public string Protect { get; set; } = string.Empty;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
private string _state = String.Empty;
|
||||
private string _protect = String.Empty;
|
||||
private string _type = String.Empty;
|
||||
|
||||
public string State
|
||||
{
|
||||
get => LockedGet(ref _state);
|
||||
set => LockedSet(ref _state, value);
|
||||
}
|
||||
public string Protect
|
||||
{
|
||||
get => LockedGet(ref _protect);
|
||||
set => LockedSet(ref _protect, value);
|
||||
}
|
||||
public string Type
|
||||
{
|
||||
get => LockedGet(ref _type);
|
||||
set => LockedSet(ref _type, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// File: Models/ProcessBaseInfo.cs
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WebmrAPI.Models
|
||||
{
|
||||
public enum ProcessStatus
|
||||
{
|
||||
Undefined,
|
||||
Running,
|
||||
NotResponding
|
||||
}
|
||||
|
||||
public class ProcessBaseInfo : MemoryRegion
|
||||
{
|
||||
private TimeSpan _lastPTime = TimeSpan.Zero;
|
||||
private TimeSpan _curPTime = TimeSpan.Zero;
|
||||
|
||||
private int _pid = 0;
|
||||
private int _ppid = -1;
|
||||
private int _tcount = 0;
|
||||
private string? _name = null;
|
||||
private string? _fname = null;
|
||||
private string? _cmd = null;
|
||||
private ProcessStatus _status = ProcessStatus.Undefined;
|
||||
private DateTime? _startTime = null;
|
||||
private double _cpuUsage = 0;
|
||||
|
||||
[JsonIgnore]
|
||||
public TimeSpan TotalProcessorTime
|
||||
{
|
||||
set { lock (_lock) { _lastPTime = _curPTime; _curPTime = value; } }
|
||||
}
|
||||
[JsonIgnore]
|
||||
public double ProcessorTime
|
||||
{
|
||||
get { lock (_lock) return (_lastPTime - _curPTime).TotalMilliseconds; }
|
||||
}
|
||||
public int PID
|
||||
{
|
||||
get => LockedGet(ref _pid);
|
||||
set => LockedSet(ref _pid, value);
|
||||
}
|
||||
public int ParentPID
|
||||
{
|
||||
get => LockedGet(ref _ppid);
|
||||
set => LockedSet(ref _ppid, value);
|
||||
}
|
||||
public string? Name
|
||||
{
|
||||
get => LockedGet(ref _name);
|
||||
set => LockedSet(ref _name, value);
|
||||
}
|
||||
public string? FileName
|
||||
{
|
||||
get => LockedGet(ref _fname);
|
||||
set => LockedSet(ref _fname, value);
|
||||
}
|
||||
public string? CommandLine
|
||||
{
|
||||
get => LockedGet(ref _cmd);
|
||||
set => LockedSet(ref _cmd, value);
|
||||
}
|
||||
public int ThreadCount
|
||||
{
|
||||
get => LockedGet(ref _tcount);
|
||||
set => LockedSet(ref _tcount, value);
|
||||
}
|
||||
public ProcessStatus Status
|
||||
{
|
||||
get => LockedGet(ref _status);
|
||||
set => LockedSet(ref _status, value);
|
||||
}
|
||||
public DateTime? StartTime
|
||||
{
|
||||
get => LockedGet(ref _startTime);
|
||||
set => LockedSet(ref _startTime, value);
|
||||
}
|
||||
public double CpuUsage
|
||||
{
|
||||
get => LockedGet(ref _cpuUsage);
|
||||
set => LockedSet(ref _cpuUsage, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-11
@@ -1,17 +1,26 @@
|
||||
using System.Collections.Concurrent;
|
||||
// File: Models/ProcessInfo.cs
|
||||
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WebmrAPI.Models
|
||||
{
|
||||
public class ProcessInfo
|
||||
[SupportedOSPlatform("windows")]
|
||||
public class ProcessInfo : ProcessBaseInfo
|
||||
{
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public int ProcessId { get; set; }
|
||||
public string ProcessName { get; set; } = string.Empty;
|
||||
public string? BaseAddress { get; set; }
|
||||
public long VirtualMemorySize { get; set; }
|
||||
public string? CommandLine { get; set; }
|
||||
|
||||
private DateTime _lastUpdate = DateTime.MinValue;
|
||||
private List<MemoryRegionInfo> _regions = new();
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime LastUpdate
|
||||
{
|
||||
get => LockedGet(ref _lastUpdate);
|
||||
set => LockedSet(ref _lastUpdate, value);
|
||||
}
|
||||
public List<MemoryRegionInfo> MemoryRegions
|
||||
{
|
||||
get => LockedGet(ref _regions);
|
||||
set => LockedSet(ref _regions, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace WebmrAPI.Services
|
||||
{
|
||||
public class ProcessModuleInfo
|
||||
{
|
||||
public string? ModuleName { get; set; }
|
||||
public string? FileName { get; set; }
|
||||
public string? BaseAddress { get; set; }
|
||||
public long MemorySize { get; set; }
|
||||
public string? EntrypointAddress { get; set; }
|
||||
|
||||
public static ProcessModuleInfo FromProcessModule(ProcessModule module)
|
||||
{
|
||||
return new ProcessModuleInfo
|
||||
{
|
||||
ModuleName = module.ModuleName,
|
||||
FileName = module.FileName,
|
||||
BaseAddress = "0x" + module.BaseAddress.ToInt64().ToString("X"),
|
||||
MemorySize = module.ModuleMemorySize,
|
||||
EntrypointAddress = "0x" + module.EntryPointAddress.ToInt64().ToString("X")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user