如何在运行时将文件注入到 EXE 中并在程序运行期间引用该文件?
我希望用户从我的网站下载一个 exe,其中(下载后同步)将 XML 文件注入到该应用程序中。该 XML 文件包含公钥和签名。
如何在下载之前注入文件并在稍后执行期间引用它?
理想情况下,我不会使用 shell 来注入文件,而是使用本机 .NET api。
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?
Ideally I won't be using a shell to inject the file, rather a native .NET api.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 Mono.Cecil 轻松实现这一点,您只需编写如下内容:
注入签名从签名.xml 文件中获取 .xml 资源,并使用用于签署 Application.exe 的 keypair.snk 重新签署程序集。
在运行时,您只需使用:
检索资源。
You could that easily with Mono.Cecil, you'd just have to write something like:
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:
To retrieve the resource.
要注入文件,请将其添加到您的项目中。然后在解决方案资源管理器中右键单击它,转到属性,并将其类型更改为 EmbeddedResource。
要在运行时加载它,请使用
Assembly.GetManifestResourceStream()
。在此处阅读更多信息:http://msdn.microsoft.com/en-us/library /xc4235zt.aspx。To inject the file add it to your project. Then right-click on it in the solution explorer, go to properties, and change its type to EmbeddedResource.
To load it at run-time use
Assembly.GetManifestResourceStream()
. Read more here: http://msdn.microsoft.com/en-us/library/xc4235zt.aspx.从他所写的内容来看,他似乎会在下载之前动态更改文件。
这实际上取决于您使用的服务器端语言,以及您对服务器/托管提供商帐户的控制程度。
假设您有一个 download.aspx 文件,它会生成此 exe 文件并发送以供下载。
您可以做的一件事是将程序集的源代码放在您的服务器上,然后 download.aspx 对其进行汇编并发送以供下载。 (困难的方法)
另一种方法是将编译后的程序集放在服务器上,然后使用例如 cecil ( 以编程方式嵌入资源在 .NET 程序集中 )或其他任何内容来更改它,然后将其发送以供下载。
From what he writes it seems he's gonna dynamically change the file prior to download.
This really depends on the server-side language you use, And how much control you have over your server/hosting provider account.
Say you have a download.aspx file which generates this exe files and sends for download.
One thing you can do is to put the assembly's source on your server then download.aspx assembles it and send it for download. (The difficult way)
Another way is to put the compiled assembly on server then use e.g cecil ( Programmically embed resources in a .NET assembly ) or whatever to change it then send it for download.
这个 Google 结果 似乎很有希望。
This google result seems promising.
将文件添加到您的项目中,通常类似于以下内容:
然后转到项目的属性,转到左侧站点的资源选项卡,然后选择顶部导航栏上的
files
资源。选择添加资源>添加现有文件。浏览到您刚刚放入项目中的文件并选择添加它。该文件现在将显示在项目属性的“资源”选项卡下。将“资源”选项卡中的文件名更改为更有意义。
该文件现在是项目的嵌入式资源,您可以通过以下代码访问它:
Add the file to your project, typically something along the lines of:
Then go to your project's properties, go to the resources tab on the left site and select the
files
resource on the top nav bar. Select to add a resource > add existing file. Browse to the file you just put into your project and select to add it.The file will now show up under your Resources tab of your project's properties. Change the name of your file in the Resources tab to be more meaningful.
The file is now an embedded resource of your project and you can access it by the following in code: