Skip to content

Instantly share code, notes, and snippets.

zhangyoufu /
Created August 25, 2022 10:47
create symlink on exFAT filesystem (macOS way)
#!/usr/bin/env python3
import argparse
import hashlib
import os
SMB_SYMHDRLEN = (4+1)+(4+1)+(32+1)
# see smbfs_create_windows_symlink_data
def symlink(target: str, link: str) -> None:
zhangyoufu / gdb.txt
Last active May 10, 2024 17:22
The architecture-specific signal handling code may adjust RIP/RAX to restart interrupted syscall. Address set be tracer via PTRACE_SETREGS may be decreased by 2 bytes unexpectedly on i386/x86-64. To workaround this behavior, tracer have to check whether tracee is in system call and whether the errno indicates restartable.
(gdb) set $rip=0xdeadbeef
(gdb) c
Program received signal SIGSEGV, Segmentation fault.
0x00000000deadbeed in ?? ()
=> 0x00000000deadbeed:
Cannot access memory at address 0xdeadbeed
zhangyoufu / certs.txt
Created March 7, 2024 10:47
A configuration profile needed by VirtualBox VBoxHeadless, signed by Apple, valid for 18 years, grants several entitlements
% openssl pkcs7 -print_certs -text -in embedded.provisionprofile -inform der
Version: 3 (0x2)
Serial Number: 134752589830791184 (0x1debcc4396da010)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, O=Apple Inc., OU=Apple Certification Authority, CN=Apple Root CA
Not Before: Feb 7 21:48:47 2013 GMT
Not After : Feb 7 21:48:47 2023 GMT
zhangyoufu / apple_pki_attribute.txt
Created January 10, 2022 06:06
Apple PKI attributes (incomplete)
1.2.840.113635.100.6.1 Leaf Certificate
1.2.840.113635. iOS Development
1.2.840.113635. iOS App Store Application
1.2.840.113635. iOS Distribution
1.2.840.113635. iOS App Store VPN Application
1.2.840.113635. 3rd Party Mac Developer Application
1.2.840.113635. 3rd Party Mac Developer Installer
1.2.840.113635. Mac App Store Application
1.2.840.113635. Mac App Store Installer
1.2.840.113635. Mac App Store Receipt
zhangyoufu /
Created June 10, 2019 11:07
ugly hack to initialize replica set for MongoDB docker container, put under /docker-entrypoint-initdb.d/
: "${FORKED:=}"
if [ -z "${FORKED}" ]; then
echo >&2 'mongod for initdb is going to shutdown'
mongod --pidfilepath /tmp/ --shutdown
echo >&2 'replica set will be initialized later'
unset FORKED
mongodHackedArgs=(:) # bypass mongod --shutdown in
zhangyoufu / gist:5814814
Created June 19, 2013 14:36
JNIEnv functions table, helpful when reverse engineering JNI
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
typedef int jint;
typedef int jclass;
typedef int jobject;
typedef int jmethodID;
typedef int jfieldID;
typedef int JNIEnv;
zhangyoufu / extract-installbuilder.tcl
Created August 10, 2020 10:18
extract password-protected InstallBuilder installer
## prepare runtime environment
proc init {} {
## mount optional.pak (for tcltwofish)
set optionalPak installbuilder/paks/optional.pak
vfs::mk4::Mount $optionalPak $optionalPak -readonly
## adjust library search path
set ::auto_path [list $tcl::kitpath/lib/tcl$::tcl_version $tcl::kitpath/lib $tcl::kitpath/libraries $optionalPak/linux-x64 $tcl::kitpath]
zhangyoufu /
Last active May 5, 2023 06:12
force unbuffer stdout of Windows program
#!/usr/bin/env python3
from msvcrt import get_osfhandle
from ctypes.wintypes import *
from ctypes import *
import os
import struct
if sizeof(c_ulong) == sizeof(c_void_p):
ULONG_PTR = c_ulong
elif sizeof(c_ulonglong) == sizeof(c_void_p):
zhangyoufu /
Last active March 27, 2023 06:30
IPv6 Address Space

IPv6 Address Space

::/128               Unspecified Address
  ::1/128            Loopback Address
  ::ffff:0:0/96      IPv4-mapped Address
64:ff9b::/96         IPv4-IPv6 Translate
64:ff9b:1::/48       IPv4-IPv6 Translate
100::/64             Discard-Only Address Block
0200::/7             OSI NSAP-mapped prefix set (deprecated)
zhangyoufu / ip-down
Created November 8, 2020 12:59
pppd script to generate drop-in configuration for systemd-networkd, do NOT use in production
set -eu
# check existence
[ -e "/run/systemd/network/$" ] || exit 0
# remove drop-in configuration
rm -f "/run/systemd/network/$"/ppp-*.conf
# remove previous configuration from networkd