Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » FindFile::IsExecutable() [Feature request]
FindFile::IsExecutable() [Feature request] [message #25685] Sun, 07 March 2010 21:51 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hello,
Would it be possible to add IsExecutable() method to FindFile? Implementation is quite simple, for Linux:
bool FindFile::IsExecutable() const { return (!IsDirectory()) && ((S_IXUSR|S_IXGRP|S_IXOTH) & GetMode());}
And for windows (this could be optimized):
bool FindFile::IsExecutable() const { return ToLower(GetName()).EndsWith(".exe"); }

What do you think?

Best regards,
Honza
Re: FindFile::IsExecutable() [Feature request] [message #25698 is a reply to message #25685] Mon, 08 March 2010 16:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Sun, 07 March 2010 15:51

Hello,
Would it be possible to add IsExecutable() method to FindFile? Implementation is quite simple, for Linux:
bool FindFile::IsExecutable() const { return (!IsDirectory()) && ((S_IXUSR|S_IXGRP|S_IXOTH) & GetMode());}
And for windows (this could be optimized):
bool FindFile::IsExecutable() const { return ToLower(GetName()).EndsWith(".exe"); }

What do you think?

Best regards,
Honza


What about directory with .exe extension in Windows? Smile

Mirek
Re: FindFile::IsExecutable() [Feature request] [message #25712 is a reply to message #25698] Tue, 09 March 2010 08:17 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Mon, 08 March 2010 16:55

What about directory with .exe extension in Windows? Smile

Mirek

Hi Mirek,
You got me Smile Actually I was hoping that someone who actually knows Windows will write better version using win API...

Now, after I gave it a bit more thinking I think the proper way would be reading PATHEXT environment variable and compare it to the extension of files. On Win98 (if you want to support it) fixed list with .exe and .com should be used. What do you think about this? It is slow, but probably not as slow as opening the file and determining the executability from its contents.

Another solution would be omit this method on Windows the same way as some methods are omitted on Linux because the are not well defined (IsArchive,IsCompressed,...).

Best regards,
Honza
Re: FindFile::IsExecutable() [Feature request] [message #25715 is a reply to message #25712] Tue, 09 March 2010 08:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Nah, I have just added the test for directory...

Mirek
Re: FindFile::IsExecutable() [Feature request] [message #25719 is a reply to message #25715] Tue, 09 March 2010 11:14 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

This is hard question because actually you may execute ANY file in Windows. You may rename your .exe into something like *.scr or even *.abcxyz and execute it with CreateProcess() - and it will work. There is no way to restrict using any file as executable.
So, what question you really want to answer on Windows? Is the file executable? Answer is: any file is executable.
Executable from Explorer? Then, the list from PATHEXT is not enough. There are still more executable types which are registered by Windows but not mentioned in any variables (like .scr which is heavily used by viruses).

[Updated on: Tue, 09 March 2010 11:15]

Report message to a moderator

Re: FindFile::IsExecutable() [Feature request] [message #25720 is a reply to message #25719] Tue, 09 March 2010 11:39 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello all

Perhaps the simplest and most general way to detect an executable file in Windows is the "MZ" (0x4d, 0x5a) magic number in the first two bytes.

Now there are more complex formats but all of them have an MZ in the beginning.

I think the IsExecutable() in windows would work like this:

1. Check file extension (.exe, .scr, .com, ...¿?)
2. Check MZ signature


Best regards
Iñaki
Re: FindFile::IsExecutable() [Feature request] [message #25726 is a reply to message #25685] Tue, 09 March 2010 12:08 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

Mirek:
Thank you, that is enough for me...

Mindtraveller:
Yes, PATHEXT contains extensions that can be executed from console. In some sense you could even call any file executable, if it has extension associated with some program (as there is no difference visible in some cases, e.g. opening file.py in python.exe). But for practical use, .exe is probably enough...

Koldo:
Checking the magic number is probably the safest (and slowest) method. Also I read somewhere that even "ZM" should work and some executables could even start with "PE".

Anyway, I'm happy now, whatever on top of this is just bonus Smile

Honza
Re: FindFile::IsExecutable() [Feature request] [message #25728 is a reply to message #25726] Tue, 09 March 2010 13:22 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Honza

This is true:
Quote:

Checking the magic number is probably the safest (and slowest) method. Also I read somewhere that even "ZM" should work


This is uncertain Smile :
Quote:

and some executables could even start with "PE".


The "PE" chars are inside the header but not in the beginning. In this case "MZ" will be also in the beginning of the file.


Best regards
Iñaki
Re: FindFile::IsExecutable() [Feature request] [message #25741 is a reply to message #25728] Wed, 10 March 2010 09:00 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Tue, 09 March 2010 07:22

Hello Honza

This is true:
Quote:

Checking the magic number is probably the safest (and slowest) method. Also I read somewhere that even "ZM" should work


This is uncertain Smile :
Quote:

and some executables could even start with "PE".


The "PE" chars are inside the header but not in the beginning. In this case "MZ" will be also in the beginning of the file.


As for this... Windows Shell will use "executable" icon for the file as soon as it has '.exe' extensions and tries to execute it on double-click. So what Windows Shell considers good practice is a good practice for me as well... Smile

Mirek
Previous Topic: Format(Time time, bool seconds) problem
Next Topic: CParser enhancements
Goto Forum:
  


Current Time: Thu Apr 25 21:49:19 CEST 2024

Total time taken to generate the page: 0.04507 seconds