Hey all, Some of you may recently have seen me asking a question about protecting images on your computer by changing their format. I have found an engenious solution to the problem and though that some of you might appreciate learning from my insights
My dilema was that I was making a large game, and in order to stop Panther crashing while it ran the game (it currently needs over 400 images) I decided to store a lot of information and images outside of the project in folders that came with the game.
One problem: all the pictures and graphics and levels and such were now easily viewable, just by browsing through the folders in "thumbnail view".
This simply wouldn't do, so I set out to find a way that would let Panther continue to store the images in folders and import them when necessary without any other people or programs being able to view them. This is what I found.
Using the file blocks, I noticed that I could read the contents of an image file as text - and copy it. So now I have my image sucessfully converted into a load of gobbledee gook. All I need to do now is write it to a new format. I normally use unusual file formats, but for my test I just used .txt.
so I have now copied the contents of an image file and turned it into a text file which won't open as an image! Great! Only problem now is that Panther couldn't import a text file as an image.
using a custom block with the simple code:
import image from file $String$
self importMedia: t1
I am able to give the filepath to an image and create a new costume out of it. This works fine for gifs, jpg's and png's but sadly not if any of those have been turned into a new format.
to solve this, I used a single gif image called t1 which portrays a mysterious question mark. This is the go-between I can use. I simply read the contents of the t1.gif and save it as a varaible (so that the picture is saved when I edit the file), then I read the contents of the txt file I want to import as an image, and, clearing the contents of the t1.gif file, write that file in it's place. The image is now there, called t1.gif and ready to import with the above block. As soon as it's imported, the file can be cleared and the old code for the ? image can be replaced.
This happens in a matter of a second or two, and no trace of the image file as an image is left in the folder!
Hope this helps anyone trying to keep their game a secret from prying eyes!
Offline
That's a great idea and works well, but say, what's to stop me from changing the extension of the file to view the image. Perhaps to give it amazing protection possibly pack multiple images into a file and encrypt in a way. Though even without that very nice job
Last edited by nerevar (2010-12-27 12:00:02)
Offline
Yes, It's application might be extended from just games, as any image file could be encrypted like this. Putting two images into one file would also stop someone trying to open the file in a photo viewing program like microsoft picture and fax viewer because until the two were seperated, the contents of the file would be invalid as an image
Offline
this is SOOOOOOOOOOOOOO cool.

Offline
Can I suggest you make this into a custom block, and make a block [delete file %s] so you could delete t1.gif after the block has run.
Offline
That's an interesting idea, but I think a project would probably suffice. I'm currently working on a project (Panther) which I will link to when its done here. It's a browser that lets you search your computer for gif, jpg, jpeg and png files and allows you to encrypt them into the same folder. (and decrypt them too.
Offline
hmmm...
what if....
what if unstead of wasting precious time reading it to t1.gif you simply renamed it, imported it and re-renamed it again?
Offline
sparks wrote:
Because I don't know how to change the format of a file with a block.
But you make a good point. It would make it a lot faster.
Right. Coming to think of it, neither do I.
Maybe nXIII or similar could give some more insight on the matter...
Offline
I could write a block that sets the contents of a file to a variable, deletes the original file, writes the contents to a new file, imports the image, deletes that file and creates the old one again but to be honest that's pointless and probably takes just as long to do.
What's needed is some sort of command
Offline
sparks wrote:
I could write a block that sets the contents of a file to a variable, deletes the original file, writes the contents to a new file, imports the image, deletes that file and creates the old one again but to be honest that's pointless and probably takes just as long to do.
What's needed is some sort of command![]()
There's definitely a squeak command for this, try this method from the FileDirectory class: rename: oldFileName toBe: newFileName
Offline
sparks wrote:
I will give that a go. It's certainly simpler than the block I'm putting together to execute the procedure outlined abouve :S
I should hope so
...and faster, don't forget
Offline
Much faster. I'm still trying to finish mine as i've adapted the above technique and can't just change the format anymore. I've taken the first line out of the file to stop it being viewed in an image software, the line is then added again before it's converted.
Why is this snippet:
pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'. self clearFile: pokefiles, 't1.png' pic_ pngtitle, ' ', self readFile: t1.
returning the syntax error:
pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'. self clearFile: pokefiles, 't1.png' picNothing more expected ->_ pngtitle, ' ', self readFile: t1.
? It's maddening!
Offline
sparks wrote:
Much faster. I'm still trying to finish mine as i've adapted the above technique and can't just change the format anymore. I've taken the first line out of the file to stop it being viewed in an image software, the line is then added again before it's converted.
Why is this snippet:Code:
pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'. self clearFile: pokefiles, 't1.png' pic_ pngtitle, ' ', self readFile: t1.returning the syntax error:
Code:
pngtitle_ self readLine: 1 ofFile: pokefiles, 't1.png'. self clearFile: pokefiles, 't1.png' picNothing more expected ->_ pngtitle, ' ', self readFile: t1.? It's maddening!
You forgot the period at the end of line two.
Offline
Ok. I've hit a problem.
First, I took a png image and copied all but the first line to a new file with a different format (igif).
Next I used a piece of smalltalk code to nab the contents of an image file and then paste the contents of the igif file into it, adding the first line on again.
This has gone horribly wrong! the code for both images looks exactly the same but the one that was an igif is now not opening!
replace image with png igif file: $String$
|path store t2 pngtitle| path_ self reportVar: 'path'. path_ path, '\VM\'. store_ self readFile: path, 't1.png'. pngtitle_ self readLine: 1 ofFile: path, 't1.png'. t2_ self readFile: t1. t2_ pngtitle, ' ', t2. self clearFile: path, 't1.png'. self writeText: t2 toFile: path, 't1.png'.
Last edited by sparks (2010-12-31 12:46:48)
Offline
I would guess maybe you are reading the first line as ASCII, therefore saving it incorrectly. How about just try to keep it simple?
And you need the .
The other error is not related
Offline
Well The reason it's slightly complicated is that I'm trying to make it harder for people to just view the images on my game
I might try it with blocks first then and see if that works...
Last edited by sparks (2010-12-31 13:05:47)
Offline
sparks wrote:
Well The reason it's slightly complicated is that I'm trying to make it harder for people to just view the images on my game
![]()
I might try it with blocks first then and see if that works...
Seems like a good idea to me
Offline
sparks wrote:
Yeah, it's not working with block either. smalltalk refuses to keep the contents intact while working with it, replacing symbols with other ones.
Then you should try leaving the file intact
Offline