How to: Save a string to .exe and not a different file?

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

How to: Save a string to .exe and not a different file?

Post by coolw »

How do I save a string to an .EXE without making a new file, because I wish to keep the string from being read elsewhere.

Example

Code: Select all

Secret$=Input("Password: ")
   Save Secret as Password$
Not exactly, it's just a small example. I will be using it to save a string of integers for an ecryption process. Any help is appreciated! Thanks.
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
User avatar
Jare
Devoted Member
Posts: 877
Joined: Mon Aug 27, 2007 10:18 pm
Location: Pori
Contact:

Re: How to: Save a string to .exe and not a different file?

Post by Jare »

I think you just can't. You should edit the exe (OpenToEdit) but that is impossible while the exe is in use.

You may have to find another solution. One (dirty) way is to save the external file into a location that nobody can guess (for example "c:\Windows\ImportantApplicationFile.sth" and no one who sees that file knows which application it is related to) but you still should avoid doing that.

Better way would be to save the file in the same directory with the exe and encrypt the file correctly. If the file contains a password to some data which is located in somewhere, just do not save the password into the external file. Save instead the result of Crc32(password$) and when user is trying to log in to your application, check the password by doing something like this: If crc32_from_file$ = Crc32(password_written_by_user$ Then login_accepted = True.

So you just need to encrypt the secret data somehow. After that you don't have any need to write the data to the exe. Ask more if you wish. ;)
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Re: How to: Save a string to .exe and not a different file?

Post by coolw »

Well, what I was going to do is make a string and then have a random code generator generate a 9 digit code and then save it in the .exe, so when that is saved, I can make a new temporary file with that 9 digit code and then use it to decrypt and encrypt the data file and then delete the temporary file so there is no trace, and then nobody could make a program that decrypts it if they happen to find the code. I am just trying to make my program secure, because that is what people like nowadays ;)

Thanks, I like the idea of a file somewhere in the windows folder! I might use that, I might not, but any help on the above would be nice. :D
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
User avatar
Jare
Devoted Member
Posts: 877
Joined: Mon Aug 27, 2007 10:18 pm
Location: Pori
Contact:

Re: How to: Save a string to .exe and not a different file?

Post by Jare »

coolw wrote:Thanks, I like the idea of a file somewhere in the windows folder! I might use that, I might not, but any help on the above would be nice. :D
There is still some problems with that. One is that if a user moves the program to another computer, he/she doesn't get his data moved too.
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Re: How to: Save a string to .exe and not a different file?

Post by coolw »

Well, I could make it so its in a dir right near the Program, but how could I make it so people can't open it, and if they happen to find out how, it would be encrypted?
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
User avatar
Jare
Devoted Member
Posts: 877
Joined: Mon Aug 27, 2007 10:18 pm
Location: Pori
Contact:

Re: How to: Save a string to .exe and not a different file?

Post by Jare »

Encrypt the file's content before saving it.

Here are some functions to Encrypt and Decrypt strings (simple but hopefully not too simple): http://www.coolbasic.com/oldforums/inde ... wtopic=427. (The functions' names are "EnCrypt" and "DeCrypt" so you may need to rename them like "EnCrypt2" and "DeCrypt2" because if I remember right, CoolBasic already have inbuild functions named Encrypt and Decrypt, but they work only on files and memory blocks).

You can try to use the inbuild encrypting and decrypting functions too (directly to a file) but I have no experience of them and I've always just crypted a string before writing it to a file. Maybe you should try both and see which one suits better for you. ;)
Post Reply