blob: 7f5735737c80c452060d32c8a27bb83b89821565 [file] [log] [blame] [raw]
#include "hive-internals.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <endian.h>
void checksum(struct regf_header *head) {
uint32_t *p = (uint32_t *)head;
head->csum = 0;
while((char *)p - (char *)head < 508) head->csum ^= le32toh(*p++);
}
int main(int argc, char **argv) {
if(argc < 2) {
fprintf(stderr, "Usage: %s [-n] <path>\n", argv[0]);
return -1;
}
int open_flags = O_WRONLY;
int fd = open(argv[1], open_flags, 0666);
if(fd == -1) {
perror(argv[1]);
return 1;
}
off_t file_size = lseek(fd, 0, SEEK_END);
if(file_size == (off_t)-1) {
perror("lseek");
return 1;
}
lseek(fd, 0, SEEK_SET);
struct regf_header head = {
.magic = "regf",
.major_ver = 1,
.offset = 0x20,
.blocks = file_size - 0x1000,
};
checksum(&head);
int s = write(fd, &head, sizeof head);
if(s < 0) {
perror("write");
return 1;
}
return 0;
}