#include #include #include #include #include int main(int argc, char *argv[]) { int fd1, fd2, big_endian = 0; Elf32_Ehdr ehdr; char buf[512]; if (argc != 3) { printf("usage: %s input-file output-file\n", argv[1]); exit(1); } fd1 = open(argv[1], O_RDONLY); if (fd1 < 0) { printf("Error: couldn't open %s\n", argv[1]); exit(1); } if (read(fd1, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) { printf("Error: couldn't read the ELF header\n"); exit(1); } if (ehdr.e_machine != htole16(EM_ARM)) { if (ehdr.e_machine != htobe16(EM_ARM)) { printf("Error: Not an ARM ELF binary.\n"); exit(1); } else big_endian = 1; } else big_endian = 0; if (big_endian) { ehdr.e_flags &= ~htobe32(0x200); /* Remove FPA Soft float */ ehdr.e_flags |= htobe32(0x400); /* VFP Soft Float */ } else { ehdr.e_flags &= ~htole32(0x200); /* Remove FPA Soft float */ ehdr.e_flags |= htole32(0x400); /* VFP Soft Float */ } fd2 = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0755); if (fd2 < 0) { printf("Error: couldn't open %s for writing\n", argv[2]); exit(1); } write(fd2, &ehdr, sizeof(ehdr)); while (read(fd1, buf, sizeof(buf)) > 0) write(fd2, buf, sizeof(buf)); }