I have a a.out
file from "hello world" in c:
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("hello world\n");
}
Which I can see in hexdump (file a.out
) with command :%!xxd -g1
00000000: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 .ELF............
00000010: 03 00 3e 00 01 00 00 00 50 10 00 00 00 00 00 00 ..>.....P.......
00000020: 40 00 00 00 00 00 00 00 c3 b8 40 00 00 00 00 00 @.........@.....
00000030: 00 00 00 00 00 40 00 38 00 0b 00 40 00 23 00 22 [email protected]...@.#."
00000040: 00 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 .........@......
00000050: 00 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 .@.......@......
00000060: 00 68 02 00 00 00 00 00 00 68 02 00 00 00 00 00 .h.......h......
00000070: 00 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 ................
00000080: 00 c2 a8 02 00 00 00 00 00 00 c2 a8 02 00 00 00 ................
00000090: 00 00 00 c2 a8 02 00 00 00 00 00 00 1c 00 00 00 ................
000000a0: 00 00 00 00 1c 00 00 00 00 00 00 00 01 00 00 00 ................
000000b0: 00 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
...
after seeing the hexdump (not modifying), I will try to revert back haxdump to binary with command :%!xxd -r
. After which the file cannot be run anymore:
$./a.out
bash: ./a.out: cannot execute binary file: Exec format error
I have not made any changes. So did vim saved it with some changes, or why cannot bash recognize the format ELF?
a.out
file usingvim -b
(for "binary")? Vim will potentially mess up with line endings and possibly add a newline to the very end of the file. It might also mess with encodings.-b
should neutralize all that. Check whether it works please?vim -b
—I know it has to do with encodings/line-endings, and it's not enough to set the options appropriately after the file has loaded. It must be done ahead of time, such as using-b
or++bin
options (see:help edit-binary
). See also github.com/benknoble/vim-hex/issues/4