Skip to content

Instantly share code, notes, and snippets.

@xoofx
Created June 6, 2017 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoofx/f5929b24e28118d8bb63215fe4659b21 to your computer and use it in GitHub Desktop.
Save xoofx/f5929b24e28118d8bb63215fe4659b21 to your computer and use it in GitHub Desktop.
Proof of concept of (un)safe code breaking https://unbreakable-test.azurewebsites.net/
// proof of concept for breaking https://unbreakable-test.azurewebsites.net/
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
static class Program {
[MethodImpl(MethodImplOptions.NoInlining)]
public static void MethodToPatch()
{
}
static int Run() {
var method = typeof(Program).GetMethod("MethodToPatch");
var methodHandle = method.MethodHandle;
RuntimeHelpers.PrepareMethod(methodHandle);
var functionPtr = methodHandle.GetFunctionPointer();
Marshal.WriteByte(functionPtr, 0xCC);
MethodToPatch();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment