A: 新增全局Process缓存类 (Infrastructure/GlobalCaches/ProcessCache.cs) A: 新增WinDivert封装和PacketSniffer数据包捕获功能 (WinDivertNet/WinDivertWrapper) A: 新增Todo文档 (ClientApp/doc/Todo.md) U: 配置生成路由显示 (ClientApp/src/constants/app.ts) U: WebPanel新增数据包捕获触发逻辑 (Shell/Views/WebPanel.xaml.cs) U: 配置Shell项目加载WinDivert相关文件 (Shell/Shell.csproj)
33 lines
994 B
C#
33 lines
994 B
C#
using System.Drawing;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Infrastructure.utils;
|
|
|
|
|
|
public static class IconHelper
|
|
{
|
|
[DllImport("Shell32.dll", CharSet = CharSet.Auto)]
|
|
private static extern IntPtr ExtractIcon(IntPtr hInst, string lpszExeFileName, int nIconIndex);
|
|
|
|
/// <summary>
|
|
/// 获取 ICON
|
|
/// </summary>
|
|
/// <param name="exePath"></param>
|
|
/// <returns></returns>
|
|
public static string GetIconBase64(string? exePath)
|
|
{
|
|
if (exePath == null && !File.Exists(exePath)) return "";
|
|
IntPtr hIcon = ExtractIcon(IntPtr.Zero, exePath, 0);
|
|
if (hIcon == IntPtr.Zero) return "";
|
|
|
|
using Icon icon = Icon.FromHandle(hIcon);
|
|
using Bitmap bmp = icon.ToBitmap();
|
|
using MemoryStream ms = new MemoryStream();
|
|
// 保存为 PNG 格式
|
|
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
byte[] bytes = ms.ToArray();
|
|
return Convert.ToBase64String(bytes);
|
|
}
|
|
}
|