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 tools/Makefile
include src/Makefile include src/Makefile
default: all .PHONY: all
all: embed libdzonerzy libdzonerzy-gen all: embed libdzonerzy libdzonerzy-gen
runlocal: embed libdzonerzy-runlocal runlocal: embed libdzonerzy-runlocal
tools: embed
clean: clean-tools clean-libdzonerzy 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 "`" #define MD_CODE(x) "`" x "`"
// code block macros // code block macros
#define MD_CODEBLOCK(x) "```" x "```" #define MD_CODEBLOCK(x) "```" x "```"
// start/end a code block macros
#define MD_CODEBLOCK_TICKS(x) "\n```" x "\n"
// code block macros with language // code block macros with language
#define MD_CODEBLOCK_LANG(l, c) "```" l "\n" c "\n```" #define MD_CODEBLOCK_LANG(l, c) "```" l "\n" c "\n```"
// text macros // text macros

View File

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