Ivo@2: /* To compile, you may have to specify: Ivo@2: * The include paths for mono: -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ Ivo@2: * The location of the VBoxXPCOMC.so library: /usr/lib/virtualbox/VBoxXPCOMC.so Ivo@2: * The location of the mono library (if an alternative build is to be used): /home/ivo/mono/devtest/lib/libmono-2.0.so Ivo@2: * To link against the mono library (if the system wide installed version is to be used): -lmono Ivo@2: * Where to look for the VBoxXPCOMC.so library at run time: -Wl,-R,/usr/lib/virtualbox Ivo@2: * Where to look for the mono library at run time (if non-standard): -R,/home/ivo/mono/devtest/lib/ Ivo@2: * Ivo@2: * The resulting commandline may look like this: Ivo@2: gcc VBoxMono.c -o VBoxMono -lmono \ Ivo@2: -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ \ Ivo@2: /usr/lib/virtualbox/VBoxXPCOMC.so -Wl,-R,/usr/lib/virtualbox Ivo@2: * The resulting commandline may look like this if mono is installed in an alternative location: Ivo@2: gcc VBoxMono.c -o VBoxMono \ Ivo@2: -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ \ Ivo@2: /usr/lib/virtualbox/VBoxXPCOMC.so -Wl,-R,/usr/lib/virtualbox \ Ivo@2: /home/ivo/mono/devtest/lib/libmono-2.0.so -Wl,-R,/home/ivo/mono/devtest/lib/ Ivo@2: * Then make the binary owned by root and set the suid bit: Ivo@2: sudo chown root VBoxMono Ivo@2: sudo chmod u+s VBoxMono Ivo@2: */ Ivo@2: Ivo@2: #include Ivo@2: #include Ivo@2: #include Ivo@2: #include Ivo@2: #include Ivo@2: #include Ivo@2: Ivo@2: extern int RTR3InitAndSUPLib(); Ivo@2: Ivo@2: int main(int argc, char *argv[]) { Ivo@2: if (argc < 2) { Ivo@2: fprintf(stderr, "VBoxMono: Usage: %s assembly.exe\n", argv[0]); Ivo@2: return 1; Ivo@2: } Ivo@2: int rc = RTR3InitAndSUPLib(); Ivo@2: if (rc != 0) { Ivo@2: fprintf(stderr, "VBoxMono: Could not initialize VirtualBox driver (%d)\n", rc); Ivo@2: return rc; Ivo@2: } Ivo@2: int gid = getuid(); Ivo@2: if (gid != getegid()) setregid(gid, gid); Ivo@2: int uid = getuid(); Ivo@2: if (uid != geteuid()) setreuid(uid, uid); Ivo@2: mono_config_parse(NULL); Ivo@2: //mono_set_dirs("/home/ivo/mono/devtest/lib", "/etc"); Ivo@2: MonoDomain *domain = mono_jit_init_version("VirtualBox", "v2.0.50727"); Ivo@2: if (!domain) { Ivo@2: fprintf(stderr, "VBoxMono: Could not create application domain\n"); Ivo@2: return 1; Ivo@2: } Ivo@2: MonoAssembly *assembly = mono_domain_assembly_open(domain, argv[1]); Ivo@2: if (!assembly) { Ivo@2: fprintf(stderr, "VBoxMono: Could not load assembly %s\n", argv[1]); Ivo@2: mono_jit_cleanup(domain); Ivo@2: return 1; Ivo@2: } Ivo@2: int ret = mono_jit_exec(domain, assembly, argc - 1, argv + 1); Ivo@2: mono_jit_cleanup(domain); Ivo@2: return ret; Ivo@2: }