6

我希望用户从我的网站下载一个 exe,其中(在下载时同步)一个 XML 文件被注入到这个应用程序中。此 XML 文件包含一个公钥和一个签名。

如何在下载之前注入文件并在稍后执行期间引用它?

理想情况下,我不会使用 shell 来注入文件,而是使用本机 .NET api。

4

5 回答 5

8

您可以使用Mono.Cecil轻松实现,您只需要编写如下内容:

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 资源,并使用用于签署 Application.exe 的 keypair.snk 重新签署程序集。

在运行时,您只需要使用:

var stream = Assembly.GetExecutingAssembly ()
    .GetManifestResourceStream ("signature.xml");

检索资源。

于 2011-03-17T15:00:46.583 回答
1

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.

于 2011-03-17T15:00:52.550 回答
1

要注入文件,请将其添加到您的项目中。然后在解决方案资源管理器中右键单击它,转到属性,并将其类型更改为 EmbeddedResource。

要在运行时加载它,请使用Assembly.GetManifestResourceStream(). 在此处阅读更多信息:http: //msdn.microsoft.com/en-us/library/xc4235zt.aspx

于 2011-03-17T14:53:33.857 回答
0

Add the file to your project, typically something along the lines of:

+solution
  +project
    +Resources
      +SomeDirectory
        -SomeFile

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:

var MyFile = Properties.Resources.MyFile
于 2011-03-17T15:02:55.453 回答
0

这个 谷歌结果似乎很有希望。

于 2011-03-17T14:55:15.697 回答