Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mulligan

Storing data within an exe at runtime.

This topic is 5222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I read somewhere that in .NET, its possible to actually store data within the program file itself, is that true? To better explain myself, an example. Say there is a simple program that allows the user to select a bitmap file on the harddrive. Once selected, the bitmap''s data is copied INTO the exe. When you close the program, the size of the exe is now bigger because it internally contains the bitmap image. The program could have an extract feature to unload the image from the exe. Anything like this possible?

Share this post


Link to post
Share on other sites
Advertisement
What you''re referring too is known as metadata, but it''s usually used to store information about the assembly and the types it contains rather than your own custom data. It might be possible, but I''m sure only at compile time. I''m pretty sure you can''t modify an assembly file as it''s being run.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You could store the bitmap as a resource. Editting an EXE or DLL''s resources after it''s been compiled is messy but possible.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
AFAIK there is no way to do this at run-time into the active executable (if that''s what you mean).

There are ways that you could do it though, for example you could have a little helper app, that when started would wait for the process that launched it to shut down, then opens the file & adds the bitmap into the resources (note, you''ll need a good grip of the PE executable format to do this), once thats done then re-launch the original process & close down the helper app. You''d actually need to make sure all instances of the program to be modified were closed down otherwise you won''t be able to open the file for writing.

Other than that I''m out of ideas!

Perhaps you can explain what you''re trying to do slightly better, I mean why can''t the bitmap just exist as an external file ? is this meant to be for (say) a user configurable background ? or are you trying to come up with some kind of electronic-card for people to send (in which case its a rather easier problem) -- as in people bind an image into an exe with some kind of message & then send it to a friend (then I can see why you''d want it as a single file...).



PS: I can''t help thinking that when ever you start a new topic there ought to be a reminder to people to state what they are trying to do or achieve --- I just hate the way people state their problem in the most narrow sense rather than saying I''m trying achieve this effect/result overall, this is my specific problem [, this is how I''m trying to do it {optional}].

Share this post


Link to post
Share on other sites
You cannot modify an exe file whilst its running because windows will have it open for reading. So you wont be able to get write permission.

However, once the program is closed, you can use another program to append whatever data you like to the end. You dont need to know anything about the exe file format.

E.g

I have a self extracting archive system where by a packer program makes a copy of the installer exe, and appends a data ''entry point'' signature, a content table and then then the data files, and it works fine!

Share this post


Link to post
Share on other sites
quote:
Original post by Empirical
You cannot modify an exe file whilst its running because windows will have it open for reading. So you wont be able to get write permission.



IIRC windows will load the whole thing into memory at once and close it. Plus you can probably mess with shared i/o and get access.

A big problem is that most virus scanners will yell if a program tries to modify its own executable. Im sure there are ways to get around this, but it probably messy.

Share this post


Link to post
Share on other sites
quote:

IIRC windows will load the whole thing into memory at once and close it. Plus you can probably mess with shared i/o and get access.


I think windows memory maps its executable files, hence the problem of not being able to delete an exe while it''s running.

Share this post


Link to post
Share on other sites
Try this:

Make a small program that loads the binary image of a program into memory, then appends your data at the end, then saves.

Try running the program. If it works, I guess there is no problem the loader and the PE section.

Then you can make an app and use VirtualProtect to make your code section writeable, or make use linker flags. You will need to make some part of you code section writeable becuase you will need to patch your code to access your new data. If you need more memory then the last 4k section of your program, use VirtualAlloc to get more.

Perhaps you could save the patched app to a sub-directory?

This is pretty easy to do in assembly. C++, maybe impossible.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!