Skip to content

Instantly share code, notes, and snippets.

@hypeartist
hypeartist / log
Created September 22, 2019 18:56
JitDump output
****** START compiling Test2:DoTest(int,int,ubyte):int (MethodHash=8bafdb7c)
Generating code for Windows x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = false
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC = false
OPTIONS: compProcedureSplitting = false
OPTIONS: compProcedureSplittingEH = false
IL to import:
IL_0000 02 ldarg.0
@hypeartist
hypeartist / JitDump
Created September 23, 2019 11:40
JitDump
This file has been truncated, but you can view the full file.
****** START compiling Test1:TestMethodAll(struct,ubyte,ubyte,ubyte,ubyte,ubyte) (MethodHash=f166d70a)
Generating code for Windows x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = false
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC = false
OPTIONS: compProcedureSplitting = false
OPTIONS: compProcedureSplittingEH = false
IL to import:
IL_0000 12 00 ldloca.s 0x0
@hypeartist
hypeartist / gist:19124f0e1e2214f37223df87d9f7a981
Created January 10, 2020 19:56
.NET Core 3.1, IndexOf(char)
internal static unsafe class Intrinsics
{
private static ReadOnlySpan<byte> TrailingZeroCountDeBruijnTable => new byte[]
{
00, 01, 28, 02, 29, 14, 24, 03,
30, 22, 20, 15, 25, 17, 04, 08,
31, 27, 13, 23, 21, 19, 16, 07,
26, 12, 18, 06, 11, 05, 10, 09
};
@hypeartist
hypeartist / gist:4bef9b02f98ebbe8c5af9668de05f1fb
Created January 10, 2020 20:12
.NET Core 3.1, IndexOf(char) test case
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
DoTest();
}
@hypeartist
hypeartist / trick.cs
Created February 7, 2020 22:29
CoreClrImageBase
namespace ConsoleApp1
{
internal static class Program
{
private static unsafe void Main(string[] args)
{
var tp = new ThreadPrivateAccessor {Thread = Thread.CurrentThread};
var currentThreadHandle = (void**)tp.ThreadExposer._DONT_USE_InternalThread;
var someProcFromCoreClr = *currentThreadHandle;
var coreClrImageBase = (byte*)someProcFromCoreClr - 0x3ec4c0;
@hypeartist
hypeartist / trick.cs
Last active June 6, 2020 18:33
.net core digging
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
namespace ConsoleApp1
{
internal static class Program
{
@hypeartist
hypeartist / PInvoke trick?
Last active May 13, 2022 15:06
P/Invoke trick?
static class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
static void Main()
{
@hypeartist
hypeartist / Simd
Last active May 23, 2020 22:52
SimdQ
public unsafe struct PixelInfo
{
public const int Shift = 8;
public const int Scale = 1 << Shift;
public const int Mask = Scale - 1;
public const int Msb = 1 << (Shift - 1);
public struct Cover
{
public const int Shift = 8;
@hypeartist
hypeartist / gist:d52ef1196e2f19a7b36367d95a123c3a
Created June 6, 2020 17:58
Get PEB64 without using P/Invoke
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
namespace ConsoleApp1
{
unsafe class Program
{
static void Main(string[] args)
[StructLayout(LayoutKind.Sequential, Size = 256)]
public unsafe struct Bitset
{
public void Set(int bitIndex) => ((int*) Unsafe.AsPointer(ref Unsafe.AsRef(this)))[(bitIndex & ~7) >> 5] |= 1 << (bitIndex & 7);
public void Unset(int bitIndex) => ((int*)Unsafe.AsPointer(ref Unsafe.AsRef(this)))[(bitIndex & ~7) >> 5] ^= 1 << (bitIndex & 7);
public void SetAll() => Unsafe.InitBlock(Unsafe.AsPointer(ref Unsafe.AsRef(this)), 0xff, (uint) Unsafe.SizeOf<Bitset>());
public void UnsetAll() => Unsafe.InitBlock(Unsafe.AsPointer(ref Unsafe.AsRef(this)), 0x00, (uint) Unsafe.SizeOf<Bitset>());
}