Skip to content

Instantly share code, notes, and snippets.

#include <objbase.h>
#include <relogger.h>
#include <tdh.h>
#include <evntcons.h>
#include <strsafe.h>
#include <DbgHelp.h>
#include <unordered_set>
#include <unordered_map>
struct CV_INFO_PDB70
@mjsabby
mjsabby / ExtractETLEventsByTime.cpp
Created February 14, 2019 05:13
Extracts ETL events by time
#include <Windows.h>
#include <evntcons.h>
#include <relogger.h>
#include <string>
#include <atomic>
constexpr UCHAR DCStart = 3;
constexpr UCHAR DCStop = 4;
constexpr UCHAR LoadVerbose = 143;
@mjsabby
mjsabby / ParallelXxHash32.cs
Last active August 15, 2023 04:59
Parallel XxHash32 in C# using AVX2
namespace ParallelXxHash32
{
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using static Extensions;
@mjsabby
mjsabby / PerfectHash.cs
Created February 12, 2023 10:22
Hash Displace Algorithm
namespace PerfectHash
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Numerics.BitOperations;
public static class PerfectHash
{
#include <Windows.h>
#include <DbgEng.h>
#include <DbgHelp.h>
#include <cstdio>
#include <string>
#include <vector>
template <typename T, ULONG N> constexpr ULONG countOf(T const (&)[N]) noexcept { return N; }
#define addr(x) &x[0]
#define IfFailCleanup(EXPR) do { hr = (EXPR); if(FAILED(hr)) { goto cleanup; } } while (0)
@mjsabby
mjsabby / DumpAzureDevOpsAuditLogs.cs
Created October 23, 2023 19:36
Dump Azure DevOps Audit Logs
/*
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.3" />
</ItemGroup>
@mjsabby
mjsabby / Program.cs
Created February 7, 2024 21:42
Certificate Auto Updater
namespace CertificateUpdater
{
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
@mjsabby
mjsabby / CertificateUpdater.cs
Created April 10, 2024 03:26
C# program that implements ACME protocol to get certificates from Let's Encrypt using DNS Challenge for Cloudflare
/*
Example appsettings.json
{
"AzureManagedIdentityClientId": "YOURGUID",
"AzureKeyVaultAADScope": "https://vault.azure.net",
"AzureKeyVaultUrl": "https://YOURAKV.vault.azure.net/",
"AzureKeyVaultCertificateSecret": "akv_secret_for_cert",
"AzureKeyVaultCloudeflareApiKeySecret": "akv_secret_forcloudflareapikey",
@mjsabby
mjsabby / VerifyRS256JWTSignature.cs
Last active April 29, 2024 05:42
Verify RS256 using more primitive operations to find where time is spent
// <PackageReference Include="SymCryptNative" Version="103.4.2" />
// <PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
namespace VerifyRS256JWTSignature
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
@mjsabby
mjsabby / UpdateADODefaultBranch.cs
Created May 29, 2024 19:34
Update ADO default branch
namespace UpdateDefaultBranch
{
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;