Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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