问题描述
我希望用户从我的网站上下载一个exe,在该网站上(下载时同步)将XML文件注入到此应用程序中。该XML文件包含一个公共密钥和一个签名。
I'd like a user to download an exe from my website, where (synchronously upon download) an XML file is injected into this application. This XML file contains a public key, and a signature.
如何在下载之前注入文件,并在执行期间稍后引用?
How do I inject the file prior to downloading and reference it later during execution?
理想情况下,我会赢
推荐答案
您可以使用,您只需要编写以下内容:
You could that easily with Mono.Cecil, you'd just have to write something like:
var module = ModuleDefinition.ReadModule ("Application.exe");
module.Resources.Add (
new EmbeddedResource (
"signature.xml",
ManifestResourceAttributes.Private,
File.ReadAllBytes ("signature.xml")));
module.Write ("Application.exe",
new WriterParameters {
StrongNameKeyPair = new StrongNameKeyPair ("keypair.snk")
});
要从signature.xml文件中注入signature.xml资源,并使用
To inject the signature.xml resource from the signature.xml file, and sign back your assembly with your keypair.snk that you used to sign Application.exe.
在运行时,您只需要使用:
And at runtime, you'd just have to use:
var stream = Assembly.GetExecutingAssembly ()
.GetManifestResourceStream ("signature.xml");
检索资源。
这篇关于如何在运行时将文件注入EXE并在程序运行期间引用该文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!