All pastes #720767 Raw Edit

Anonymous

public c v1 · immutable
#720767 ·published 2007-09-30 17:57 UTC
rendered paste body
#include <stdio.h>#include <fcntl.h>#include <sys/types.h>#include <unistd.h>#include <sys/mman.h>#include <sys/stat.h>#include <inttypes.h>#include <string.h>static off_t find_gfxboot(const char *string,			  uint8_t *data, off_t offset, off_t size){	size_t len = strlen(string);	for (; offset <= (size - len); offset++) {		if (memcmp(&data[offset], string, len) == 0)			return offset;	}	return size;}static void print_gfxboot_addr(const char *string, uint8_t *addr, off_t size){	off_t offset;	offset = 0;	while (offset < size) {		offset = find_gfxboot(string, addr, offset, size);		if (offset < size) {			printf("GFXBOOT string found at: 0x%" PRIx64 "\n",				offset);			offset++;		}	}}int main(int argc, char **argv){	int fd;	uint8_t *addr;	struct stat stbuf;	const char *string = "GFXBOOT bootlogo";	off_t patch_address = 0;	if (argc != 2) {		printf("Usage: %s ISO\n", argv[0]);		return 1;	}	fd = open(argv[1], O_RDWR);	if (fd == -1) {		fprintf(stderr, "open failed: %m\n");		return 1;	}	if (fstat(fd, &stbuf) == -1) {		fprintf(stderr, "fstat failed: %m\n");		return 1;	}	addr = mmap(NULL, stbuf.st_size, PROT_READ | PROT_WRITE,		    MAP_SHARED, fd, 0);	if (addr == MAP_FAILED) {		fprintf(stderr, "mmap failed: %m\n");		return 1;	}	if (patch_address) {		size_t len = strlen(string);		if ((patch_address + len) > stbuf.st_size) {			fprintf(stderr, "Patch address is invalid\n");			return 1;		}		if (memcmp(&addr[patch_address], string, len) != 0) {			fprintf(stderr,				"GFXBOOT string not found at patch address\n");			return 1;		}		memset(&addr[patch_address], ' ', len);	} else		print_gfxboot_addr(string, addr, stbuf.st_size);	munmap(addr, stbuf.st_size);	close(fd);	return 0;}