Tuesday, October 4
Shadow

Syncword insert/sync tools, somewhat borked

#include <cstdio>
#include <stdint.h>
#include <fstream>

/* syncword will be inserted every SYNCWORD_INTERVAL 64-bit chunks */
#define SYNCWORD_INTERVAL 10

int main(int argc, char *argv[]) {
    const uint64_t syncword = 0x1acffc1d69420694;

    if(argc < 3) {
        fprintf(stderr, "%s - take binary file and add a syncword(0x%llx) to it\n", argv[0], syncword);
        fprintf(stderr, "usage: %s input output\n", argv[0]);
        return 1;
    }

    std::ifstream input(argv[1], std::ios::binary);
    if(!input.is_open()) {
        fprintf(stderr, "could not open %s\n", argv[1]);
        return 1;
    }

    std::ofstream output(argv[2], std::ios::binary);
    if(!output.is_open()) {
        fprintf(stderr, "could not open %s\n", argv[1]);
        return 1;
    }

    uint64_t* buffer = (uint64_t*)malloc((SYNCWORD_INTERVAL + 1) * sizeof(uint64_t)); // SYNCWORD_INTERVAL + 1 for syncword

    buffer[0] = syncword;

    while(input.read((char*)&buffer[1], SYNCWORD_INTERVAL * sizeof(uint64_t))) {
        output.write((char*)buffer, (SYNCWORD_INTERVAL + 1) * sizeof(uint64_t));
    }

    free(buffer);
    input.close();
    output.close();
}

Leave a Reply