Skip to content

Instantly share code, notes, and snippets.

@fifty-six
Created February 17, 2022 06:42
Show Gist options
  • Save fifty-six/f0ec6780eb4646c089feab5bd7c02d98 to your computer and use it in GitHub Desktop.
Save fifty-six/f0ec6780eb4646c089feab5bd7c02d98 to your computer and use it in GitHub Desktop.
using System.Runtime.CompilerServices;
#pragma warning disable CS8604
#pragma warning disable CS8600
C local = null;
if (local != null && local.Prop)
{
Console.WriteLine(local.ToString());
}
class C
{
private int _h;
public bool Prop
{
get
{
unsafe
{
fixed (int* iptr = &_h)
{
var i = (nuint*) iptr;
// Kill the vtable
*(i - 1) = 0;
// Kill the object header too
*(i - 2) = 0;
}
}
return true;
}
}
public static bool operator !=(in C a, in C _)
{
Unsafe.AsRef(a) = new C();
return true;
}
public static bool operator ==(C a, C b) => throw new NotImplementedException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment