38 lines
638 B
C
38 lines
638 B
C
#include <stdio.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
#include "elf.h"
|
|
|
|
int main(int argc, const char **argv)
|
|
{
|
|
if (argc < 2) {
|
|
fprintf(stderr, "no elf file specified.\n");
|
|
return -1;
|
|
}
|
|
|
|
unsigned long pagesz = sysconf(_SC_PAGESIZE);
|
|
|
|
FILE *fp = fopen(argv[1], "r+b");
|
|
if (!fp) {
|
|
perror(argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
void *p = mmap(NULL, pagesz, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(fp), 0);
|
|
if (p == MAP_FAILED) {
|
|
perror("mmap");
|
|
fclose(fp);
|
|
return -1;
|
|
}
|
|
|
|
elf_ehdr_t *elf = p;
|
|
elf->e_machine = EM_386;
|
|
|
|
munmap(p, pagesz);
|
|
fclose(fp);
|
|
|
|
printf("patched %s e_machine to EM_386\n", argv[1]);
|
|
|
|
return 0;
|
|
}
|