Skip to content

Instantly share code, notes, and snippets.

@iamahuman
iamahuman / dnf-set-metalink-params.py
Last active September 1, 2023 17:17
Set metalink parameters in DNF repo config
@iamahuman
iamahuman / gdi_argb8888_to_pargb8888.c
Created March 13, 2022 23:09
Convert ARGB8888 bitmap to Premultipled ARGB8888 bitmap (expected by GdiAlphaBlt)
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#include <windows.h>
HBITMAP argb8888_to_pargb8888(HBITMAP hbm, HDC hdc)
{
const BLENDFUNCTION blendfn = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA };
HDC hdcSrc, hdcTmp1, hdcTmp2;
HBITMAP hbmRes = NULL, hbmTmp1, hbmTmp2;
@iamahuman
iamahuman / Makefile
Last active January 1, 2022 16:59
openat() tracer
CC = gcc
CFLAGS = -O2 -g -shared -fPIC -Wall $(EXTRACFLAGS)
LDFLAGS = -Wl,-z,now,-z,relro $(EXTRALDFLAGS)
LIBS = -lunwind-x86_64 -lpthread
all: libmain.so
libmain.so: main.c
$(CC) $(CFLAGS) -o libmain.so main.c $(LDFLAGS) $(LIBS)
@iamahuman
iamahuman / deb-decompress.c
Created April 4, 2021 08:15
Decompress inner archives (control.tar, data.tar) of Debian packages (.deb)
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
@iamahuman
iamahuman / capiblob.py
Created March 8, 2021 15:01
Parse Crypto API certificate blobs in Windows Registry
#!/usr/bin/env python3
import sys
import os
import struct
PROP_STRUCT = struct.Struct("<3I")
# {{{ constants
PROP_IDS = {
1: "KEY_PROV_HANDLE",
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#define _LARGEFILE64_SOURCE
@iamahuman
iamahuman / mvdir.c
Last active June 25, 2019 18:21
(*nix) Merge two dirs w/o copying
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
@iamahuman
iamahuman / ContLabel.hs
Created May 1, 2019 08:02
"setjmp / longjmp" in Haskell (continuations)
module ContLabel where
import Control.Monad.Trans.Cont
import Control.Monad.IO.Class
type Jmp r m a = (Maybe a, Label r m a)
newtype Label r m a = Label (Jmp r m a -> m r)
setjmp :: ContT r m (Jmp r m a)
setjmp = ContT $ \ c -> c (Nothing, Label c)
@iamahuman
iamahuman / PureRef.hs
Last active April 4, 2021 13:02
A pure ST monad transformer with coercible references
{-# OPTIONS_HADDOCK show-extensions #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ExistentialQuantification #-}
-----------------------------------------------------------------------------
-- |
-- Module : Data.PureRef
-- Copyright : (c) Jinoh Kang, 2019
-- License : MIT
module Main where
import Control.Applicative
import Control.Exception
import Data.List
import Data.Char
import qualified Data.Map as Map
import System.IO
import System.IO.Error
import System.Environment