w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Determine whether a file is a binary executable file or a script file using gcc in Linux

You can check so-called magic bytes. For elf 1st four bytes are supposed to be 7f 45 4c 46 in hex. You have to care for byte order though.

Opening file in binary mode and reading 1st four bytes should suffice.

E.g.

shell$ hexdump -n 10 ./ni6_ga
0000000 457f 464c 0101 0301 0000




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.