Convert Txt To Binary Question

Started by
8 comments, last by Aardvajk 17 years, 9 months ago
I'm trying to prevent tampering of my config file in my Windows app. I was going to write a little app to convert my config from text to binary. Yes, I know this will not stop hard core hackers. Is there an easy way to do this? Or do I have to create a lookup table and do the conversion myself? Thanks.
Advertisement
They're already stored in binary. One of the most common lookup tables used is ASCII.

For obfuscation, simple techniques range from adding an offset to the character values. For example, adding 3 would change A into D, D into G, etc. Alternatively, you could store a randomly generated table which maps stored values to and from the ASCII table values they represent.

It's quite likely to be quite trivial to circumvent, however, "hard core" hacker or not.
Another method to prevent tampering:
Store a hashcode/checksum of whole the file within the file (warning: not easy).
If you just want a binary representation of numbers and string data that was previously stored as text, may I introduce you to a small utility called va to be found at http://myweb.tiscali.co.uk/easilyconfused.

Basically, instead of having a text file containing, say

10
20
"hello"
30

and parsing it, you create a text file like

10d // d for double i.e. 32 bit int
20d
"hello" 0b // b for byte - null terminator
30d
#save "x.dat"

then run va on the text file. It spits out a binary representation that you can read into your program with ios binary read functions. As you say, it provides almost no protection against hackers but will prevent tampering by casual users.

(Aside note - this is not what va was created for BTW. It was created for constructing binary level files when a project is too young for a level editor, or for generating byte code for virtual machines when too early for a proper compiler and does have some slightly more advanced features as well [smile]).
What's the point of preventing tampering with a config file? Maybe some people like to manually configure your app some time. Would that be bad? Why?

Even if nobody would want to manually configure your app, doing this just adding needless complexity to the program.

Is the purpose to protect some kind of high-score list in a game? In that case, quite frankly, who cares if a user edits his high-score or not?
I'd take a look at base64 encoding its a very lightweight encryption method this oftern used for this kind of thing (may be a bit of overkill mind you)...

http://synesis.com.au/software/b64.html

Quote:Original post by griffin2000
I'd take a look at base64 encoding its a very lightweight encryption method this oftern used for this kind of thing (may be a bit of overkill mind you)...

http://synesis.com.au/software/b64.html


It's not really "encryption", it's just an encoding method to transfer binary data as ascii. Nobody is using it to try hiding stuff.
Quote:
It's not really "encryption", it's just an encoding method to transfer binary data as ascii. Nobody is using it to try hiding stuff.


Its what Thunderbird uses to encrypt email passwords :-) But strickly speak your right its not really encrypting anything, but its hard enough to do what the OP needed (e.g. you couldn't just open highscores.dat in a hex editor and change your high score).

My config file holds params which affect my app's performance, AI execution, and other algorithm behaviors. I just want something my app can read, but I don't want a person to open it up in NotePad and modify it.
I just wouldn't worry about it to be honest. Unless you are going to go to the trouble of implementing some kind of extremely secure encryption system with checksums and stuff, it is always going to be POSSIBLE for people to tinker with your files.

If you give your file a non-text-file extension that will stop casual users from double-clicking it open.

At the end of the day, I could open your program's exe file with notepad if I really wanted, edit it, save the changes and then the program wouldn't run at all [smile].

What I am trying to say is that if users are going to start tinkering around with files in your program's install directory, on their own heads be it. If you are concerned users will change settings in order to "cheat", just let them get on with it. Most commercial games let you do this anyway.

This topic is closed to new replies.

Advertisement