简体   繁体   English

如何使用C#以编程方式将内容添加到新的/现有的可执行文件中,并可能使解决方案在Mac上运行?

[英]How can I programmatically add content to new/existing executable using c# and possibly make the solution work on a mac?

I've seen a number of variations on this question and im not sure if this question has been completely duplicated. 我在这个问题上看到了许多变体,不确定该问题是否已完全重复。

I would like to be able to at run-time run an existing executable (SOURCE exe) and have it: 1) take an existing TARGET exe at run time and add content of any size and type to the TARGET exe (pdf, image, word, excel file type, etc) 2) be able to run the modified TARGET exe so that when the TARGET exe is run, it will find the embedded content inside of itself and copy the content to the hard drive and then run the program associated with the content (foe example, run excel on a copied xls file) 我希望能够在运行时运行现有的可执行文件(SOURCE exe),并具有以下功能:1)在运行时获取现有的TARGET exe,并将任意大小和类型的内容添加到TARGET exe(pdf,图像, word,excel文件类型等)2)能够运行修改后的TARGET exe,以便在运行TARGET exe时,它将发现其内部的嵌入内容并将其复制到硬盘驱动器,然后运行关联的程序与内容(例如,在复制的xls文件上运行excel)

I've seen examples where you embed resources at compile time in visual studio but I want to do this at run-time in code (c#, java, whatever works). 我已经看到了一些示例,在这些示例中,您可以在Visual Studio的编译时嵌入资源,但是我想在运行时使用代码(C#,Java,无论什么方法)都可以做到这一点。 Either the host TARGET exe needs to already exist and content should be added to it OR the exe will need to be generated from scratch at run-time and content again added to it. 主机TARGET exe必须已经存在并且应该向其添加内容,或者需要在运行时从头开始生成该exe,然后再次添加内容。

I also would prefer not to use any of the cmd-line tools that visual studio or any other tool would run behind the scenes (if possible) to create an exe to minimize the enduser needing to download any more libraries/sdks than necessary. 我也不想使用Visual Studio或任何其他在后台运行的cmd-line工具(如果可能)来创建exe,以最大程度地减少最终用户需要下载的库/ SDK。

This product is in line with what i want to do http://www.boomeranglistbuilder.com/instructions/usingsoftware.php 该产品符合我的要求http://www.boomeranglistbuilder.com/instructions/usingsoftware.php

(I want to improve upon it) :) (我想对此进行改进):)

Lastly it'd be great if the solution could be cross platform compatible (doubt it though) Could this be done in java? 最后,如果解决方案可以跨平台兼容(这值得怀疑),那会很好吗,可以在Java中完成吗?

I've seen the window library resource method updateresource method mentioned in my searches but I'm not sure if that would completely fit my situation. 我已经在搜索中看到了窗口库资源方法updateresource方法,但不确定是否完全适合我的情况。 can anyone comment? 有人可以评论吗?

I hope my question is clear. 希望我的问题清楚。 Please let me know. 请告诉我。

Any help would be graciously appreciated. 任何帮助将不胜感激。

Thank you, 谢谢,

Carlos 卡洛斯

I think that it's true for most binary file formats (including the executables), appending data to a well-formed file will not affect the usage of the file, the way it is typically interpreted by most programs. 我认为对于大多数二进制文件格式(包括可执行文件)都是如此,将数据追加到格式正确的文件中不会影响文件的使用,大多数程序通常会解释这种方式。 You could, maybe, take advantage of this. 您也许可以利用这一点。

To embed, you'll need to take your (existing) target executable and simply append some binary data to it. 要嵌入,您需要获取(现有的)目标可执行文件,然后简单地向其附加一些二进制数据。 That data will have two parts: 该数据将包含两个部分:

  1. A magic word (to denote the presence of an appended resource) 一个神奇的词(表示存在附加资源)
  2. The resource itself. 资源本身。

So, this: 所以这:

[target executable data]

Becomes this: 变成这个:

[target executable data]
[magic word]
[resource]

To read the resource from the target executable, simply have that executable open itself, search for the magic word and, if it's present, start reading the resource appended after it. 要从目标可执行文件中读取资源,只需将该可执行文件自身打开,搜索魔术词,如果存在,就会开始读取附加在其后的资源。

This is what WinRAR does (or at least did four years ago, when I last checked) to recognize the archives inside of its self-extracting files. 这就是WinRAR的做法(或者至少在四年前,当我最后一次检查时),它可以识别其自解压文件中的档案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 c# 在 Visual Studio 2010 中以编程方式将现有项目添加到当前解决方案 - How to add an existing project to a current solution programmatically in visual studio 2010 using c# 我如何以编程方式确定是否使用C#将新工作项添加到TFS中 - How can I programmatically determine whether new work item added to TFS using C# 如何使用wpf和c#将新属性添加到现有xml节点? - How can I add a new attribute to an existing xml node using wpf and c#? 使用C#,如何以编程方式创建新的Visual Studio 2012解决方案? - Using C#, how do I create a new Visual Studio 2012 Solution programmatically? 在 C# 7 中,如何从现有元素和新元素创建新的 ValueTuple? - In C# 7, How Can I Make a New ValueTuple from an Existing and New Elements? 如何使.NET C#ActiveX插件在Mac Safari上工作? - How can I make .NET C# ActiveX plugin work on Mac Safari? C#:如何向列表中已存在的值添加新值<object> ? - C#: How can I add a new value to a value which is already existing in list<object>? 如何在C#中以编程方式添加新引用? - How to add new reference programmatically in c#? 如何通过C#以编程方式在不使用.mdf或.ldf文件的情况下将.bak文件还原到新服务器? - How can I restore a .bak file to a new server without using the .mdf or .ldf files, programmatically with C#? 如何使用 C# 以编程方式在 MSBuild 解决方案中添加项目依赖项 - How to add project dependencies in a MSBuild solution programmatically with C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM