Skip to content

Instantly share code, notes, and snippets.

@lambdageek
Created October 23, 2019 15:57
Show Gist options
  • Select an option

  • Save lambdageek/1397cf5f5d4eec83888b88e5f3c8ad79 to your computer and use it in GitHub Desktop.

Select an option

Save lambdageek/1397cf5f5d4eec83888b88e5f3c8ad79 to your computer and use it in GitHub Desktop.

In one terminal run: mono foo.exe In anothr terminal run: kill -TERM [PID]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
foo (void)
{
printf ("Hello\n");
}
void
bar (void)
{
while (1) {
sleep (10);
foo ();
}
}
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
public class Program
{
[DllImport("foo", EntryPoint="bar")]
static extern void bar ();
public static void EnableMERP (string pwd) {
MethodInfo m = typeof (string).Assembly.GetType ("Mono.Runtime").GetMethod ("EnableMicrosoftTelemetry", BindingFlags.NonPublic | BindingFlags.Static);
if (m == null)
throw new Exception ("no meth");
m.Invoke (null, new object[] {"Merp", "Merp", "1.0", pwd, "unused", pwd, pwd + Path.DirectorySeparatorChar} );
}
public static void WhitelistNative () {
MethodInfo m = typeof (string).Assembly.GetType ("Mono.Runtime").GetMethod ("RegisterReportingForAllNativeLibs", BindingFlags.NonPublic | BindingFlags.Static);
if (m == null)
throw new Exception ("no whit");
m.Invoke (null, null);
}
public static void Main ()
{
EnableMERP(Directory.GetCurrentDirectory());
WhitelistNative();
Console.WriteLine ("Ready:");
bar ();
}
}
all: foo.exe
.PHONY: all
libfoo.dylib: foo.c
clang -shared -fpic -o $@ $<
foo.exe: foo.cs libfoo.dylib
csc /target:exe /out:$@ foo.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment