Skip to content

Instantly share code, notes, and snippets.

View michel-pi's full-sized avatar

Michel michel-pi

View GitHub Profile
@michel-pi
michel-pi / FakeObjectFactory.cs
Created October 21, 2023 11:59
Mimicking .NET objects in memory.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Snippets
{
/// <summary>
/// Mimicking .NET objects in memory.
/// </summary>
/// <remarks>
@michel-pi
michel-pi / WorkerThreadDispatcher.cs
Created October 15, 2023 13:57
Provides services for managing the queue of work items for a thread.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Snippets.Threading
{
/// <summary>
/// Provides services for managing the queue of work items for a thread.
/// </summary>
@michel-pi
michel-pi / WorkerThread.cs
Last active October 15, 2023 11:41
Best practise thread start, stop, pause, resume and join.
/*
* Best practise thread start, stop, pause, resume and join.
* Example code at the end of the file.
*/
using System;
using System.Globalization;
using System.Threading;
namespace Snippets.Threading
@michel-pi
michel-pi / PackedInteger.cs
Last active July 17, 2023 20:48
Packing integers
using System;
using System.Runtime.InteropServices;
namespace Data
{
[StructLayout(LayoutKind.Explicit, Pack = 1)]
public struct PackedInteger
{
/*
* Use cases:
@michel-pi
michel-pi / MessageBox.cs
Created June 20, 2021 21:48
Using NtRaiseHardError to display a MessageBox
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Undocumented.Windows
{
public static unsafe class MessageBox
{
// http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FError%2FNtRaiseHardError.html
private static readonly delegate* unmanaged[Stdcall]<uint, uint, uint, uint*, uint, uint*, uint> _ntRaiseHardError;
@michel-pi
michel-pi / FriendCode.cs
Created June 13, 2021 16:50
Generates friend codes for csgo or turns them into steam id's
using System;
using System.Buffers.Binary;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace Csgo
{
public static class FriendCode
{
https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2019
https://marketplace.visualstudio.com/items?itemName=SteveCadwallader.CodeMaid
https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler
https://marketplace.visualstudio.com/items?itemName=MichaelKissBG8.Supercharger
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileIcons
https://marketplace.visualstudio.com/items?itemName=EWoodruff.VisualStudioSpellCheckerVS2017andLater
https://marketplace.visualstudio.com/items?itemName=NikolayBalakin.Outputenhancer
https://marketplace.visualstudio.com/items?itemName=ironcev.sharpen
@michel-pi
michel-pi / open-recyclebin.cmd
Created January 11, 2021 23:17
opens the recycle bin in a new windows explorer window
@echo off
start shell:RecycleBinFolder
exit
@michel-pi
michel-pi / cloudflare-dns.cmd
Created January 11, 2021 23:16
set cloudflare dns server with console
@echo off
netsh interface ipv4 set dnsservers name="Ethernet" validate=no static 1.1.1.1 primary > nul
netsh interface ipv4 add dnsservers name="Ethernet" validate=no 1.0.0.1 index=2 > nul
netsh interface ipv6 set dnsservers name="Ethernet" validate=no static 2606:4700:4700::1111 primary > nul
netsh interface ipv6 add dnsservers name="Ethernet" validate=no 2606:4700:4700::1001 index=2 > nul
ipconfig /flushdns > nul
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
namespace ProcessMemoryTest.Native
{
[SuppressUnmanagedCodeSecurity]
public static unsafe class Kernel32
{