Instantly share code, notes, and snippets.

View AllocUmm.cs
public static unsafe class AllocUmm
{
[Flags]
public enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
View MemoryInfo.cs
public class MemoryInfo
{
[Flags]
public enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
View StripHTMLAll.cs
public static string StripHTMLAll(string source)
{
try
{
string result;
result = source.Replace("\r", " ");
result = result.Replace("\n", " ");
result = result.Replace("\t", " ");
result = Regex.Replace(result, @"( )+", " ", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"<( )*head([^>])*>", "<head>", RegexOptions.IgnoreCase);
View ResizeEx.cs
public class ResizeEx
{
/// <summary>
/// Resizes a one-dimensional array to the specified new size.
/// </summary>
public static void Resize<T>(ref T[] array, int newSize)
{
if(newSize <= 0)
throw new ArgumentOutOfRangeException($@"New Size {newSize} must be greater than 0.");
if(array == null)
View KvPair.cs
[Serializable]
public class KvPair<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
{
public KvPair(T1 key, T2 value)
{
Key = key;
Value = value;
}
public T1 Key {get;}
public T2 Value{get;}
View CopyFileEx.cs
public bool CopyFileEx(string sourceFile, string targetFile)
{
long bytesLeft = 0;
long bytesProcessed = 0;
long sectorsCopied = 0;
var fileinfo = new FileInfo(sourceFile);
var fileFragments = FileFragments.GetFileAllocation(sourceFile);
if(fileFragments.TotalFragments == 0 || fileinfo.Length == 0)
return false;
var device = new Device(512);
View FileFragments.cs
public class FileFragments
{
private const int FSCTL_GET_RETRIEVAL_POINTERS = 0x00090073;
private const uint FileAccess_GenericRead = 0x80000000;
private const uint FileAccess_GenericWrite = 0x40000000;
private const uint FileShare_Read = 0x00000001;
private const uint FileShare_Write = 0x00000002;
private const uint FileShare_ReadWrite = FileShare_Read | FileShare_Write;
private const uint FileMode_OpenExisting = 0x00000003;
private const uint FileAttributes_Normal = 0x00000080;
View Device.cs
public class Device
{
public enum CreationDisposition : uint
{
CREATE_NEW = 1,
CREATE_ALWAYS = 2,
OPEN_EXISTING = 3,
OPEN_ALWAYS = 4,
TRUNCATE_EXSTING = 5
}
View HashAlgorithmHelper.cs
public static class HashAlgorithmHelper
{
public static byte[] UpdateHash(this HashAlgorithm hash, byte[] buffer)
{
hash.TransformBlock(buffer, 0, buffer.Length, null, 0);
hash.TransformFinalBlock(new byte[0], 0, 0);
hash.Final();
return hash.Hash;
}
View FileHelperEx.cs
/// <summary>
/// Example:
/// var fh = new FileHelperEx();
/// var hash = new SHA512CryptoServiceProvider();
/// hash.Initialize();
/// fh.ReadStream(fileName, buffer => hash.TransformBlock(buffer, 0, buffer.Length, null, 0));
/// hash.Final();
/// var sha512 = new BigInteger(hash.Hash);
/// </summary>
public class FileHelperEx