ev3duder  0.3.0
EV3 Downloader/Uploader
mkrbf.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 
12 #include "defs.h"
13 #include "error.h"
14 #include "funcs.h"
15 
16 //calling with buf = null is undefined behaviour
17 static const char magic[] = "LEGO"; // MAGIC at start of RBF files
18 static const char before[] =
19 "\x68\x00\x01\x00\x00\x00\x00\x00\x1C\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x60\x80";
20 static const char after[] = "\x44\x85\x82\xE8\x03\x40\x86\x40\x0A";
29 size_t mkrbf(char **buf, const char *cmd)
30 {
31  size_t cmd_sz = strlen(cmd);
32  u32 static_sz = (u32)(sizeof magic -1 + 4 + sizeof before -1 + cmd_sz + 1 + sizeof after -1);
33  *buf = malloc(static_sz);
34  (void)mempcpy(mempcpy(mempcpy(mempcpy(mempcpy(*buf,
35  magic, sizeof magic -1),
36  &static_sz, 4),
37  before, sizeof before - 1),
38  cmd, cmd_sz + 1),
39  after, sizeof after -1);
40  return static_sz;
41 }
42 // funny trivia: This is technically undefined behavior (Translation unit not ending with line break)
Error enumerations and decriptions.
uint32_t u32
Definition: defs.h:11
size_t mkrbf(char **buf, const char *cmd)
Offline functionality. Generates bytecode for executing a binary executable.
Definition: mkrbf.c:29
contains declarations for ev3 commands