开发者

Concatenate data to .net application

I want to make a program that concatenates an exe and data into one file.

Basicly:

Program A (Program B, Data) => Program C

Program A will just merge to Streams into one. Even the though of using copy /b B.exe + file.data also comes to mind. So I'm not too concerned with how cleanly the files are merged.

The idea is that Program B knows its going to be used in this way and will look for the data. The question that come to mind is how can Program C know where it's开发者_如何学运维 exe code ends and the data begins? I know that dos exes used to have header data defining their size but I don't know what exists in .net for this kind of inspection.


While you could figure out the .exe size from the PE header, there's a simpler way: Write the length of the appended section as the last word along with a magic number. To read it, Seek(-WordSizePlusMagicNumberSize, SeekOrigin.End), read them and verify they are valid.


If your goal is to embed data in an executable, could you include the data file as a resource in visual studio instead?


Add the data as an embedded resource.

In visual studio add the file you wish to add then change the build action in the file properties from None (the default for non code types) to Embedded Resource. Then compile

The next step rather depends on what you wish to do with it? You can access it from within your app via the ResourceManager or in a similar way you can write another app to pull this resource data from it.

You need some context in your question

OR if you are really talking about two streams the you may be talking about ADS, Alternate Data Streams, which, if memory serves, is a pain but there is code out there that gives an easy(ish) API

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜