from zero to botnet

This commit is contained in:
dzonerzy 2023-10-19 14:02:01 +02:00
parent 1f3538e47d
commit 704ebd3919
13 changed files with 101 additions and 74 deletions

View File

@ -1,10 +1,12 @@
include tools/Makefile
include src/Makefile
default: all
.PHONY: all
all: embed libdzonerzy libdzonerzy-gen
runlocal: embed libdzonerzy-runlocal
tools: embed
clean: clean-tools clean-libdzonerzy

BIN
res/binwalk.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

BIN
res/bored-hacker.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

BIN
res/botnet.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 KiB

BIN
res/bug-wires.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

BIN
res/dark-side-cookie.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

BIN
res/hopeless-programmer.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

BIN
res/router-going-wild.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

BIN
res/routers-stunned.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
res/system-add-user.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

File diff suppressed because one or more lines are too long

View File

@ -87,6 +87,8 @@ Copyright:
#define MD_CODE(x) "`" x "`"
// code block macros
#define MD_CODEBLOCK(x) "```" x "```"
// start/end a code block macros
#define MD_CODEBLOCK_TICKS(x) "\n```" x "\n"
// code block macros with language
#define MD_CODEBLOCK_LANG(l, c) "```" l "\n" c "\n```"
// text macros

View File

@ -31,6 +31,7 @@ typedef struct _embed
char *format;
int verbose;
int quiet;
int autowrap;
} embed_t;
static void usage(char **argv);
@ -43,7 +44,7 @@ int main(int argc, char **argv)
int c = 0;
embed_t args = {0};
while ((c = getopt(argc, argv, "hvi:o:f:Vq")) != -1)
while ((c = getopt(argc, argv, "hvi:o:f:Vqw")) != -1)
{
switch (c)
{
@ -89,6 +90,9 @@ int main(int argc, char **argv)
case 'q':
args.quiet = 1;
break;
case 'w':
args.autowrap = 1;
break;
default:
usage(argv);
exit(EXIT_FAILURE);
@ -207,12 +211,6 @@ int embed(embed_t *args)
return EXIT_FAILURE;
}
if (args->output == NULL)
{
fprintf(stderr, "Output file not specified\n");
return EXIT_FAILURE;
}
if (args->format == NULL)
{
fprintf(stderr, "Output format not specified\n");
@ -235,13 +233,15 @@ int embed(embed_t *args)
return EXIT_FAILURE;
}
FILE *output = fopen(args->output, "w");
FILE *output = NULL;
if (output == NULL)
if (args->output != NULL)
{
if (!args->quiet)
fprintf(stderr, "Unable to open output file: %s\n", args->output);
return EXIT_FAILURE;
output = fopen(args->output, "w");
}
else
{
output = stdout;
}
char *name_only = strdup(args->input);
@ -276,48 +276,76 @@ int embed(embed_t *args)
if (args->format[0] == 'c')
{
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {\n", name_only, input_name);
if (args->autowrap)
{
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {\n", name_only, input_name);
}
else
{
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {", name_only, input_name);
}
}
else if (args->format[0] == 'h')
{
fprintf(output, "#pragma once\n");
fprintf(output, "#ifndef %s_H\n", input_name);
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {\n", name_only, input_name);
if (args->autowrap)
{
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {\n", name_only, input_name);
}
else
{
fprintf(output, "__attribute__((section(\"embed/%s\"))) const unsigned char %s[] = {", name_only, input_name);
}
}
int c = 0;
int i = 0;
while ((c = fgetc(input)) != EOF)
if (args->autowrap)
{
if (i == 0)
while ((c = fgetc(input)) != EOF)
{
fprintf(output, " ");
if (i == 0)
{
fprintf(output, " ");
}
fprintf(output, "0x%02X", c);
fprintf(output, ", ");
if (i < 15)
{
fprintf(output, ", ");
}
else
{
fprintf(output, ",\n");
i = -1;
}
i++;
}
fprintf(output, "0x%02X", c);
if (i < 15)
if (i > 0)
{
fprintf(output, "\n");
}
fprintf(output, " 0x00,\n");
fprintf(output, "};\n");
}
else
{
while ((c = fgetc(input)) != EOF)
{
fprintf(output, "0x%02X", c);
fprintf(output, ", ");
}
else
{
fprintf(output, ",\n");
i = -1;
}
i++;
fprintf(output, "0x00");
fprintf(output, "};\n\n");
}
if (i > 0)
{
fprintf(output, "\n");
}
fprintf(output, " 0x00,\n");
fprintf(output, "};\n");
if (args->format[0] == 'h')
{
fprintf(output, "#endif /* %s_H */\n", input_name);