Solved

Identifying Binaries/Executables on GNU Linux/UNIX

Posted on 2006-11-30
4
292 Views
Last Modified: 2010-04-15
Is there a way, perhaps using a stat struct with fstat, to identify whether a certain file is an executable binary?  I looked over the fstat man pages, and it says you can identify the files permissions, or whether it's a directory, but I can't see anything to tell whether it's an executable.  
0
Comment
Question by:chsalvia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 125 total points
ID: 18044529
Hi chsalvia,

Look into source code of file command ... They use some heuristics such as magic number to determine file type ...
http://www.die.net/doc/linux/man/man1/file.1.html

Cheers!
sunnycoder
0
 
LVL 22

Expert Comment

by:grg99
ID: 18045332
Do you mean:

(1)  Does the file have executable permissions for user X?

(2)  Is the file in a format this OS can load and execute?

(3)  #2 and are its prerequisite shared libraries around?

(4) #3 are the aforementioned libraries the right versions for this executable?

(5) #4 and are the config and other  files for this executable in the right places?

(6) #5 and are there enough system resources available to user X to run the program?


All very different questions, and they get harder and harder to verify as you go down the list.



0
 

Author Comment

by:chsalvia
ID: 18048603
grg, I meant number 2 on the list.  Is the file in a format the OS can load and execute.
0
 
LVL 22

Accepted Solution

by:
grg99 earned 125 total points
ID: 18048820
okay, you can determine the file format either by using the "file" command, or peeking at the first few bytes of the file.

Search the internet for "a.out file format" which will describe the several magic numbers an a.out format file can have.

Also on Linux most binaries are in ELF format, search for "ELF executable format" for the magic numbers in these files.

Some Unix systems use COFF format, that has its own distinctive header magic words.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question