Commit 9b4bb25b by liulongfei

DLL 安全校验

parent 8a28afd4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// 应用程序DLL检测
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
public class ApplicationDllCheckAttribute : Attribute
{
/// <summary>
/// 键
/// </summary>
public string Key { get; set; }
}
}
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
<Compile Include="Core\Net\NetHelperMacInfo.cs" /> <Compile Include="Core\Net\NetHelperMacInfo.cs" />
<Compile Include="Core\Object\IObjectPoolManager.cs" /> <Compile Include="Core\Object\IObjectPoolManager.cs" />
<Compile Include="Core\Object\ObjectPoolManager.cs" /> <Compile Include="Core\Object\ObjectPoolManager.cs" />
<Compile Include="Core\Safe\ApplicationDllCheckAttribute.cs" />
<Compile Include="Core\Safe\ApplicationMacCheckAttribute.cs" /> <Compile Include="Core\Safe\ApplicationMacCheckAttribute.cs" />
<Compile Include="Core\Safe\ApplicationTimeCheckAttribute.cs" /> <Compile Include="Core\Safe\ApplicationTimeCheckAttribute.cs" />
<Compile Include="Core\Image\ImageHelperExpand.cs" /> <Compile Include="Core\Image\ImageHelperExpand.cs" />
......
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Management;
using VIZ.Framework.Core;
using VIZ.Framework.Connection;
using VIZ.Framework.Module;
using System.Reflection;
namespace VIZ.Framework.Module
{
/// <summary>
/// 应用程序启动 -- Dll安全
/// </summary>
public abstract class AppSetup_DllSafeBase : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_DllSafeBase));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- Dll安全";
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
// 入口
ApplicationDllCheckAttribute entry_attribute = Assembly.GetEntryAssembly().GetCustomAttribute<ApplicationDllCheckAttribute>();
if (entry_attribute == null || string.IsNullOrWhiteSpace(entry_attribute.Key))
{
log.Error("dll check error.");
return false;
}
// 模块
ApplicationDllCheckAttribute module_attribute = this.GetType().Assembly.GetCustomAttribute<ApplicationDllCheckAttribute>();
if (module_attribute == null || string.IsNullOrWhiteSpace(module_attribute.Key))
{
log.Error("dll check error.");
return false;
}
// 不匹配
if (!string.Equals(entry_attribute.Key, module_attribute.Key))
{
log.Error("dll check error.");
return false;
}
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
}
/// <summary>
/// 获取所有用于MAC地址校验的值
/// </summary>
/// <returns>用于MAC地址校验的值</returns>
private List<string> getAllMacAddressForCheck()
{
List<string> list = new List<string>();
foreach (NetHelperMacInfo info in NetHelper.GetAllMacAddressWithDefaultFilter())
{
if (!string.IsNullOrWhiteSpace(info.PhysicalAddress))
{
list.Add(info.PhysicalAddress);
}
if (!string.IsNullOrWhiteSpace(info.DHCPv6ClientDUID))
{
list.Add(info.DHCPv6ClientDUID);
}
}
return list;
}
}
}
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
<Compile Include="Setup\AppSetupContext.cs" /> <Compile Include="Setup\AppSetupContext.cs" />
<Compile Include="Setup\IAppSetup.cs" /> <Compile Include="Setup\IAppSetup.cs" />
<Compile Include="Setup\Message\AppShutDownMessage.cs" /> <Compile Include="Setup\Message\AppShutDownMessage.cs" />
<Compile Include="Setup\Provider\AppSetup_DllSafeBase.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_TimerInit.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_TimerInit.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_ObjectPool.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_ObjectPool.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_ApplicationSafe.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_ApplicationSafe.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment