当前位置: 首页 > news >正文

crm系统软件排名/重庆seo教程

crm系统软件排名,重庆seo教程,登录入口网址,iview做的网站在读取RedisSessionStateProvider配置 提到用mono ceil 来修改程序集以及它的签名,里面GetPublicKey 和GetPubliKeyToken 方法里面那个字符串的获取 以及后来的签名 我们都应该 用code来实现,还有应用该dll文件的签名也一同需要修改。 所以我这里实现了一…

在读取RedisSessionStateProvider配置 提到用mono ceil 来修改程序集以及它的签名,里面GetPublicKey 和GetPubliKeyToken 方法里面那个字符串的获取 以及后来的签名 我们都应该 用code来实现,还有应用该dll文件的签名也一同需要修改。

所以我这里实现了一个简单的helper方法 如下:

namespace ConsoleSession
{using Mono.Cecil;using System;using System.IO;using System.Linq;using System.Reflection;using System.Runtime.InteropServices;public class ChangeAssemblyInfo{public string FileName { set; get; }public string FullName { set; get; }}public class keyHelper{static byte[] GetNewKey(string keyFileName){using (FileStream keyPairStream = File.OpenRead(keyFileName)){return new StrongNameKeyPair(keyPairStream).PublicKey;}}public static void ReSign(string keyFileName, string assemblyFileName){AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(assemblyFileName);asm.Name.PublicKey = GetNewKey(keyFileName);asm.Write(assemblyFileName);//用KEY文件建立密钥容器                     byte[] pbKeyBlob = File.ReadAllBytes(keyFileName);string wszKeyContainer = Guid.NewGuid().ToString();StrongNameKeyInstall(wszKeyContainer, pbKeyBlob, pbKeyBlob.Length);//使用新建的密钥容器对程序集经行签名          StrongNameSignatureGeneration(assemblyFileName, wszKeyContainer, IntPtr.Zero, 0, 0, 0);//删除新建的密钥容器          
            StrongNameKeyDelete(wszKeyContainer);}private static byte[] tryGetPublicKeyToken(string keyFileName){try{byte[] newPublicKey;using (FileStream keyPairStream = File.OpenRead(keyFileName)){newPublicKey = new StrongNameKeyPair(keyPairStream).PublicKey;}int pcbStrongNameToken;IntPtr ppbStrongNameToken;StrongNameTokenFromPublicKey(newPublicKey, newPublicKey.Length, out ppbStrongNameToken,out pcbStrongNameToken);var token = new byte[pcbStrongNameToken];Marshal.Copy(ppbStrongNameToken, token, 0, pcbStrongNameToken);StrongNameFreeBuffer(ppbStrongNameToken);return token;}catch (Exception){return null;}}public static void ReLink(string keyFileName, ChangeAssemblyInfo[] assemblyInfoList){byte[] publicKeyToken = tryGetPublicKeyToken(keyFileName);if (publicKeyToken == null){return;}//获得每个程序集的名称foreach (ChangeAssemblyInfo assemblyInfo in assemblyInfoList){assemblyInfo.FullName = AssemblyDefinition.ReadAssembly(assemblyInfo.FileName).Name.FullName;}//检查是否被引用,是的话,就替换PublicKeyTokenforeach (ChangeAssemblyInfo assemblyInfo in assemblyInfoList){AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyInfo.FileName);foreach (ModuleDefinition module in assembly.Modules)foreach (AssemblyNameReference reference in module.AssemblyReferences)if (assemblyInfoList.Any(a => a.FullName == reference.FullName)){reference.PublicKeyToken = publicKeyToken;assembly.Write(assemblyInfo.FileName);}}}#region StrongName库作为一项资源包含在 MsCorEE.dll 中,其一系列API包含有[DllImport("mscoree.dll", EntryPoint = "StrongNameKeyDelete", CharSet = CharSet.Auto)]static extern bool StrongNameKeyDelete(string wszKeyContainer);[DllImport("mscoree.dll", EntryPoint = "StrongNameKeyInstall", CharSet = CharSet.Auto)]static extern bool StrongNameKeyInstall([MarshalAs(UnmanagedType.LPWStr)] string wszKeyContainer,[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2,SizeConst = 0)] byte[] pbKeyBlob, int arg0);[DllImport("mscoree.dll", EntryPoint = "StrongNameSignatureGeneration", CharSet = CharSet.Auto)]static extern bool StrongNameSignatureGeneration(string wszFilePath, string wszKeyContainer,IntPtr pbKeyBlob, int cbKeyBlob, int ppbSignatureBlob,int pcbSignatureBlob);[DllImport("mscoree.dll", EntryPoint = "StrongNameErrorInfo", CharSet = CharSet.Auto)]static extern uint StrongNameErrorInfo();[DllImport("mscoree.dll", EntryPoint = "StrongNameTokenFromPublicKey", CharSet = CharSet.Auto)]static extern bool StrongNameTokenFromPublicKey(byte[] pbPublicKeyBlob, int cbPublicKeyBlob,out IntPtr ppbStrongNameToken, out int pcbStrongNameToken);[DllImport("mscoree.dll", EntryPoint = "StrongNameFreeBuffer", CharSet = CharSet.Auto)]static extern void StrongNameFreeBuffer(IntPtr pbMemory);#endregion}
}

调用code 如下:

    using System;using System.IO;using System.Linq;using Mono.Cecil;class Program{static void Main(string[] args){#region 修改程序集string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Microsoft.Web.RedisSessionStateProvider3.dll");AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(filePath);TypeDefinition[] types = asm.MainModule.Types.ToArray();//修改ProviderConfiguration为publicTypeDefinition typeConfiguration = types.FirstOrDefault(x => x.Name == "ProviderConfiguration");typeConfiguration.IsPublic = true;//修改ProviderConfiguration的字段为publicTypeDefinition typeRedisProvide = types.FirstOrDefault(x => x.Name == "RedisSessionStateProvider");FieldDefinition filedConfiguration = typeRedisProvide.Fields.ToArray().FirstOrDefault(x => x.Name == "configuration");filedConfiguration.IsPublic = true;//保存dll文件filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Microsoft.Web.RedisSessionStateProvider.dll");asm.Write(filePath);#endregionstring keyfileName = @"D:\mykey.snk";//修改单个dll文件的签名
            keyHelper.ReSign(keyfileName,filePath);//修改引用该dll文件的签名keyHelper.ReLink(keyfileName, new ChangeAssemblyInfo[] {new ChangeAssemblyInfo { FileName = filePath },new ChangeAssemblyInfo { FileName=Path.Combine(@"C:\Users\UNIT12\Documents\visual studio 2015\Projects\SessionWebApp\SessionWebApp\bin","SessionWebApp.dll")}});//Console.ReadLine();
        }}

参考资料:

利用Mono-cecil实现.NET程序的重新签名,重新链接相关库的引用

 

转载于:https://www.cnblogs.com/majiang/p/6149007.html

http://www.lbrq.cn/news/100117.html

相关文章:

  • 淘宝客做网站教程/9个广州seo推广神技
  • 网站建设 自动生成/百度一下百度主页
  • 一个专门做试题的网站/怎么网上宣传自己的产品
  • 网站建设公司主营业务/新的网站怎么推广
  • 网站开发常用的开发工具/公司网页制作
  • 目前国内有哪些网站做家具回收/代做百度收录排名
  • 软件网站开发合同/个人seo外包
  • 品牌网吴为简介/霸榜seo
  • 申通物流的网站建设/关键词优化公司
  • 网站建设需求分析要做的事/在线优化工具
  • 网站建设绵阳辉煌电商/949公社招聘信息
  • 梧州做网站建设/苏州疫情最新消息
  • wordpress 全站 下载/网络营销方式对比分析
  • 微企免费网站建设/seo做关键词怎么收费的
  • ps做网站 字体多大/网站的推广方法
  • 家乡网站建设策划书模板/口碑营销策略
  • 视频剪辑找什么公司/免费seo网站诊断
  • wordpress多站用户/百度网盘客服电话
  • wordpress标签无法显示/seo营销推广多少钱
  • 音乐网站可以用什么语言做/免费b站推广网站2022
  • 专业做网站推广/站长工具使用
  • 产品推广方案范本3篇/太原seo顾问
  • 广告推广的好处/惠州百度关键词优化
  • 网站建设佰首选金手指六/百度搜索词热度查询
  • 个人专属logo设计/信息流优化师简历模板
  • wordpress keywords 用逗号 区分关键字/重庆seo全面优化
  • 四川省人民政府网站集约化建设/公关公司一般收费标准
  • 小型公司网站建设/广州番禺发布网
  • 有没有专门做衣服搭配的网站/注册百度推广账号
  • 网络销售怎么做才能有业务/蜘蛛seo超级外链工具
  • .java->.class->java 虚拟机中运行
  • Effective C++ 条款54:熟悉标准库
  • selenium一些进阶方法如何使用
  • 自然语言处理——04 注意力机制
  • LLaVA-3D,Video-3D LLM,VG-LLM,SPAR论文解读
  • SQL-leetcode—3451. 查找无效的 IP 地址