Possible to load a PNG file from within a binary data file?

I’ve allowed people to mod my SDL WW2 game Firefight, but modders complain that as they have to distribute all their work as PNG files other people can rip off their work. They’ve asked if I can make it so that their PNGs are somehow obfuscated. Is it possible with SDL (I’m still using SDL2, but could update to 3 if needed) to load a PNG from raw data contained within a binary data file?

If so, I could build a big binary file with an index and then all the PNG files concatenated onto it, and get SDL to load the data for the PNG image from that.

Is it possible for SDL to do this?

Yes, you can build your own data file format that includes PNGs and then use SDL_LoadPNG_IO() to load from an I/O stream.

However, it’s trivial to scan a data file for PNG signatures and extract the images. Even if you obfuscate the data, if someone is motivated enough they can inspect your application code for deobfuscating or decryption and reverse engineer it, so this wouldn’t prevent people who really want to get the images out of the data files. If they really wanted, they could even use a tool to inspect the GPU memory and pull the textures out of there. :slight_smile:

1 Like

Thanks! I guess this is SDL3 only?

I’m OK with it being relatively easy for people to hack my binary file to find the PNGs, I’m guessing 99% of people won’t figure that out and it’s not a catastrophe if some do anyway.

I should have asked too, if the same thing can be done with sound files too?

If you are willing to load the images or sound files into memory yourself and then decode them from there, yes.

SDL2 doesn’t have any built-in PNG support that I’m aware of, but SDL3’s PNG loader uses stb_image under the hood, so for SDL2 you could just use it directly (stb_image supports decoding PNG images from memory).

You can always use a tiny SQL database (SQLite) instead of a proprietary binary format. But that’s all for naught, because there are GPU snooping tools that not only allow you to extract textures but also inspect the entire rendering pipeline, step by step, including profiling.

So don’t waste time obfuscating and hiding data, because if someone thinks your textures are valuable, they’ll extract them sooner or later, no matter how well they are hidden.

What level of obfuscation do you tend toward:

  • Cryptography and DRM are my life’s work.
  • It’s part of the game, the layers on this onion go deeper than anyone might expect.
  • Three or four layers, if they go this far the user knows they are breaking a law if they distribute what they take.
  • One or two layers, enough to stop the player from spoiling content for themselves
  • Request that players not steal from fellow users.
  • Change your Modder’s expectations, ask for their understanding.
  • None.
0 voters