From 09be8ace254a7f8bb69542d09a6b2013636123a2 Mon Sep 17 00:00:00 2001 From: Nathan Lee Date: Sun, 13 Sep 2026 17:46:26 -0500 Subject: EFI boot header support --- misc/kassemble.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 misc/kassemble.c (limited to 'misc') diff --git a/misc/kassemble.c b/misc/kassemble.c new file mode 100644 index 0000000..a818cc5 --- /dev/null +++ b/misc/kassemble.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) { + if (argc != 4) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + const char *in_path = argv[1]; + const char *out_path = argv[2]; + char *end; + errno = 0; + unsigned long long size = strtoull(argv[3], &end, 16); + if (errno || *end != '\0') { + fprintf(stderr, "bad size: %s, invalid chars: %s\n", argv[3], end); + return 1; + } + + FILE *in = fopen(in_path, "rb"); + if (!in) { perror("fopen in"); return 1; } + + FILE *out = fopen(out_path, "wb"); + if (!out) { perror("fopen out"); fclose(in); return 1; } + + /* Copy in -> out */ + unsigned char buf[65536]; + size_t n; + while ((n = fread(buf, 1, sizeof buf, in)) > 0) { + if (fwrite(buf, 1, n, out) != n) { perror("fwrite"); return 1; } + } + if (ferror(in)) { perror("fread"); return 1; } + + /* Write size as u64 little-endian at offset 16 */ + unsigned char le[8]; + for (int i = 0; i < 8; i++) + le[i] = (unsigned char)(size >> (8 * i)); + + if (fseek(out, 16, SEEK_SET) != 0) { perror("fseek"); return 1; } + if (fwrite(le, 1, 8, out) != 8) { perror("fwrite size"); return 1; } + + fclose(in); + if (fclose(out) != 0) { perror("fclose out"); return 1; } + return 0; +} -- cgit v1.2.3