#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main()
{
	# define ELF_HD "\177ELF"
	int nr;
	char inp[512];

	int fi, fo;

	if ((fi = open("arch/i386/boot/compressed/vmlinux", O_RDONLY)) < 0) {
		perror("Reading vmlinux");
		exit(3);
	}
		
	if ((fo = open("kernel.2200", O_WRONLY|O_CREAT, 0644)) < 0) {
		perror("Writing kernel.2200");
		exit(3);
	}

	nr = read(fi, inp, 512);
	if (nr != 512) {
		fprintf(stderr, "Error on Input, only %d bytes read in\n", nr);
		exit(1);
	}

	if (!strncmp(inp, ELF_HD, 4)) {
		inp[0x2c] = 1;

		write(fo,inp,512);
	} else {
		fprintf(stderr, "no ELF-Header in Input. Exiting ...\n");
		exit(1);
	}

	while ((nr = read(fi, inp, 512)) > 0) {
		write(fo,inp,nr);
	}

	close(fi);
	close(fo);

	return 0;
}

