If you are getting an MD5 hash of an embedded resource at runtime to try to prevent possible corruption/substitution of the resource doing it at runtime will do not good.
If the resource is corrupt or replaced the hash will be from the bad resource.
You need to get the MD5 beforehand, and then program a check at startup if the MD5 matches the original hash.
You need to get the MD5 beforehand, and then program a check at startup if the MD5 matches the original hash.
which implies doing it at runtime to check the stored number. But any half decent hacker can change the hash if they can change the data, if you are using such a common and old algorithm. It may slow them down, but
-everyone knows md5
-the hacker has the original bitmap that he took out
- the hacker has the new bitmap
- you haven't really increased security.
if you at least did something screwy like hashed every nth byte of the data, maybe in reverse, they would at least have to disassemble your code to get to the bottom of it.
- you can screw with the round robin constants to have something md5-like that isn't md-5 as well, that would be aggravating to figure out, esp if you just kept on calling your routine md-5.
md5 is a bit of a long, but not too complex algorithm. do you need the code for it or something? Ive got one that I lifted from the web and sped up a bit if you can't find one for yourself. Its probably more c-ish than some would care for, but it works.
that I can't answer. How do you extract it to display it? "bitmap" is also a risky term, to some it means an RGB array and to others, an object representing a windows file format that has a few extra fields alongside the data array.
Can you get to an RGB or RGBA array of the image? It should be ok to just do that part; if the image data is the same then the other fields are pretty much irrelevant. You can check the size (rows/cols) field(s) first to save time: if the sizes mismatch its a no-go.
however you choose to do it must match ... the same bytes on the pre-computed answer and the live computed result ... of course!
There isn't one in pure c++. Dunno if windows libs pull in that function or not. Or some other library?
you need some way to look at what you have as if it were a disk file or a block of bytes. Once you have that you just run MD5 on it, which you can do with either someone's library and a bunch of effort or just grab the code and dump that into a function in your project.
the entire concept of resources is more of a windows concept (but the same idea is used in many other places like data-dlls / wadfiles / etc type things) so I would look there first. Some of this stuff may be under the managed umbrella and I have avoided that like the plague -- I saw what M$ did to java, and Ive seen what they did to c++, and Im not having any of it :)
Thank you guys for the responses and thanks jonnin for the follow-up resource links. With LoadResource and other API related functions, I finally got this one solved.