diff options
author | kr3nshaw <20672068+kr3nshaw@users.noreply.github.com> | 2020-06-08 20:46:44 +1000 |
---|---|---|
committer | kr3nshaw <20672068+kr3nshaw@users.noreply.github.com> | 2020-06-08 20:46:44 +1000 |
commit | dd04f2ba09632dcaa6a27fdf802c3687b87d9370 (patch) | |
tree | 4f9d5555e6158a5e464827b1a64ce4b8a3d36772 /tools/nitrogfx/util.c | |
parent | 9243be03ab56a74fd083205c9a2017e4fc4b4ff6 (diff) | |
parent | 5dfe3440383dd530bda24985f802d8c94bb452b8 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'tools/nitrogfx/util.c')
-rw-r--r-- | tools/nitrogfx/util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 87abeb31..73a128a1 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <stdint.h> #include <errno.h> #include <limits.h> #include "global.h" @@ -122,3 +123,26 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) fclose(fp); } + +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder) +{ + unsigned char header[0x10] = + { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 }; + //magic number + memcpy(header, magicNumber, 4); + + //byte order + if (!byteorder) + { + memset(header + 4, 0, 2); + } + + //size + size += 0x10; //add header size + header[8] = size & 0xFF; + header[9] = (size >> 8) & 0xFF; + header[10] = (size >> 16) & 0xFF; + header[11] = (size >> 24) & 0xFF; + + fwrite(header, 1, 0x10, fp); +} |