build: add support for building tools targeting host machine
This commit is contained in:
37
tools/e64patch/main.c
Normal file
37
tools/e64patch/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user