mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Bazaar/Protect : fixed compiling in optimal mode for GCC
git-svn-id: svn://ultimatepp.org/upp/trunk@3150 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
844cf49278
commit
ed89332b46
3 changed files with 15 additions and 5 deletions
|
|
@ -16,6 +16,9 @@ using namespace Upp;
|
|||
|
||||
#ifdef PLATFORM_POSIX
|
||||
|
||||
// no optimize with -O2 or more an encrypted function
|
||||
#define PROTECT_NO_OPTIMIZE __attribute__((optimize(0)))
|
||||
|
||||
#define PROTECT_START_FUNC(decrFunc) \
|
||||
static bool __decrypted = false; \
|
||||
if(!__decrypted) \
|
||||
|
|
@ -81,6 +84,10 @@ using namespace Upp;
|
|||
|
||||
#else
|
||||
|
||||
// no optimize strongly an encrypted function
|
||||
// @@ TO DO -- check if needed on MSC...
|
||||
#define PROTECT_NO_OPTIMIZE
|
||||
|
||||
#define _PROTECT_START_MARKER __asm _emit 0xba __asm _emit 0xad __asm _emit 0xde __asm _emit 0xad __asm _emit 0xfa __asm _emit 0xce
|
||||
#define _PROTECT_END_MARKER __asm _emit 0xc0 __asm _emit 0xde __asm _emit 0xde __asm _emit 0xad __asm _emit 0xfe __asm _emit 0xed
|
||||
|
||||
|
|
@ -202,8 +209,9 @@ using namespace Upp;
|
|||
const int len = strlen("abracadabra"); \
|
||||
Buffer<byte>buf(len); \
|
||||
Buffer<byte>nonce(6); \
|
||||
memcpy(buf, crypted + 6 /* sizeof(PROTECT_START_MARKER)*/, len); \
|
||||
memcpy(nonce, crypted, 6); \
|
||||
/* can't use memcpy, it gets optimized out */ \
|
||||
for(int i = 0; i < len; i++) buf[i] = crypted[i + 6 /* sizeof(PROTECT_START_MARKER)*/]; \
|
||||
for(int i = 0; i < 6 /* sizeof(PROTECT_START_MARKER)*/; i++) nonce[i] = crypted[i]; \
|
||||
decrFunc(buf, len, nonce, 6); \
|
||||
__keyOk = !memcmp(buf, "abracadabra", len); \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -896,9 +896,11 @@ string, every 2 chars represent 1 hex byte.&]
|
|||
[s0; &]
|
||||
[s0;i150;O0; In your application, enclose parts of code you want
|
||||
to be encrypted by mean of PROTECT`_START`_FUNC(decrFunc) and
|
||||
PROTECT`_END`_FUNC macros :&]
|
||||
PROTECT`_END`_FUNC macros, and mark function as [* non`-optimizable],
|
||||
otherwise the optimizing compiler will rearrange the code and
|
||||
make the system crash : :&]
|
||||
[s0; &]
|
||||
[s0;l160; [/ void MyEncryptedFunction(void)]&]
|
||||
[s0;l160; [*/ PROTECT`_NO`_OPTIMIZE][/ void MyEncryptedFunction(void)]&]
|
||||
[s0;l160; [/ `{]&]
|
||||
[s0;l160; [/ -|][*/ PROTECT`_START`_FUNC(Decrypt);]&]
|
||||
[s0;l160;/ &]
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ we can make cracker`'s live a bit more difficult if we encrypt
|
|||
somehow also sensitive parts of code with a random key.&]
|
||||
[s0; This is done by another couple of macros :&]
|
||||
[s0; &]
|
||||
[s0;l160; [/ void MyObfuscatedFunction(void)]&]
|
||||
[s0;l160; [*/ PROTECT`_NO`_OPTIMIZE][/ void MyObfuscatedFunction(void)]&]
|
||||
[s0;l160; [/ `{]&]
|
||||
[s0;l160; [/ -|][*/ OBFUSCATE`_START`_FUNC;]&]
|
||||
[s0;l160;/ &]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue