Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Load an encrypted file in memory and use it

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 24th Jan 2022 10:01
Hi

Do you if it's possible to load/open an encrypted file in memory and use it directly, (without creating a decrypted file,) ?

What I would like :
- I have encrypted file (txt, image)
- I would like to decrypt it in memory
- and use the result directly from the memblock

For the moment, what I do :
- open a file and decrypt it in memblock
- and use CreateFileFromMemblock() to create the decrypted file
- so after, I open the file (ex :with loadimage() if it's an image or opentoread() if it's a txt).
- And I delete the file decrypted.

It's not good for me.
I would like to use the result, directly from memory (I can do that in purebasic).

But I don't know how to do that, and if it's possible.

Do you have an idea how to do that ?

Thank you a lot.
AGK2 tier1 - http://www.dracaena-studio.com
SFSW
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 24th Jan 2022 15:53
About the only practical way to do things that way is to first convert the files you want to protect over to memblock format (ie 'LoadImage()' with 'CreateMemblockFromImage()'). Then encrypt the media in the memblock and save out the encrypted memblock file (compress as may be desired). Once that's done, then you can just reload the file back into a memblock directly ('CreateMemblockFromFile()'), decrypt it, then transfer it over to its intended media format ('CreateImageFromMemblock()').
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 26th Jan 2022 09:35
HI

Thank you for your answers

SFSW : yes, I have tried to use memblock, but my images size are multiplied by 2 or 3, so it isn't interesting for me

Blinkok : yes, I have see this post, and I will tried to see if I will use this technic for text

For the moment, with my technic, I can load image with CreateImageFromPNGmemory() so it's cool for png.
But, It miss a CreateImageFromJPGmemory() to load my jpg image in memory

Thanks again
AGK2 tier1 - http://www.dracaena-studio.com
SFSW
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 26th Jan 2022 19:06
@Blendman

Not sure what you mean by 'interesting', but size and format won't matter with the technique I described involving saving out the memblock first. So it doesn't matter if you're working with PNG or JPG, the system is still the same. It's kind of like precompiling your media to go directly from memblock files to memory using AGK2/S compatible formats. The steps you'll need to do are (it's handy to have a separate app to handle this part whenever you need to rebuild your media into memblock files):

- Load the media file into the required type - LoadImage(1,"MyImage.jpg")
- Convert the media type to a memblock - CreateMemblockFromImage(1,1)
- Encrypt the memblock using your preferred method
- Save the memblock out to a file - CreateFileFromMemblock("MyNewImage.mem",1)
- Clear the memblock after use - DeleteMemblock(1)
- Compress the output file as may be desired to minimize disk overhead - CreateZip(1,"MyNewImage.zip") > AddZipEntry(1,"MyNewImage.mem") > CloseZip(1)

The zipped and encrypted memblock files are now all you need to bundle with your game, just keep the originals elsewhere for safe keeping and future editing. Then to load the media files:

- Unzip the memblock file as needed - ExtractZip("MyNewImage.zip","")
- Load the extracted memblock file from disk - CreateMemblockFromFile(1,"MyNewImage.mem")
- Decrypt the memblock using your preferred method
- Place the memblock into its required media type - CreateImageFromMemblock(1,1)
- Clear the memblock after use - DeleteMemblock(1)

Depending on the overhead of your encryption process, you'll likely find this is a pretty fast way to load protected media directly into memory.
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Jan 2022 01:15

If your trying to protect stuff like pre rendered spite animations (assuming), then storing them as span lists with prevent people form using the files directly and you can just leave them as unencrypted PNG's or just raw data. So you load the PNG/ copy the spans out to a second/third (whatever) image to reassemble it.

While you can encode the data, but this tends to have flow on impacts on their final compression ratio. So if the final project size is an issue, it's worth considering.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
luxuluxu
2
Years of Service
User Offline
Joined: 12th Mar 2022
Location:
Posted: 13th Mar 2022 12:38

Excuse me, has your problem been solved?

Login to post a reply

Server time is: 2024-11-21 12:33:58
Your offset time is: 2024-11-21 12:33:58