Commit dda7d71e by liulongfei

DLL 安全校验

parent 1a3d9a7a
using DevExpress.Xpf.Docking;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
......@@ -22,11 +24,47 @@ namespace VIZ.Package.Module
/// </summary>
public partial class MainView : UserControl
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(MainView));
public MainView()
{
InitializeComponent();
this.CheckDll();
WPFHelper.BindingViewModel(this, new MainViewModel());
}
/// <summary>
/// 监测DLL
/// </summary>
private void CheckDll()
{
// 入口
ApplicationDllCheckAttribute entry_attribute = Assembly.GetEntryAssembly().GetCustomAttribute<ApplicationDllCheckAttribute>();
if (entry_attribute == null || string.IsNullOrWhiteSpace(entry_attribute.Key))
{
log.Error("dll check error.");
throw new Exception("dll check error.");
}
// 模块
ApplicationDllCheckAttribute module_attribute = this.GetType().Assembly.GetCustomAttribute<ApplicationDllCheckAttribute>();
if (module_attribute == null || string.IsNullOrWhiteSpace(module_attribute.Key))
{
log.Error("dll check error.");
throw new Exception("dll check error.");
}
// 不匹配
if (!string.Equals(entry_attribute.Key, module_attribute.Key))
{
log.Error("dll check error.");
throw new Exception("dll check error.");
}
}
}
}
......@@ -3,6 +3,7 @@ using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using VIZ.Framework.Core;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
......@@ -31,13 +32,13 @@ using System.Windows;
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly:ThemeInfo(
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
......@@ -51,5 +52,7 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: ApplicationDllCheck(Key = "V1.2.0.04041049_beta")]
\ No newline at end of file
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Module;
using VIZ.Package.Domain;
using VIZ.Package.Storage;
namespace VIZ.Package.Module
{
/// <summary>
/// 应用程序启动 -- 初始化CSV
/// </summary>
public class AppSetup_DllSafe : AppSetup_DllSafeBase
{
}
}
\ No newline at end of file
......@@ -407,6 +407,7 @@
</Compile>
<Compile Include="Setting\VizConfig\VizConfigSettingPluginLifeCycle.cs" />
<Compile Include="Setting\VizConfig\ViewModel\VizConfigSettingViewModel.cs" />
<Compile Include="Setup\AppSetup_DllSafe.cs" />
<Compile Include="Setup\AppSetup_InitRecordLog.cs" />
<Compile Include="Setup\AppSetup_InitCSV.cs" />
<Compile Include="Setup\AppSetup_InitLiteDB_Config.cs" />
......
......@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Plugin;
......@@ -33,6 +34,10 @@ namespace VIZ.Package.Service
{
List<PluginInfo> list = new List<PluginInfo>();
ApplicationDllCheckAttribute entry_attribute = Assembly.GetEntryAssembly().GetCustomAttribute<ApplicationDllCheckAttribute>();
if (entry_attribute == null || string.IsNullOrWhiteSpace(entry_attribute.Key))
return list;
string[] files = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory);
Type pluginLifeCycleType = typeof(IPluginLifeCycle);
......@@ -63,6 +68,13 @@ namespace VIZ.Package.Service
continue;
}
ApplicationDllCheckAttribute attribute = type.Assembly.GetCustomAttribute<ApplicationDllCheckAttribute>();
if (attribute == null)
continue;
if (!string.Equals(entry_attribute.Key, attribute.Key))
continue;
PluginInfo info = lifeCycle.Register();
list.Add(info);
}
......
......@@ -30,6 +30,8 @@ namespace VIZ.Package
Theme.RegisterTheme(theme);
ApplicationThemeHelper.ApplicationThemeName = theme.Name;
// DLL安全
AppSetup.AppendSetup(new AppSetup_DllSafe());
// 初始化LiteDB
AppSetup.AppendSetup(new AppSetup_InitLiteDB());
// 初始化CSV
......
......@@ -3,6 +3,8 @@ using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using VIZ.Framework.Core;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
......@@ -51,5 +53,7 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: ApplicationDllCheck(Key = "V1.2.0.04041049_beta")]
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