Skip to content

Instantly share code, notes, and snippets.

View obfusk's full-sized avatar
🏳️‍🌈
hacking ⇒ ¬sleeping 😸

FC (Fay) Stegerman obfusk

🏳️‍🌈
hacking ⇒ ¬sleeping 😸
View GitHub Profile
#!/usr/bin/python3
import json
import zipfile
from hashlib import sha1, sha256
from asn1crypto import cms # type: ignore[import-untyped]
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import serialization
#!/bin/bash
set -euo pipefail
zipentry=META-INF/version-control-info.textproto
commit_from_zip() {
unzip -p -- "$1" "$zipentry" | grep revision | grep -Eo '[0-9a-f]+' | tail -1
}
url="${1:-}"
if [ -z "$url" ]; then
read -r -p 'url> '
url="$REPLY"
public class Unicode {
public static void main(String[] args) {
String foo = "🏳️‍⚧️";
for (String x : foo.split("")) {
System.out.println(x.codePointAt(0));
}
System.out.println("---");
int n = foo.codePointCount(0, foo.length());
for (int i = 0; i < n; ++i) {
int j = foo.offsetByCodePoints(0, i);
@obfusk
obfusk / .flake8
Last active July 21, 2024 18:50
pychk
[flake8]
ignore = E501
#!/usr/bin/python3
# encoding: utf-8
# SPDX-FileCopyrightText: 2024 FC (Fay) Stegerman <[email protected]>
# SPDX-License-Identifier: AGPL-3.0-or-later
import os
import struct
import zipfile
from dataclasses import dataclass

x509_canonical_name.py

Python implementation of the Java algorithm for an RFC 2253 conformant string representation of an X.500 distinguished name with additional canonicalisations (as used to compare distinguished names in X.509 certificates for equality in e.g. apksigner and Android).

See the Java documentation.

Caveats

import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
def i = new FileInputStream(args[0])
def cert = CertificateFactory.getInstance("X.509").generateCertificate(i)
println cert.getIssuerX500Principal().getName(javax.security.auth.x500.X500Principal.CANONICAL)
@mildsunrise
mildsunrise / create-object.py
Last active December 14, 2024 14:23
recursively creates git objects (trees, blobs) mirroring a directory in disk
import os, stat
from contextlib import contextmanager
from subprocess import run
@contextmanager
def fd_context(fd: int):
try:
yield fd
finally:
os.close(fd)
@obfusk
obfusk / example.sh
Created May 28, 2024 20:05
perl command to decrement numbers in a file
perl -pi -e 's/\b(\d+)\b/$1 - 1/e' file-with-numbers
#!/usr/bin/python3
import dataclasses
import json
import sys
import repro_apk.binres as binres
data = {}
for apkfile in sys.argv[1:]:
try: