diff options
Diffstat (limited to 'funccrypt.h')
-rw-r--r-- | funccrypt.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/funccrypt.h b/funccrypt.h index bdac0f3..56d1930 100644 --- a/funccrypt.h +++ b/funccrypt.h @@ -21,21 +21,24 @@ typedef struct crypt_header { } GCC_PACKED crypt_header; typedef enum crypt_return { - CRET_ERROR /* Neither prologue marker nor epilogue marker found. */, - CRET_PROLOGUE /* prologue marker found */, - CRET_EPILOGUE /* epilogue marker found */, - CRET_CHECK /* all pre (en|de)cryption checks successful */, - CRET_OK /* (en|de)cryption succeeded */ + CRET_ERROR, /* Neither prologue marker nor epilogue marker found. */ + CRET_ERROR_MEM, /* set memory page protection failed */ + CRET_PROLOGUE, /* prologue marker found */ + CRET_EPILOGUE, /* epilogue marker found */ + CRET_CHECK, /* all pre (en|de)cryption checks successful */ + CRET_OK_ENC, /* encryption succeeded */ + CRET_OK_DEC, /* decryption succeeded */ } crypt_return; #define CRYPT_FUNC_MAXSIZ 0x100 #define CRYPT_FUNC(fn) \ crypt_func((void *)fn) +#define CRYPT_RETVAL() __cr #define CRYPT_PROLOGUE(fn) \ crypt_return __cr; \ { \ __cr = CRYPT_FUNC(fn); \ - if (__cr != CRET_OK) \ + if (__cr != CRET_OK_DEC) \ asm volatile goto("jmp %l0 \n" \ : : : : cr_epilogue); \ asm volatile goto("jmp %l0 \n" \ @@ -65,7 +68,8 @@ typedef enum crypt_return { ); \ } \ cr_epilogue: \ - CRYPT_FUNC(fn); + if (CRYPT_RETVAL() == CRET_OK_DEC) \ + CRYPT_FUNC(fn); #define CRYPT_FNDEF(name, ...) \ void name( __VA_ARGS__ ) { \ |