A:
This commit is contained in:
1 parent
2fb4de59d9
commit
2f6e912c58
2 files changed
+50
-3
No files matched your search
@@ -1,4 +1,3 @@
|
||||
|
||||
namespace Infrastructure.Models;
|
||||
|
||||
/// <summary>
|
||||
@@ -6,6 +5,11 @@ namespace Infrastructure.Models;
|
||||
/// </summary>
|
||||
public class ProgramInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 编译时间
|
||||
/// </summary>
|
||||
public DateTime? CompileTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 进程名称
|
||||
/// </summary>
|
||||
@@ -28,9 +32,9 @@ public class ProgramInfo
|
||||
|
||||
/*
|
||||
ExitTime 和 ExitCode 这两个属性只有在进程已经退出后才能访问。对于正在运行的进程,
|
||||
访问这些属性会抛出 "Process must exit before requested information can be determined" 异常。
|
||||
访问这些属性会抛出 "Process must exit before requested information can be determined" 异常。
|
||||
*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 退出时间
|
||||
/// </summary>
|
||||
@@ -95,6 +99,7 @@ public class ProgramInfo
|
||||
public class ApplicationInfoModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 进程名称
|
||||
/// </summary>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using Common;
|
||||
using Common.ExpandException;
|
||||
using Common.Logger;
|
||||
@@ -230,6 +231,21 @@ public static class SysInfoUtils
|
||||
Log.Information($"无法获取进程 {pid} 的图标: {ex.Message}");
|
||||
}
|
||||
|
||||
// 获取编译时间戳(PE Header 中的时间戳)
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(exeInfo.MainModulePath))
|
||||
{
|
||||
var compileTime = GetPECompileTime(exeInfo.MainModulePath);
|
||||
exeInfo.CompileTimestamp = compileTime;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information($"无法获取进程 {pid} 的编译时间戳: {ex.Message}");
|
||||
exeInfo.CompileTimestamp = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
ProcessCache.Instance.Set(pck, exeInfo);
|
||||
@@ -268,6 +284,32 @@ public static class SysInfoUtils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目编译时间
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
private static DateTime? GetPECompileTime(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
using var reader = new BinaryReader(fs);
|
||||
|
||||
fs.Seek(0x3C, SeekOrigin.Begin);
|
||||
int peOffset = reader.ReadInt32();
|
||||
|
||||
fs.Seek(peOffset + 8, SeekOrigin.Begin);
|
||||
int timestamp = reader.ReadInt32();
|
||||
|
||||
return DateTimeOffset.FromUnixTimeSeconds(timestamp).LocalDateTime;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取程序路径(名称)
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user