mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-14 19:40:24 +00:00
VMBoxGen: minor refactoring
This commit is contained in:
@@ -13,11 +13,12 @@
|
||||
} while (0);
|
||||
#define RANDBYTE (rand() % UINT8_MAX)
|
||||
|
||||
static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c "
|
||||
"*/\n#ifndef LAIKA_VMBOX_CONFIG_H\n#define LAIKA_VMBOX_CONFIG_H\n\n";
|
||||
static const char *PREAMBLE = "/* file generated by VMBoxGen, see tools/vmboxgen/src/main.c */\n"
|
||||
"#ifndef LAIKA_VMBOX_CONFIG_H\n"
|
||||
"#define LAIKA_VMBOX_CONFIG_H\n\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;
|
||||
|
||||
@@ -28,18 +29,18 @@ void writeArray(FILE *out, uint8_t *data, int sz)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
void addPadding(uint8_t *data, int start)
|
||||
static void addPadding(uint8_t *data, int start)
|
||||
{
|
||||
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;
|
||||
|
||||
for (i = 0; i < sz; i++)
|
||||
buff[i] = data[i] ^ key;
|
||||
|
||||
buff[i++] = key; /* add the null terminator */
|
||||
addPadding(buff, i);
|
||||
buff[i++] = key; /* add the null terminator (key ^ key = 0x00) */
|
||||
addPadding(buff, i); /* fill in the remaining bytes with semi-rand padding */
|
||||
}
|
||||
|
||||
#define MAKESKIDDATA(macro) \
|
||||
@@ -69,14 +70,17 @@ void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
|
||||
int main(int argv, char **argc)
|
||||
{
|
||||
uint8_t tmpBuff[LAIKA_VM_CODESIZE];
|
||||
int key;
|
||||
FILE *out;
|
||||
char *fileName;
|
||||
int key;
|
||||
|
||||
if (argv < 2)
|
||||
ERR("USAGE: %s [OUTFILE]\n", argv > 0 ? argc[0] : "BoxGen");
|
||||
|
||||
if ((out = fopen(argc[1], "w+")) == NULL)
|
||||
ERR("Failed to open %s!\n", argc[1]);
|
||||
/* open output file */
|
||||
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
|
||||
slow them down */
|
||||
@@ -100,8 +104,8 @@ int main(int argv, char **argc)
|
||||
fprintf(out, POSTAMBLE);
|
||||
fclose(out);
|
||||
|
||||
printf("Wrote %s\n", argc[1]);
|
||||
printf("Laika VMBox data header dumped to '%s'\n", fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef MAKEDATA
|
||||
#undef MAKESKIDDATA
|
||||
|
Reference in New Issue
Block a user