PolymorphicEngine
Barry Renaming 'encrypted' to 'polymorphic' e7850a6 (3 years, 5 months ago)diff --git a/src/main.c b/src/main.c index be08164..ab676ef 100644 --- a/src/main.c +++ b/src/main.c @@ -12,19 +12,17 @@ #define NAME_AFFIX_LENGTH 6 /* Number of random chars after prefix */ #define KEY_SIZE 8 /* Size of encryption key */ -#define ENCRYPTED __attribute__((noinline, section(".encrypted"))) +#define POLYMORPHIC __attribute__((noinline, section(".polymorphic"))) /* Linked values */ -extern unsigned char binaryStart[]; -extern unsigned char encryptedStart[]; -extern unsigned char encryptedEnd[]; +extern unsigned char binaryStart[], polymorphicStart[], polymorphicEnd[]; /* Keys */ const uint8_t act[KEY_SIZE] = {}, /* Operators */ key[KEY_SIZE] = {}; /* Operands */ /* Functions */ -int encrypted_main(int argc, char **argv); +int polymorphic_main(int argc, char **argv); /* Traditional main function */ int @@ -32,7 +30,7 @@ main(int argc, char **argv) { size_t i, mask; void *aligned; - uint8_t *code = (uint8_t *) encryptedStart; + uint8_t *code = (uint8_t *) polymorphicStart; long pageSize = sysconf(_SC_PAGESIZE); /* Make memory writable */ @@ -40,11 +38,11 @@ main(int argc, char **argv) return 1; mask = pageSize - 1; aligned = (void *) ((size_t) code & ~mask); - if (mprotect(aligned, (encryptedEnd - encryptedStart) + pageSize, PROT_READ|PROT_WRITE|PROT_EXEC)) + if (mprotect(aligned, (polymorphicEnd - polymorphicStart) + pageSize, PROT_READ|PROT_WRITE|PROT_EXEC)) return 1; /* Decrypt our code */ - for (i = 0; i < (encryptedEnd - encryptedStart); i++) { + for (i = 0; i < (polymorphicEnd - polymorphicStart); i++) { switch (act[i % KEY_SIZE]) { case 0: code[i] ^= key[i % KEY_SIZE]; @@ -59,11 +57,11 @@ main(int argc, char **argv) } /* Run the decrypted code */ - return encrypted_main(argc, argv); + return polymorphic_main(argc, argv); } /* Copy a file */ -ENCRYPTED +POLYMORPHIC void copy_file(char *src, char *dst) { @@ -93,15 +91,15 @@ copy_file(char *src, char *dst) fclose(child); } -/* Encrypted main function */ -ENCRYPTED +/* Polymorphic main function */ +POLYMORPHIC int -encrypted_main(int argc, char **argv) +polymorphic_main(int argc, char **argv) { char filename[NAME_PREFIX_LENGTH + NAME_AFFIX_LENGTH + 1] = NAME_PREFIX, /* Possible characters in filename */ alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - uint8_t dKey[KEY_SIZE], dAct[KEY_SIZE], data, *code = (uint8_t *) encryptedStart; + uint8_t dKey[KEY_SIZE], dAct[KEY_SIZE], data, *code = (uint8_t *) polymorphicStart; FILE *child; size_t i; @@ -131,8 +129,8 @@ encrypted_main(int argc, char **argv) fwrite(dKey, 1, KEY_SIZE, child); /* Encrypt our code */ - fseek(child, (unsigned long int) (encryptedStart - binaryStart), SEEK_SET); - for (i = 0; i < (encryptedEnd - encryptedStart); i++) { + fseek(child, (unsigned long int) (polymorphicStart - binaryStart), SEEK_SET); + for (i = 0; i < (polymorphicEnd - polymorphicStart); i++) { data = code[i]; switch (dAct[i % KEY_SIZE]) { case 0: