mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-15 03:50:08 +00:00
Added .clang-format, formatted codebase
This commit is contained in:
@@ -1,38 +1,46 @@
|
||||
#include "lconfig.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "lconfig.h"
|
||||
|
||||
#define ERR(...) do { printf(__VA_ARGS__); exit(EXIT_FAILURE); } while(0);
|
||||
#define ERR(...) \
|
||||
do { \
|
||||
printf(__VA_ARGS__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} 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) {
|
||||
void writeArray(FILE *out, uint8_t *data, int sz)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(out, "{");
|
||||
for (i = 0; i < sz-1; i++) {
|
||||
for (i = 0; i < sz - 1; i++) {
|
||||
fprintf(out, "0x%02x, ", data[i]);
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
void writeDefineVal(FILE *out, char *ident, int data)
|
||||
{
|
||||
fprintf(out, "#define %s 0x%02x\n", ident, data);
|
||||
}
|
||||
|
||||
void addPadding(uint8_t *data, int start) {
|
||||
void addPadding(uint8_t *data, int start)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* if the box is less than LAIKA_VM_CODESIZE, add semi-random padding */
|
||||
@@ -41,7 +49,8 @@ void addPadding(uint8_t *data, int start) {
|
||||
}
|
||||
}
|
||||
|
||||
void makeSKIDdata(char *data, int sz, uint8_t *buff, int key) {
|
||||
void makeSKIDdata(char *data, int sz, uint8_t *buff, int key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sz; i++)
|
||||
@@ -51,13 +60,14 @@ void makeSKIDdata(char *data, int sz, uint8_t *buff, int key) {
|
||||
addPadding(buff, i);
|
||||
}
|
||||
|
||||
#define MAKESKIDDATA(macro) \
|
||||
key = RANDBYTE; \
|
||||
makeSKIDdata(macro, strlen(macro), tmpBuff, key); \
|
||||
writeDefineVal(out, "KEY_" #macro, key); \
|
||||
#define MAKESKIDDATA(macro) \
|
||||
key = RANDBYTE; \
|
||||
makeSKIDdata(macro, strlen(macro), tmpBuff, key); \
|
||||
writeDefineVal(out, "KEY_" #macro, key); \
|
||||
writeDefineArray(out, "DATA_" #macro, tmpBuff);
|
||||
|
||||
int main(int argv, char **argc) {
|
||||
int main(int argv, char **argc)
|
||||
{
|
||||
uint8_t tmpBuff[LAIKA_VM_CODESIZE];
|
||||
int key;
|
||||
FILE *out;
|
||||
@@ -68,7 +78,8 @@ int main(int argv, char **argc) {
|
||||
if ((out = fopen(argc[1], "w+")) == NULL)
|
||||
ERR("Failed to open %s!\n", argc[1]);
|
||||
|
||||
srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to slow them down */
|
||||
srand(time(NULL)); /* really doesn't need to be cryptographically secure, the point is only to
|
||||
slow them down */
|
||||
|
||||
fprintf(out, PREAMBLE);
|
||||
/* shared */
|
||||
|
Reference in New Issue
Block a user