Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save data in executable

I have a portable executable that saves data to a file in the same folder as the executable. Is there any way that I can save data into the executable itself when I close the app?

This maybe weird, but taking the data with me and only have one file for the exe and data would be great.

Would prefer if this was made with C#, but is not a requisite.

like image 911
Artur Carvalho Avatar asked Sep 07 '10 18:09

Artur Carvalho


Video Answer


2 Answers

You cannot modify your own EXE to contain stored data in anything approaching an elegant or compact way. First off, the OS obtains a lock on the EXE file while the application contained within is being run. Second, an EXE comes pre-compiled (into MSIL at least), and modification of the file's source data usually requires recompilation to reset various pointers to code handles, or else a SERIOUS knowledge on a very esoteric level about what you're doing to the file.

The generally-accepted methods are the application config file, a resource file, or some custom file you create/read/modify at runtime, like you're doing now. Two files for an application should not be cause for concern

like image 139
KeithS Avatar answered Oct 28 '22 13:10

KeithS


You can, by reserving space through the means of using a string resource and pad it out. You need to do a bit of detective work to find out exactly where in the offset to the executable you wish to dump the data into, but be careful, the file will be "in use", so proceed cautiously with that.

like image 45
t0mm13b Avatar answered Oct 28 '22 15:10

t0mm13b