aboutsummaryrefslogtreecommitdiff
path: root/example.c
blob: 93688f33915839d617d5818fd352134b7e630ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <time.h>

#include "funccrypt.h"


static int crypted_fn(int arg0, char *arg1, void *arg2)
{
    CRYPT_PROLOGUE(crypted_fn);
    int i;
    printf("I'm decrypted ..\n");
    for (i = 0; i < 32; ++i)
        printf("%d ", i);
    puts("");
    CRYPT_EPILOGUE(crypted_fn);

    return 0x66;
}

static void crypted_fn2(void)
{
    CRYPT_PROLOGUE(crypted_fn2);
    printf("Another decrypted fn..\n");
    CRYPT_EPILOGUE(crypted_fn2);
}

CRYPT_FNDEF(crypted_fn3, void *arg0, int arg1, const char *arg2)
{
    printf("Yet another cryptable fn.. ");
    /* generate some nonsense machine instructions */
    printf("."); printf("."); printf("."); printf(".");
    printf("\n");
}
CRYPT_FNEND(crypted_fn3);

int main(void)
{
    srand(time(NULL));

#ifdef _DEBUG
    printf("Before Encryption:\n");
    printf("crypted_fn:\n");
    printHexBuf((uint8_t *)crypted_fn, 160, 32);
    printf("crypted_fn2:\n");
    printHexBuf((uint8_t *)crypted_fn2, 160, 32);
    printf("crypted_fn3:\n");
    printHexBuf((uint8_t *)crypted_fn3, 160, 32);
#endif
    printf("\nAfter Encryption:\n");
    printf("crypted_fn return val: %s\n",
           crypt_strs[ crypt_func((void *)crypted_fn) ]);
    printf("crypted_fn2 return val: %s\n",
           crypt_strs[ crypt_func((void *)crypted_fn2) ]);
    printf("crypted_fn3 return val: %s\n",
           crypt_strs[ crypt_func((void *)crypted_fn3) ]);

    printf("crypted_fn:\n");
    printHexBuf((uint8_t *)crypted_fn, 160, 32);
    printf("crypted_fn2:\n");
    printHexBuf((uint8_t *)crypted_fn2, 160, 32);
    printf("crypted_fn3:\n");
    printHexBuf((uint8_t *)crypted_fn3, 160, 32);
#ifdef _DEBUG
    printf("\noutput:\n");
    printf("crypted_fn: 0x%X\n", crypted_fn(0, NULL, NULL));
    crypted_fn2();
    crypted_fn3(NULL, (unsigned int)-1, "TEST");
#endif
    return 0;
}