Beispiel #1
0
int _tmain(int argc, _TCHAR* argv[])
{
	bool compress;

	_tprintf(_T("bmzip Copyright (C) 2012  Jeffrey Bush <*****@*****.**>\n"));
	_tprintf(_T("This program comes with ABSOLUTELY NO WARRANTY;\n"));
	_tprintf(_T("This is free software, and you are welcome to redistribute it\n"));
	_tprintf(_T("under certain conditions;\n"));
	_tprintf(_T("See http://www.gnu.org/licenses/gpl.html for more details.\n"));
	_tprintf(_T("\n"));

	compress = argc > 1 && _tcslen(argv[1]) == 2 && (argv[1][0] == _T('-') || argv[1][0] == _T('/')) && (argv[1][1] == _T('c') || argv[1][1] == _T('C'));
	if (!compress && argc == 3)		return bm_decomp(argv[1], argv[2]);
	else if (compress && argc == 4)	return bm_comp(argv[2], argv[3]);
	usage(argv[0]);
	return 1;
}
Beispiel #2
0
main(int argc, char **argv)
{
	void *kern, *filesys, *ramdisk;
	int kernlen, filesyslen;
	bm_pat *bm;
	static char pattern[] = "Ramdiskorigin";

	if (argc != 3) {
		fprintf(stderr, "usage: %s kernel filesystem", argv[0]);
		exit(1);
	}

	/* Map the kernel image read/write */
	kern = map(argv[1], O_RDWR, &kernlen);

	/* Map the filesystem image read only */
	filesys = map(argv[2], O_RDONLY, &filesyslen);

	/* Search the kernel image for the ramdisk signature */
	bm = bm_comp(pattern, sizeof(pattern), NULL);
	ramdisk = bm_exec(bm, kern, kernlen);
	if (!ramdisk) {
		fprintf(stderr, "Origin of ramdisk not found in kernel\n");
		exit(1);
	}

	/* Does the filesystem image fit into the kernel image? */
	if ((kernlen - (ramdisk - kern)) < filesyslen) {
		fprintf(stderr, "Kernel image to small\n");
		exit(1);
	}

	/* Copy the filesystem image into the kernel image */
	memcpy(ramdisk, filesys, filesyslen);

	/* Sync vm/fs and unmap the images */
	msync(kern, kernlen, 0);
	munmap(kern, kernlen);
	munmap(filesys, filesyslen);
	exit(0);
}