#include #include #include #include #include #include #include #include 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; }