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 / get_init.py
Created January 3, 2022 22:59
list initialization functions of an ELF object
#!/usr/bin/env python3
# this is very incomplete
# - aarch64 only
# - legacy INIT tag not supported
# - no other relocation tables supported other than RELA
# - no other relocation types supported other than R_64_RELATIVE
# - multiple(?) or no relocations?
# - assume segments are all mapped contiguously
@mildsunrise
mildsunrise / mappings.py
Created January 3, 2022 22:56
logic to deal with non-overlapping interval mappings
'''logic to deal with non-overlapping [key, key+length) mappings,
given as a list of opaque elements plus `key` and `length` key functions.'''
from bisect import bisect
from typing import Callable, Iterator, Sequence, TypeVar
T = TypeVar('T')
def pairwise(xs: Sequence[T]) -> Iterator[tuple[T, T]]:
return zip(xs, xs[1:])
@mildsunrise
mildsunrise / conway_3d.py
Last active January 11, 2022 19:23
🦠 Conway's game of life(ish) in 3D, with OpenVDB output for every generation
#!/usr/bin/env python3
import pyopenvdb as vdb
import numpy as np
import scipy.signal
# PARAMETERS
kernel = '''
XXX|XXX|XXX
@mildsunrise
mildsunrise / README.md
Created October 19, 2021 22:12
🔬 Script to mount decrypted disk on Android 12 https://twitter.com/mild_sunrise/status/1449321409793175552

Important: This script is not really meant to be used as is, instead you should execute each step one by one, understanding its purpose. I highly recommend you read the accompanying Twitter thread before trying it.

--

This is a script that performs all needed actions to mount the userdata partition of an Android 12 emulator device (AVD).

@mildsunrise
mildsunrise / blobs.py
Last active May 3, 2024 21:15
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 / emojis.py
Last active January 10, 2022 02:54
🏴 Code to deal with emojis
'''Code to deal with emojis.
Right now it's just oriented about formatting national flag emojis,
see format_iso_country() and format_subdivision_flag().
'''
# ISO 3166 logic
def is_iso_country_alpha2(code):
return len(code) == 2 and all('A' <= x <= 'Z' for x in code)
@mildsunrise
mildsunrise / gdb_print_thread_name.diff
Created August 24, 2021 11:09
make GDB print the thread name in all thread ID descriptions, not just `info threads`
--- gdb-8.1.1.orig/gdb/linux-thread-db.c
+++ gdb-8.1.1/gdb/linux-thread-db.c
@@ -1380,11 +1380,16 @@ thread_db_pid_to_str (struct target_ops
if (thread_info != NULL && thread_info->priv != NULL)
{
- static char buf[64];
+ static char buf[128];
thread_db_thread_info *priv = get_thread_db_thread_info (thread_info);
+ const char *name = thread_info->name ? thread_info->name : target_thread_name(thread_info);
@mildsunrise
mildsunrise / dump_vdso_data.c
Last active October 1, 2022 16:36
dumps the data in the vdso_data VVAR (timekeeping info for gettimeofday vDSO)
// WARNING: only for x86
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <sys/auxv.h>
@mildsunrise
mildsunrise / save.py
Last active June 28, 2021 10:28 — forked from mickael9/save.py
Factorio map metadata parser
from zipfile import ZipFile
from struct import Struct
## primitives ##
class Deserializer:
u16 = Struct('<H')
u32 = Struct('<I')
@mildsunrise
mildsunrise / Brainfuck.hs
Last active June 18, 2021 21:01
Brainfuck interpreter in Haskell
{-# LANGUAGE FlexibleContexts #-}
module Brainfuck (
VMState (..), initializeState,
hasExited, executeInstruction, executeVM,
) where
import Data.Maybe (fromMaybe, fromJust)
import qualified Data.Map as Map
import Data.Array.Base (numElements)