/* elf_fsck.c -- by mort -- http://mortix.net * * A program to change the ELF identification (magic) * field in the program header. * * mad gr33tz to dlab */ #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd; Elf32_Ehdr *keke; if(argc!=3) { printf("Usage: %s \n", argv[0]); return 0; } /* Open file */ fd = open(argv[1], O_RDWR); if(fd < 0) { printf("Error opening file...\nExiting...\n"); return 1; } /* mmap file into memory */ keke = (Elf32_Ehdr *) mmap(0,sizeof(Elf32_Ehdr), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(keke == MAP_FAILED) { printf("Unable to map file...\nExiting...\n"); return 1; } /* Copy over new string */ memcpy(keke->e_ident, argv[2], sizeof(keke->e_ident)); /* Write changes to file */ msync(keke, sizeof(Elf32_Ehdr), MS_SYNC); /* Un-map file */ munmap(keke, sizeof(Elf32_Ehdr)); /* Close file */ close(fd); printf("Done.\n"); return 0; }