Skip to content

Instantly share code, notes, and snippets.

@odzhan
odzhan / dump_lua.cpp
Created August 15, 2025 11:17
Dump Lua byte code from resource directory of PE file.
/**
windiag.dll has support for executing Lua bytecode. At the time of writing, there's only one DLL that uses windiag.dll to execute Lua code and that's the Windows Hardware Error Service (whesvc.dll).
The Lua byte code itself is located in the resource directory of whesvc_assets.dll
You need to decompress the data before actually obtaining the byte code, but this is simply done via cabinet compression API.
cl /EHsc /std:c++20 dump_lua.cpp
*/
#ifndef _WIN32_WINNT
@odzhan
odzhan / sha256.h
Last active July 8, 2025 21:35
sha256
#ifndef SHA256_H
#define SHA256_H
#define R(v,n)(((v)>>(n))|((v)<<(32-(n))))
#define F(n)for(i=0;i<n;i++)
#ifdef _MSC_VER
#include <intrin.h>
#define rev32(x) _byteswap_ulong(x)
@odzhan
odzhan / crt.c
Last active May 25, 2025 20:16
Writing Tiny Executables in C
/**
Compile with your C console project.
*/
#include <stdio.h>
#include <windows.h>
#define __UNKNOWN_APP 0
#define __CONSOLE_APP 1
#define __GUI_APP 2
@odzhan
odzhan / clr_hostctrl.cpp
Created February 26, 2025 05:22
hosting
//#include "x64/Debug/mscorlib.tlh"
#import "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.tlb" rename("or", "or2") rename("ReportEvent", "ReportEvent2") no_namespace raw_interfaces_only
#include <iostream>
#define __IObjectHandle_INTERFACE_DEFINED__
#include <MScorEE.h>
#include <MetaHost.h>
#include <shlwapi.h>
#include <vector>
#include <fstream>
#include "objbase.h"
@odzhan
odzhan / pklnxcli.c
Created February 15, 2025 21:59
Simple Echo Servers Using Symmetric Encryption
/*
** Demo Public Key OpenSSL Echo Client
**
** Connects to an PK Echo Server. Generates RSA Key and
** sends encoded public key to server. Response is a
** session key encoded with the public key. Sends client
** request, encoded with session key, consisting of
** header and text to be echo'd between lines 'BEGIN'
** and 'END' (inclusive). Reads server response, also
** encoded with session key, consisting of header and
@odzhan
odzhan / find_exp.c
Last active October 25, 2024 20:40
Find Involutory Exponents
/**
Find involutory exponents for a modulus like a Mersenne prime: 2^31-1
Uses brute force
Very fast for small numbers, very slow for anything more than 16-bits.
gcc -O2 find_exp.c -ofind_exp -lcrypto
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@odzhan
odzhan / aperm.py
Created October 18, 2024 15:01
Affine Permutation For Obfuscation
#!/usr/bin/env python3
"""
Affine Permutation File Encoder/Decoder
This script allows you to encode and decode files using an Affine Permutation.
It uses command-line arguments to specify the operation mode (encode or decode), input file, and output file.
Additionally, it stores a SHA256 hash of the original data to verify successful decoding.
Usage:
To encode a file:
@odzhan
odzhan / prng.c
Last active October 21, 2024 19:25
LCG and ICG
/**
LCG output...
lcg(1) : 40B2947B
lcg(2) : 73718F14
lcg(3) : 6203F04B
lcg(4) : 1BB91A70
lcg(5) : 0CFC23E0
ICG output...
icg(5) : 0CFC23E0
@odzhan
odzhan / f8.c
Created September 15, 2024 05:56
FEAL Block Cipher Implementations from Handbook of Cryptography.
//
// FEAL-8 Block Cipher
//
#include <stdio.h>
#include <stdint.h>
// Define the Sd function as per equation (7.6)
uint8_t Sd(uint8_t x, uint8_t y, uint8_t d) {
@odzhan
odzhan / aradi.c
Last active August 12, 2024 05:17
/**
ARADI and LLAMA: Low-Latency Cryptography for Memory Encryption
Published in August 2024
Only tested on little-endian CPU.
For more details, see https://eprint.iacr.org/2024/1240
*/
#include <stdint.h>