I searched a bit through stackoverflow and can't find the exact examples of approaches of how to prevent someone to use dll.
Consider a dll with some exported function, that creates com-like object:
extern "C" _declspec(dllexport)void factory(void **obj)
{
Object *object = new Object();
*obj = object;
}
Obvious idea that comes to mind is to add second argument as a key:
extern "C" _declspec(dllexport)void factory(void **obj, const char *key)
{
if(strcmp(key, "just a secret here as a const string"))
return;
Object *object = new Object();
*obj = object;
}
But I think it would be extremely easy to decompile it and get the secret. Well, I can manually obfuscate it a bit:
extern "C" _declspec(dllexport)void factory(void **obj, const char *key)
{
if(key[0] != 256 - 59 || key[1] != sqrt(16) || key[2] != 'g')
return;
Object *object = new Object();
*obj = object;
}
Yet, I think this is also easy to disassembler.
Does anyone one more secure way to license the dll?