Skip to content

Instantly share code, notes, and snippets.

View MagicAndre1981's full-sized avatar
💭
I may be slow to respond for the next weeks

MagicAndre1981

💭
I may be slow to respond for the next weeks
View GitHub Profile
public static DbTransaction CreateWriteTransaction(this System.Data.Entity.Database self)
{
DbTransaction ret;
self.Connection.Open();
if (self.Connection is FbConnection)
{
FbTransactionOptions options = new FbTransactionOptions() { TransactionBehavior = FbTransactionBehavior.Write | FbTransactionBehavior.ReadCommitted | FbTransactionBehavior.NoRecVersion | FbTransactionBehavior.Wait };
ret = ((FbConnection)self.Connection).BeginTransaction(options);
}
else
@mattifestation
mattifestation / autodump_powershell_process.ps1
Last active September 16, 2019 04:58
Automatically capture a full PowerShell memory dump upon any PowerShell host process termination
$EventFilterArgs = @{
EventNamespace = 'root/cimv2'
Name = 'PowerShellProcessStarted'
Query = 'SELECT FileName, ProcessID FROM Win32_ModuleLoadTrace WHERE FileName LIKE "%System.Management.Automation%.dll"'
QueryLanguage = 'WQL'
}
$Filter = New-CimInstance -Namespace root/subscription -ClassName __EventFilter -Property $EventFilterArgs
$CommandLineConsumerArgs = @{
@AArnott
AArnott / EnumerableCache.cs
Created May 26, 2009 23:09
Get the benefit of deferred execution from generator methods without the cost of multiple generation when enumerated twice
//-----------------------------------------------------------------------
// <copyright file="EnumerableCache.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// This code is released under the Microsoft Public License (Ms-PL).
// </copyright>
//-----------------------------------------------------------------------
namespace IEnumeratorCache {
using System;
using System.Collections;
@axelheer
axelheer / FakeDbSet.cs
Created February 27, 2015 18:54
Fake implementation of Entity Framework's DbSet for fast unit testing
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServer;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@EtherZa
EtherZa / RetargetFramework.cs
Last active July 5, 2021 09:14
Visual Commander script to retarget all loaded Visual Studio projects to a specified .net version (TargetFramework).
// Retarget all loaded projects to the .net version specified in "TargetFramework"
// Execute with Visual Commander (https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander)
// **********************************************************
// NOTE: NuGet packages need to be reinstalled post execution
// **********************************************************
using EnvDTE;
using EnvDTE80;
using System.Collections.Generic;
@goldshtn
goldshtn / analyze.py
Created March 4, 2017 15:22
.NET Core on Linux LLDB analysis scripts
#!/usr/bin/env python
#
# analyze.py Example of an LLDB script that loads SOS and runs a command
# for analysis of a .NET Core application on Linux/macOS.
# Requires LLDB matching the version of libsosplugin.so for your
# CoreCLR version, and gdb.
#
# USAGE: analyze.py [--memory] [--stacks] COREFILE
#
# NOTE: To run this as stand-alone, you might need to fix some bad symlinks
@Zhentar
Zhentar / EtwStackCaching.md
Last active October 3, 2021 16:06
Unlocking the secrets of ETW: Stack Caching

ETW Stack Caching

"Stack Caching" (or Stack Compression as PerfView calls it) is a feature of ETW designed to reduce trace buffer & etl file sizes by de-duplicating stack traces. Naturally, as an ETW feature it is documented solely through obtuse (likely accidental) references and hints in Microsoft tooling. And so the documentation is left to stubborn reverse engineers dedicated ETW enthusiasts such as myself.

The Windows version studied for this was Windows 10 1809 64-bit. I do not think this feature has changed significantly since its introduction, but I have not verified that.

Basics

In trace buffers, the compressed stacks are emitted with the Stackwalk task guid, like regular stackwalks, but with opcodes for events (as labeled by WPA) like "Stack Walk: Delete Definition" and "Stack Walk: Reference [User]". "Reference" entries contain a 'StackKey' value that uniquely identifies a stack trace definition. "Stack Walk: Delete Definition" is logged when cached stacks are evicted; from the MOF def

@mattifestation
mattifestation / wmi_provider_association.ps1
Last active August 16, 2022 05:14
Enumerates WMI providers, the DLLs that back the provider, and the classes hosted by the provider.
<#
Author: Matthew Graeber (@mattifestation)
License: BSD 3-Clause
#>
function Get-WmiNamespace {
[OutputType([String])]
Param (
[String]
[ValidateNotNullOrEmpty()]
#include <windows.h>
void SetWindowBlur(HWND hWnd)
{
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
if (hModule)
{
@OlegKarasik
OlegKarasik / Demo.cs
Last active January 30, 2023 14:35
Code Tip: How to work with asynchronous event handlers in C#?
public class Demo
{
public event EventHandler DemoEvent;
public void Raise()
{
this.DemoEvent?.NaiveRaiseAsync(this, EventArgs.Empty).GetAwaiter().GetResult();
Console.WriteLine("All handlers have been executed!");
}
}