Solved

executable file

Posted on 1998-11-05
6
185 Views
Last Modified: 2010-04-15
In a C program, How it is possible to know that a particular file is executable?
0
Comment
Question by:navin_agrawal
6 Comments
 
LVL 1

Expert Comment

by:MatthewL
ID: 1254063
Are you just interested in the actual file name or the file structure?

if filename then you could use command line arguments since the first argument is the filename.  Then you could use strtok or strstr to point to the "." and pull in the extension.

if structure, then my reference says that the first word of an executable file should be EXE program identifier.  It lists this value as being 5A4DH.  It's not clear to me if this is a sample value or always the case.

Matt
0
 
LVL 10

Expert Comment

by:rbr
ID: 1254064
It depends on your OS. Which OS do you use?
0
 
LVL 4

Expert Comment

by:siabod
ID: 1254065
That's always the case for a EXE
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:navin_agrawal
ID: 1254066
Let me be specific in telling the things. Following assumptions are made:

OS: Unix
File Name: /usr/home/stc/friend
Language: C

main ()
{
      char file_name[][] = "/usr/home/stc/friend"

      Here I want to know whether the file in file_name variable is executable or not. How to do this?
} /* end of mail () */
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1254067
You'll have more luck posting in the UNIX Programming topic area.
0
 
LVL 10

Accepted Solution

by:
rbr earned 100 total points
ID: 1254068
#include <sys/stat.h>
#include <unistd.h>
main ()
{
char file_name[]="/usr/home/stc/friend"

struct stat stat_buf;

stat (file_name,&stat_buf);

if (stat_buf.st_mode & S_IXUSR)
printf ("Execute by user");
if (stat_buf.st_mode & S_IXGRP)
printf ("Execute by group");
if (stat_buf.st_mode & S_IXOTH)
printf ("Execute by others");
}

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now