macropas
macropas

Reputation: 3160

Using Mono to recognize executable files in Linux?

Can we recognize which file is executable (i.e. chmod +x) using Mono under Linux? Is there any method in common .Net/Mono base class libraries?

Edit: native Linux executables

Upvotes: 1

Views: 1215

Answers (3)

Noldorin
Noldorin

Reputation: 147240

The best you can do is use the Mono.Unix.Native namespace to check file permissions, I believe. You can check whether a file has executable permissions (for owner/group/others) by calling the Syscall.Stat method. More specifically, you'll want to look into the FilePermissions enum.

Upvotes: 4

Rytmis
Rytmis

Reputation: 32037

Yes, we can, but I don't know of a common .NET class that does it. You could look at the mono sources. :)

Edit:

The original link refers to a helper application, which can't be found. However, the Mono Project page has something to say about binfmt support too, and no helper app seems to be required.

Upvotes: 1

OregonGhost
OregonGhost

Reputation: 23759

Though it's not exactly a method to find .NET executables, you can load the assembly with Assembly.Load. If it fails, it's not a .NET assembly.

Upvotes: 0

Related Questions