Skip to content

Instantly share code, notes, and snippets.

View smourier's full-sized avatar

Simon Mourier smourier

View GitHub Profile
@smourier
smourier / nvmldxgi.cpp
Created September 17, 2024 16:34
dump DXGI & NVML PCI bus information
#include <windows.h>
#include <dxgi.h>
#include <D3dkmthk.h>
#include <stdio.h>
#include "nvml\include\nvml.h"
#pragma comment(lib, "nvml\\lib\\nvml.lib")
#pragma comment(lib, "dxgi.lib")
@smourier
smourier / OnDemandDataObject.cs
Created August 31, 2024 13:27
On-Demand IDataObject
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
namespace OnDemandDataObject;
@smourier
smourier / PrivateUwpRegistry.cpp
Created August 24, 2024 12:40
Update some (here photos) app's registry from outside the app itself.
#include <windows.h>
#include <userenv.h>
#include <atlbase.h>
#include <stdio.h>
#include <shlobj.h>
#include <string>
#pragma comment(lib, "userenv")
@smourier
smourier / ReadHeicFileThroughGdiPlusAndWic.cs
Created August 18, 2024 18:39
Use WIC component with GDI+ (version 3)
var hr = GdiplusStartup(out var token, StartupInputEx.GetDefault(), out var output);
using var img = new Bitmap(Environment.GetCommandLineArgs()[1]);
[DllImport("gdiplus")]
private static extern int GdiplusStartup(out nint token, in StartupInputEx input, out StartupOutput output);
private struct StartupInputEx
{
public int GdiplusVersion;
public nint DebugEventCallback;
@smourier
smourier / AuthenticodeSignature.cs
Created August 1, 2024 16:27
A C# utility to decode all authenticode signatures (primary and secondaries)
public class AuthenticodeSignature
{
private AuthenticodeSignature() { }
public int Index { get; private set; }
public string ProgramName { get; private set; }
public string PublisherLink { get; private set; }
public string MoreLink { get; private set; }
public string SerialNumber { get; private set; }
public X509Certificate2 Certificate { get; private set; }
public string HashAlgorithm { get; private set; }
@smourier
smourier / CreateWindowAndSwapChainCsWin32.cs
Created July 29, 2024 05:39
Create Window and Swapchain with CsWin32
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Microsoft.Win32.SafeHandles;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Direct3D;
using Windows.Win32.Graphics.Direct3D11;
using Windows.Win32.Graphics.Dxgi;
using Windows.Win32.Graphics.Dxgi.Common;
@smourier
smourier / mallocspy.cs
Created April 10, 2024 12:55
C# implementation of IMallocSpy
public class ConsoleMallocSpy : MallocSpy
{
protected override void Log(object message, [CallerMemberName] string methodName = null) => Console.WriteLine(methodName + ": " + message);
private readonly ConcurrentDictionary<IntPtr, IntPtr> _blocks = new();
private IntPtr _allocRequest;
protected override IntPtr PreAlloc(IntPtr cbRequest)
{
@smourier
smourier / JobObject.cs
Created February 26, 2024 16:13
JobObject C# class with wait, support for ShellExecute, etc.
public class JobObject : IDisposable
{
private IntPtr _handle;
public JobObject(string name = null, bool terminateOnDispose = false)
{
Name = name;
TerminateOnDispose = terminateOnDispose;
_handle = CreateJobObject(IntPtr.Zero, name);
if (_handle == IntPtr.Zero)
@smourier
smourier / LoadNonloadedOverlayIdentifiers.cs
Last active February 3, 2024 10:40
Load Nonloaded Overlay Identifiers
[STAThread]
static void Main()
{
var mgr = (IShellIconOverlayManager)new CLSID_CFSIconOverlayManager();
Console.WriteLine(mgr.LoadNonloadedOverlayIdentifiers());
}
[ComImport, Guid("63B51F81-C868-11D0-999C-00C04FD655E1")]
public class CLSID_CFSIconOverlayManager { };
@smourier
smourier / SvgToPng
Created February 3, 2024 10:08
Converting SVG to PNG using WIC & Direct2D (through Wicnet & DirectN)
using System.Drawing;
using System.IO;
using DirectN;
using WicNet;
namespace ConsoleApp2
{
internal class Program
{
static void Main()