Skip to content

Instantly share code, notes, and snippets.

@martani
martani / AES_Decrypt_block.cs
Created September 23, 2012 22:53
AES single block decryption/encryption _
private static byte[] AES_Decrypt_block(byte[] cipherText, byte[] Key)
{
// Declare the string used to hold the decrypted text.
byte[] output_buffer = new byte[cipherText.Length];
using (AesManaged aesAlg = new AesManaged())
{
//If CBC, must initialize IV = O_{128}
//aesAlg.Mode = CipherMode.CBC;
//aesAlg.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@AlexArchive
AlexArchive / Program.cs
Created July 19, 2013 00:38
Demo: Basic Usage of DynamicMethod to Omit Opcodes
public sealed class Program
{
static void Main(string[] args)
{
var result = Math.AddNumbers(10, 20);
Console.WriteLine(result);
Console.ReadKey();
}
}
@FrankWu100
FrankWu100 / AESEnDecryption.cs
Last active November 1, 2023 12:44
AES Encryption/Decryption on C#
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.Serialization.Formatters.Binary;
class AESEnDecryption
{
public static byte[] encrypt(byte[] bytes, string keyStr, string ivStr)
{
public static class MethodInvoker
{
public static object InvokeMethod(string methodName, object[] paramaters = null)
{
MethodInfo method = ResolveMethodWithName(methodName);
if (method == null)
throw new InvalidOperationException("A method with the name " + methodName + " cannot be found.");
if (method.IsStatic)
{
@breezhang
breezhang / GetDelegateForFunctionPointer.cs
Created October 6, 2013 09:24
Marshal --> ( Marshal.GetFunctionPointerForDelegate GetDelegateForFunctionPointer)
public static partial class Util
{
const string kDelegateInvokeMethodName = "Invoke";
// http://www.codeproject.com/Tips/441743/A-look-at-marshalling-delegates-in-NET
public static T GetDelegateForFunctionPointer<T>(IntPtr ptr, System.Runtime.InteropServices.CallingConvention call_conv)
where T : class
{
Contract.Requires<ArgumentException>(typeof(T).IsSubclassOf(typeof(Delegate)));
Contract.Requires<ArgumentNullException>(ptr != IntPtr.Zero);
Contract.Requires<ArgumentException>(call_conv != System.Runtime.InteropServices.CallingConvention.ThisCall,
using System;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace MyProgram
{
class Program
@Konctantin
Konctantin / ProcessMemory
Created March 28, 2014 16:21
ProcessMemory
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace NetCallerFunc
@hugsy
hugsy / RunMe.c
Last active March 5, 2021 16:31
RunMe.c
/**
* Trick to run arbitrary command when code execution policy is enforced
* (i.e. AppLocker or equivalent). Works on Win98 (lol) and up - tested on 7/8
*
* To compile using CL as DLL:
* C:> cl.exe RunMe.c /LD /OUT:RunMe.dll
* To compile as PE (USE_DLL must be commented out):
* C:> cl.exe RunMe.c /OUT:RunMe.exe
*
* To execute under Windows:
/*
Change Log:
v1.12 (2017-01-18) - Fixed OnExit not exiting
v1.11 (2017-01-17) - Added an internal function Ensure_Admin_And_Compiled()
v1.10 (2015-10-22) - Added support for sending characters that needs to press {shift} key, such as "@" or "A".
v1.00 (2015-07-25)
Dependency files:
WinRing0_v1.3.1.19.zip -- https://drive.google.com/file/d/0B7yNOlCgfluzMTE2UFc2ZHp5Z1E/view?usp=sharing
@brianhassel
brianhassel / PreventSleep.cs
Last active June 24, 2024 18:42
Prevent Computer Sleep in C#
internal static class NativeMethods {
public static void PreventSleep() {
SetThreadExecutionState(ExecutionState.EsContinuous | ExecutionState.EsSystemRequired);
}
public static void AllowSleep() {
SetThreadExecutionState(ExecutionState.EsContinuous);
}