2

How can I modify an application from Console Application Type to Windows Application Type and vice versa with Mono.Cecil?

  • There's quite a bit of window handling and such that just won't be in a console app. You may be able to change the flags or entrypoint, but you'd have to inject that code somewhere for it to be of any use (and since it'll just have a window and no actual UI, it won't do much). – ssube Sep 23 '11 at 06:43

2 Answers2

2

To convert a console .exe to windows .exe, you can use:

var file = "foo.exe";
var module = ModuleDefinition.ReadModule (file);
// module.Kind was previously ModuleKind.Console
module.Kind = ModuleKind.Windows;
module.Write (file);

The other way around is as simple as choosing the appropriate ModuleKind value. From Cecil's source:

public enum ModuleKind {
    Dll,
    Console,
    Windows,
    NetModule,
}
Jb Evain
  • 17,319
  • 2
  • 67
  • 67
0

For people who needed more help on this like me :)

you may need the apt pacakge libmono-cecil-cil-dev

//mono-cecil-set-modulekind-windows.cs
using System;
using Mono.Cecil;

namespace CecilUtilsApp {
    class CecilUtils {
        static void Main(string[] args) {
            var file = args[0];
            var module = ModuleDefinition.ReadModule (file);
            module.Kind = ModuleKind.Windows;
            module.Write (file);
        }
    }
}

// -----
//Makefile
//mono-cecil-set-modulekind-eq-windows.exe:
//    mcs $(shell pkg-config --libs mono-cecil) ./mono-cecil-set-modulekind-windows.cs
./mono-cecil-set-modulekind-windows.exe myprog.exe
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147