开发者

Change application type with Mono.Cecil?

开发者 https://www.devze.com 2023-04-07 13:15 出处:网络
How can I modify an application from Console App开发者_运维技巧lication Type to Windows Application Type and vice versa with Mono.Cecil?To convert a console .exe to windows .exe, you can use:

How can I modify an application from Console App开发者_运维技巧lication Type to Windows Application Type and vice versa with Mono.Cecil?


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,
}


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
0

精彩评论

暂无评论...
验证码 换一张
取 消