Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Protect package - A starting copy protection system
Re: Protect package - A starting copy protection system [message #31079 is a reply to message #30973] Fri, 04 February 2011 01:39 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Protect main encryption routines PROTECT_XXX works (finally !!!) with optimized mode in GCC too.... it was quite difficult Smile

OBFUSCATE_xxx macros STILL DON'T WORK in optimized mode, so don't use them or the app will crash Smile
I'm trying to solve it, but not sure that it's possible.

BTW GCC, besides the nasty optimizer that is on the way even if you don't want it, has a nasty bug on __attribute((optimize(0)))
for functions that makes it call wrong ones sometimes, so for now don't do function-level optimizations.
I've seen that also optimization-by-module has sometimes (often...) undesiderable and nasty side effects, so... keep it global ! Smile

Ciao

Max
Re: Protect package - A starting copy protection system [message #31086 is a reply to message #31079] Fri, 04 February 2011 12:04 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Now fully working in optimized mode too, both PROTECT and OBFUSCATE macros.
Tested on GCC 4.4.xxx and MSC9.

Ciao

Max
Re: Protect package - A starting copy protection system [message #31909 is a reply to message #31086] Wed, 06 April 2011 10:02 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Max,

I tried the ProtectTest package on Windows. It worked beautifully when compiled with MSC9 but crashed when compiled with MSC10. Can you help?

(Also it turns out that 64-bit versions can not be compiled at all. However, this is not currently especially important for me.)

Best regards,

Tom
Re: Protect package - A starting copy protection system [message #31910 is a reply to message #31909] Wed, 06 April 2011 13:49 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Tom1 wrote on Wed, 06 April 2011 10:02

Hi Max,

I tried the ProtectTest package on Windows. It worked beautifully when compiled with MSC9 but crashed when compiled with MSC10. Can you help?

(Also it turns out that 64-bit versions can not be compiled at all. However, this is not currently especially important for me.)

Best regards,

Tom



Hi Tom,

I've just tested it and developed on windows32, MSC9 and on gcc (should work on both 32 and 64 bit of gcc).
The code is STRONGLY dependent on compiler's optimizations, so it's not easy to make it generic.
I've no time right now to test with MSC10, you can do it looking at the generated code; it's not so easy, indeed.
I had the same prolem with GCC in unoptimized vs. optimized mode; on latter the compiler rearranges the code.
On MSC9 there was no difference between optimized and un-optimized; probably MSC10 does it better.
Try to disable optimizations; if it works, you'll have an hint !

Ciao

Max
Re: Protect package - A starting copy protection system [message #31914 is a reply to message #31910] Wed, 06 April 2011 15:23 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Max,

It turns out disabling optimizations on MSC10 does not help in any way. (Maybe you can take a look at it sometime in the future??)

Now, I have a question: After reading the Protect documentation I was left with the impression that OBFUSCATE_START_FUNC and OBFUSCATE_END_FUNC should surround the code used to obtain the key in order to hide the key retrieval details. Well, I tried this modification with the ProtectTest sample application:
String GetKey(void)
{
	OBFUSCATE_START_FUNC;
	String key(ScanHexString("AABBCCDDEEFF00112233445566778899"));
	OBFUSCATE_END_FUNC;
	return key;
}


... and I got a crash. So, I must have misunderstood something vital. Can you tell me what did I do wrong here?

Best regards,

Tom
Re: Protect package - A starting copy protection system [message #31919 is a reply to message #31914] Wed, 06 April 2011 23:18 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
mhhh... weird. With MSC9 too ?
Anyways, I can't test it right now. Maybe on next days

Max
Re: Protect package - A starting copy protection system [message #31923 is a reply to message #31919] Thu, 07 April 2011 14:55 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Yes, with MSC9.

I kind of found a way around though: First I read the key using obfuscation and store it in a static String variable. Then Decrypt() uses that variable directly when calling PROTECT_DECRYPT(). Then again, I'm not sure if this is really a safe way to do this...(?)

// Tom
Re: Protect package - A starting copy protection system [message #32778 is a reply to message #31923] Wed, 08 June 2011 10:08 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Max,

Do you have plans to make the Protect package work on MSC9x64 or MSC10x64? I found out that inline assembly is not supported by Microsoft compilers on x64 architecture, so this may not be easy to solve.

(My application runs out of memory at around 2.4 GB data allocation even with /LARGEADDRESSAWARE linker option, so I need to switch to x64 platform for that app, but still need Protect to work.)

Best regards,

Tom
Re: Protect package - A starting copy protection system [message #32779 is a reply to message #32778] Wed, 08 June 2011 10:11 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hmmmmm... I've still not tested MSC9/10 on 64 bit, but if they don't support assembly, we can't do anything about it.
Self decrypting code do need inline assembly.
The only thing I can think about would be to make some modules as 32 bit executables protected with protect and spawned by main app.
Not a very nice solution indeed.....

Max

Edit: thinking about it, it would be maybe possible to write a separate assembly routine which modify caller code, but that would require quite a bit of work.... If some assembly guru wants to jump into, he's wellcome Smile

[Updated on: Wed, 08 June 2011 10:15]

Report message to a moderator

Re: Protect package - A starting copy protection system [message #34092 is a reply to message #32779] Mon, 17 October 2011 21:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Added SQLITE support to Protect packages so that now it is not necessary to have MySQL installed to have the package scrambling and encryption features Smile.

Best regards
Iñaki
Re: Protect package - A starting copy protection system [message #35014 is a reply to message #34092] Wed, 28 December 2011 10:54 Go to previous messageGo to next message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hello everybody,

I try to use Protect package with MingW on Windows but it seems it does not support assembler.

Here is my code
/*#include <CtrlLib/CtrlLib.h>
#include <Protect/Protect.h>

using namespace Upp;

void decrypt(byte *start, size_t len, byte const *nonce, size_t nonceLen)
{
    return PROTECT_DECRYPT( start, len, "\xAA\xBB\xCC\xDD\xEE\xFF\x00\11\x22\x33\x44\x55\x66\x77\x88\x99", nonce, nonceLen);
}

void MyEncryptedFunction()
{
	PROTECT_START_FUNC(decrypt);
		PromptOK("solved");
	PROTECT_END_FUNC;
}

GUI_APP_MAIN
{		
	ON_PROTECT_BAD_KEY(decrypt)
	{	
	    PromptOK("License error");	
	    exit(1);	
	}
	
	MyEncryptedFunction();
}
*/

#include <CtrlLib/CtrlLib.h>

#include <Protect/Protect.h>

using namespace Upp;

String GetKey(void)
{
	return ScanHexString("AABBCCDDEEFF00112233445566778899");
}

void Decrypt(byte *start, size_t len, byte const *nonce, size_t nonceLen)
{
	PROTECT_DECRYPT ( start, len, GetKey(), nonce, nonceLen );
}

double CryptedTest(double d, double e)
{
	PROTECT_START_FUNC(Decrypt);

	double f;
	f = d * e;

	PromptOK("CryptedTest DECRYPTED SUCCESFULLY!!!");
	return 2 * f + e;

	PROTECT_END_FUNC;
}

double ObfuscatedTest(double d, double e)
{

	// WARNING -- DON'T PUT ANY return STATEMENT BETWEEN
	// OBFUSCATE_START and OBFUSCATE_END
	OBFUSCATE_START_FUNC;

	double f;
	f = d * e;

	PromptOK("ObfuscatedTest DEOBFUSCATED SUCCESFULLY!!!");

	OBFUSCATE_END_FUNC;

	return 2 * f + e;
}

GUI_APP_MAIN
{
	ON_PROTECT_BAD_KEY(Decrypt)
	{
		bool res = PromptYesNo("Bad key !!&Do you want to continue anyways ?");
		if(!res)
			exit(0);
	}
		
	double d = CryptedTest(3, 4);

	d = ObfuscatedTest(3, 4);
	d = ObfuscatedTest(3, 4);
	
	PromptOK("FINISHED OK !!");
	
}



Here is the error
index.php?t=getfile&id=3599&private=0

Do you have an idea?

Thanks and Best wishes for the New year 2012.

Ratah
  • Attachment: bug.jpg
    (Size: 402.13KB, Downloaded 707 times)
Re: Protect package - A starting copy protection system [message #35015 is a reply to message #35014] Wed, 28 December 2011 13:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Ratah

I have just re-tried package ProtectTest compiled with MinGW 4.5.2 and works well.

In my case it cannot be debugged and the linker gives some warnings about "duplicate section", but the program runs well in XP.


Best regards
Iñaki
Re: Protect package - A starting copy protection system [message #49899 is a reply to message #35015] Fri, 01 June 2018 11:33 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi all! Smile

I'm (finally) trying to update the Protect package, just to solve some of its bugs.
I hope I will succeed, it's not an easy task.
Just some anticipations:

1) It will not use inline assembly code anymore, just a couple of builtins functions available both on GCC and on MSC.
2) It will encrypt ONLY the first byte of each instruction, skipping any address part which may be fixed by linker making
the application crash
3) It should work both for 32 and 64 bit builds now

For point 2 I had to import XED Intel x86 instruction set encoder/decoder; I'll add it to Bazaar to when ready.

Ciao

Max

Re: Protect package - A starting copy protection system [message #49900 is a reply to message #49899] Fri, 01 June 2018 15:43 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Max!

Sounds great!

At this point I wish to point out that I have noticed some customers having my applications freezing at startup with recent Windows 10 systems. I have used PROTECT with MSC9 all these years and the problems have just emerged a few months ago. Not on all systems though. Just some customers. I'm not sure if it has anything to do with PROTECT or writing code on the fly, since Windows does not complain about anything, but clearly something is happening with Windows... Anyway, I'm in process of making a decision how to proceed from now on, but this announcement of yours gives me new hope!

With this new PROTECT, can you support MSBT17 / MSBT17x64 and current U++ Core with C++11?

I wish you the best of luck to this! Smile

Thanks and best regards,

Tom
Re: Protect package - A starting copy protection system [message #49903 is a reply to message #49900] Sat, 02 June 2018 12:34 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
By now I'm testing first code on GCC, 64 bit, both in debug and release mode and it works perfectly.
The only caveat is that I can't set a different encrypting NONCE for each function as before, because there's no
simple way to embed data into the code as I coud do in assembly.
Not a big concern, just a bit less secure and probably crackable if you have a ton of encrypted functions, but
strong enough for most purposes.
I'm fixing the obfuscation part, then I'll go to windows.
It has NO inline assembly code inside, and there are just 2 conditions:

- encrypted code should contain NO data (which AFAIK is always true)
- the compiler should not re-arrange the code so that marked end comes before marked start. This should also be
always true but, if not, the encryptor will notice and signal it.

Code is encrypted only on its first byte of each instruction; remainig bytes and data fields are left unchanged.
This is more than enough to make the program crash if incorrectly decrypted, and avoids fiddling with fields changed
by loader (as far addresses, for example).
It should work on any X86 / X86-64 compiler with minor changes.
Re: Protect package - A starting copy protection system [message #49908 is a reply to message #49903] Mon, 04 June 2018 08:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hi Massimo

Thank you for your efforts.


Best regards
Iñaki
Re: Protect package - A starting copy protection system [message #49912 is a reply to message #49903] Tue, 05 June 2018 11:37 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Max,

This is excellent news. Smile Please let me know when you have the first Windows test release ready.

Thanks and best regards,

Tom
Re: Protect package - A starting copy protection system [message #49913 is a reply to message #49912] Tue, 05 June 2018 17:19 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi Tom,

I'm doing some windows tests (MSC15, 32 bit) and it's working ok.
I'll check it with my protected commerial application and, if all is ok, I'll update the package.
You'll need to make some small changes on your sources (quite small!), but it seems to work perfectly, and
it should work on 64 bit MSC too. No assembly at all inside!
I've not handy a 64 bit MSC, so when I'll post it I'll ask you to do some test!

Ciao

Max
Re: Protect package - A starting copy protection system [message #49916 is a reply to message #49913] Tue, 05 June 2018 19:10 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi!

For some reason, I'm not getting email notifications for this thread... Well, I'll keep polling this thread for more good news!

Thanks,

Tom

Update: And yes! I will absolutely test it as soon as I can and report to you.

[Updated on: Tue, 05 June 2018 19:13]

Report message to a moderator

Re: Protect package - A starting copy protection system [message #49917 is a reply to message #49916] Tue, 05 June 2018 19:30 Go to previous messageGo to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
I don't get any notification either... if you like I can attach here the packages.
I'm fixing other stuffs on my application (protect unrelated, coming from core changes...) so I'll need a bit
more time to test it with protect.
Would you like to have the package preview ?
Previous Topic: UPDATED PROTECT PACKAGE
Next Topic: OAuth2 package for U++
Goto Forum:
  


Current Time: Thu Mar 28 20:42:12 CET 2024

Total time taken to generate the page: 0.01254 seconds