一、场景:spa
发到客户那的程序中使用的一个C++的库须要被替换,而该库在使用了前使用了md5进行检验防止其它假装的库将其替换,于是替换时要算目标库的code
md5,并把使用该库的另外一个库也换掉。blog
二、涉及技术:md5
作一个离线补丁包去升级程序,并将库文件集成到其中,程序运行时再将其释放出来。资源
三、解决方法:get
将目标库当成资源添加到工程中,并在须要时调用它写入文件string
1 private bool GetFileFromAssembly(String fileName, String targetFilePath) 2 { 3 byte[] bs = null; 4 String fileNameWithoutExtension = fileName.Substring(0, fileName.Length - 4); 5 MemoryStream ms = null; 6 FileStream fs = null; 7 8 try 9 { 10 bs = (byte[])Properties.Resources.ResourceManager.GetObject(fileNameWithoutExtension); 11 ms = new MemoryStream(bs); 12 fs = new FileStream(targetFilePath, FileMode.Create); 13 ms.WriteTo(fs); 14 } 15 catch (System.Exception ex) 16 { 17 return false; 18 } 19 finally 20 { 21 ms.Close(); 22 fs.Close(); 23 } 24 return true; 25 }
四、相关程序:it