Skip to content

Instantly share code, notes, and snippets.

View mildsunrise's full-sized avatar
🦊
*rolls*

Alba Mendez mildsunrise

🦊
*rolls*
View GitHub Profile
@mildsunrise
mildsunrise / sllv2tossl.c
Created February 27, 2024 23:30
converts an SLLv2 pcap into an SLL one (because tools like tcpflow and tcpreplay lack support for SLLv2 and it's maddening)
// compile with: clang -Wpedantic -Wall -Wextra $(pkg-config --cflags libpcap) sllv2tosll.c $(pkg-config --libs libpcap) -o sllv2tossl
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <pcap/pcap.h>
char error_buffer[PCAP_ERRBUF_SIZE];
@mildsunrise
mildsunrise / sa-is.hs
Last active February 26, 2024 14:25
Haskell implementation of SA-IS
{-# LANGUAGE TupleSections #-}
import Data.Array (accumArray, listArray, elems)
import Data.List.Extra (findIndices, groupSortOn, chunksOf)
import Data.Vector ((!), toList)
import Control.Monad (forM_, when, zipWithM)
import qualified Data.Vector as Vec
import qualified Data.Vector.Mutable as MVec
fill v = zipWithM (MVec.write v) [0..MVec.length v - 1]
@mildsunrise
mildsunrise / block.rs
Last active February 18, 2024 18:13
simple linked list allocator in Rust
use std::{mem, ptr};
use crate::BufferAlloc;
unsafe fn write_ptr(n: *mut usize, ptr: Option<*mut usize>) {
debug_assert!(!ptr.is_some_and(|ptr| n == ptr));
ptr::write(n.cast(), ptr.unwrap_or(n))
}
unsafe fn read_ptr(n: *mut usize) -> Option<*mut usize> {
let ptr = ptr::read(n.cast());
@mildsunrise
mildsunrise / blobs.py
Last active February 18, 2024 07:52
Logic to work with Android KeyMaster blobs and Vold
#!/usr/bin/env python3
'''
keymaster blob logic.
Offers:
- low-level blob encoding and decoding
- loading softkeymaster blobs
- performing cryptographic operations (emulating KeyMaster) on a loaded blob
- CLI tool for parsing softkeymaster blobs and performing operations with them
@mildsunrise
mildsunrise / daikin.py
Last active February 9, 2024 03:06
Documentation / implementation of Daikin's IR protocol in Python
'''
This module implements the IR protocol for Daikin's air conditioning units.
It is based on this work:
<https://github.com/blafois/Daikin-IR-Reverse>
And contains some additional improvements, such as:
- Implementation of the low layer (IR signal protocol).
The low-level IR protocol is not explained very well by blafois;
no mention is made to the following:
@mildsunrise
mildsunrise / README.md
Last active February 7, 2024 15:11
🖥 Lightweight diskless VM with QEMU (Arch Linux variant)

🖥 Lightweight diskless VM with QEMU (Arch Linux variant)

This document describes a process to quickly setup a Linux VM for testing or kernel development.

The VM requires no disk image, instead it boots off a directory on the host (using virtiofs). This is:

  • more performant (no FS-in-FS overhead)
  • more convenient for experiments (both host and guest can modify files concurrently)
  • safer (no corruption* in case of kernel panic)
  • easier to set up
@mildsunrise
mildsunrise / README.md
Last active January 25, 2024 01:31
JS code in the PDF for Spanish tax form 145

The Spanish government loves (or loved) using JavaScript in their tax forms.

This gist contains the JS blocks in the official tax form 145 PDF, version 1.0/2022. Enjoy.

The code is reproduced verbatim, except for normalizing the encoding (latin-1 to utf-8) and the newlines (CRLF to LF). Using some iconv command + unix2dos should give you back the exact bytes in the PDF, except for one thing: there's a stray CR without accompanying LF in object828.js:139. Yeah, idk.

Usage of virglrenderer

Introduction

virglrenderer is a library that gives emulators the necessary tools to implement a [virtio-gpu][] device, in particular one with 3D support. See capability sets below for a summary of the APIs virglrenderer can implement for the guest. It directly implements the logic behind some 3D commands like GET_CAPSET, CTX_CREATE, CTX_SUBMIT_3D, CREATE_RESOURCE_BLOB, and though it closely follows the semantics of virtio-gpu in most cases, it is in theory independent of virtio or any other transport.

Main user is [qemu][qemu-gpu-impl], but there also appears to be a [standalone virtio-gpu vhost-user][qemu-vhost-impl] implementation that uses virglrenderer in qemu/contrib.

virglrenderer's public header is at [src/virglrenderer.h][public-header]. This document attempts to outine the public API and contract, but you should look at the header for an authoritative source of truth since semantics described here could be slightly wrong or have changed, a

@mildsunrise
mildsunrise / mysql_pcap.py
Created May 7, 2020 10:27
Script to extract statistics about MySQL queries in a .pcap.
#!/usr/bin/env python3
'''
Script to extract statistics about MySQL queries in a .pcap.
'''
import sys
from subprocess import run
import json, csv, re
args = sys.argv[1:]
if len(args) != 2:
@mildsunrise
mildsunrise / arithmetic.py
Last active December 10, 2023 23:47
Integer (and polynomial) modular arithmetic for Python!
"""
INTEGER MODULAR ARITHMETIC
These functions implement modular arithmetic-related functions (Z/nZ).
As an implied precondition, parameters are assumed to be integers unless otherwise noted.
This code is time-sensitive and thus NOT safe to use for online cryptography.
"""
from typing import Iterable, Tuple, NamedTuple
from functools import reduce