Blog

Detecting .Net Executables And Choosing Between Mono And Wine

Beeing able to double click, or simply ./app.exe from the console, is always easier that calling Mono or Wine. The Linux Kernel provides a feature that enables developers to hook and make .exe to be recognized and started as an excutable but the current solutions are not compatible between themselves. I tough that doing an application to detect which .exe’s are .NET ones and lauching the correct application to read them would be a nice little project.

I decided to hack it with C++ (with my very poor C/C++ experience) and started to look for information about it. Sadly there is not much, well formatted and organized, data about the subject. There is specially a lack of examples. With the help of some bits of data here and there, and by analysing mono source code, I was able to put it together. I could had simply copy pasted the Mono code but that would be a huge waste of memory, because this library doesn’t really need all that data strutures. In fact, it only needs to read less than 100 bytes from the file, altough its a random read.

I created an application called clrx that checks if a file is a valid .Net file. You can download it here. I say “file” because both .Net EXE and DLL files are validated. After you install it you can simply:

clrx anyfile.exe

And it will tell if it is, or not, a valid .Net file.

To build and install it:

tar -zxf clrx-1.0.tar.gz
cd clrx-1.0
./configure
make
sudo make install

Then you need to copy autoexe and autoexe-setup to /usr/local/bin. Alternatively you can simply uncompress the file, cd to the directory and, as root, execute the “install” script in there. It will do all the steps.

Because I didn’t want to waste time creating configuration files and checking paths, I simply created a script that will invoke clrx and based on the output it will call either Mono or Wine. I called this script autoexe and it can be configured in binfmt_mist with the following command as root:

echo ‘:CLR:M::MZ::/usr/local/bin/autoexe:’ > /proc/sys/fs/binfmt_misc/register

If you currently have the Wine “service” running at boot or is by some other way you are already registering EXE files to either Mono or Wine, you need to undo the respective command and change it to the provided one. To make things easier, there is a autoexe-setup that will do this.

I believe this would be a nice improvement to both Mono and Wine to include this on their releases :)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

10 Responses to “Detecting .Net Executables And Choosing Between Mono And Wine”

  1. knocte says:

    This is very
    interesting. If you open bugs on Wine and Mono to request the inclusion of this, please post the URLs here so as we can track them!

  2. Asbj?.¸rn Ulsberg says:

    This would be a really nice addition to Wine
    and Mono. The Wine and Mono installation process should take care of the configuration bits, so that after a successfully installed Wine or Mono, you should be able to ./app.exe from the command line
    or double-click it, and then clrx should be invoked automatically and then execute the file in the right environment.

    That would be awesome.

  3. alexmipego says:

    Thanks for your support.

    At this time I
    whish to see some more comments and feedback if there are bugs and if someones takes a look at the source to see if I’m too noob at C++.

    Eventually if this gets some good feedback I’ll try
    to include it in the Mono installation process and in Wine too. For some reason I feel that including it in Wine can be a bit difficult since the relationships between the two projects was a bit
    difficult in the past. Anyway, I’m not sure this belongs to either of the projects installations or if it belongs the distributions to package and install.

  4. Ilya Konstantinov says:

    We already have
    such a utility in Debian for a few years now, something which I’ve written originally. Search for binfmt-detector-cli

  5. alexmipego says:

    Thank you for letting me know that. I
    guess this little project is worthless then :) Anyway, it was for the fun. But since most distros I know, Fedora as an example, do not provide this out-the-box, this is useful and easy to setup by
    its users.

  6. j says:

    Great program, I was almost ready to start writing this exact one myself! Now I don’t have to. 😀

    But yes, I hope Mono and WINE include this in their future
    releases.

  7. Julien says:

    If I am remembering well, there were some patches submitted to Wine (wine-patches) to start mono if Wine detected .Net files. Anyway, I am not sure this solution is
    really better.

  8. Mirco Bauer says:

    If you are interested in the source of the BINFMT CLI detector that is used in Debian
    (which is written in C btw) check this out:
    http://svn.debian.org/wsvn/pkg-mono/mono/trunk/debian/detector/binfmt-detector-cli.c?op=file&rev=0&sc=0

  9. Andrew says:

    Hey, this sounds cool, and what I was looking for!

    However, the “download it here” link is dead! :( It links to:

    http://www.alexandre-gomes.com/files/clrx-1.0.tar.gz

    Which simply says “Sorry, but the page you’re trying to view doesn’t exist.” and suggests a Google Search, which shows *2* results, both of which are your (this) web page!

    Please let me know if/where I can get this code/program! Thanks!

    (BTW – also the link Mirco gives does not show any code – I suspect that the tree referred to has changed such that that particular file has probably had it’s code incorporated into another file on the tree, but on idea which/where!)

  10. alexmipego says:

    Sorry, I think I lost track of the file between one of several migrations :(

Leave a Reply

For spam filtering purposes, please copy the number 9890 to the field below: