Skip to content

Instantly share code, notes, and snippets.

@zhangyoufu
zhangyoufu / check-hyperv-enlightenment.c
Created November 17, 2024 18:24
check enabled Hyper-V Enlightenment inside VM
#include <intrin.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/******************************************************************************/
// include/qemu/bitops.h
#define BIT(nr) (1UL << (nr))
@zhangyoufu
zhangyoufu / 99-replica-set.sh
Created June 10, 2019 11:07
ugly hack to initialize replica set for MongoDB docker container, put under /docker-entrypoint-initdb.d/
#!/bin/bash
: "${FORKED:=}"
if [ -z "${FORKED}" ]; then
echo >&2 'mongod for initdb is going to shutdown'
mongod --pidfilepath /tmp/docker-entrypoint-temp-mongod.pid --shutdown
echo >&2 'replica set will be initialized later'
FORKED=1 "${BASH_SOURCE[0]}" &
unset FORKED
mongodHackedArgs=(:) # bypass mongod --shutdown in docker-entrypoint.sh
@zhangyoufu
zhangyoufu / gist:0b3123fe37e2906536827ace81c0ad5d
Created November 3, 2024 09:40
Windows Processor Architecture Enumeration
0: PROCESSOR_ARCHITECTURE_INTEL
1: PROCESSOR_ARCHITECTURE_MIPS
2: PROCESSOR_ARCHITECTURE_ALPHA
3: PROCESSOR_ARCHITECTURE_PPC
4: PROCESSOR_ARCHITECTURE_SHX
5: PROCESSOR_ARCHITECTURE_ARM
6: PROCESSOR_ARCHITECTURE_IA64
7: PROCESSOR_ARCHITECTURE_ALPHA64
8: PROCESSOR_ARCHITECTURE_MSIL
9: PROCESSOR_ARCHITECTURE_AMD64
@zhangyoufu
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.100.6.1.2 iOS Development
1.2.840.113635.100.6.1.3 iOS App Store Application
1.2.840.113635.100.6.1.4 iOS Distribution
1.2.840.113635.100.6.1.6 iOS App Store VPN Application
1.2.840.113635.100.6.1.7 3rd Party Mac Developer Application
1.2.840.113635.100.6.1.8 3rd Party Mac Developer Installer
1.2.840.113635.100.6.1.9 Mac App Store Application
1.2.840.113635.100.6.1.10 Mac App Store Installer
1.2.840.113635.100.6.1.11 Mac App Store Receipt
@zhangyoufu
zhangyoufu / ipv6-address-space.md
Last active August 3, 2024 19:03
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
zhangyoufu / getgo.sh
Last active July 25, 2024 07:43
Download latest Go release and install to /opt
#!/bin/sh
not_available() { echo -- "$1 is not available"; exit 1; }
ensure_command_available() { which -- "$1" >/dev/null && return; not_available "$1"; }
ensure_gnu_tar() { tar --version | grep -F 'GNU tar' >/dev/null || not_available 'GNU tar'; }
ensure_command_available curl
ensure_command_available jq
ensure_gnu_tar
@zhangyoufu
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
zhangyoufu / tiger-vnc.rb
Created June 17, 2024 02:50
tiger-vnc Homebrew Formula with ffmpeg for PiKVM H.264 encoding
class TigerVnc < Formula
desc "High-performance, platform-neutral implementation of VNC"
homepage "https://tigervnc.org/"
url "https://github.com/TigerVNC/tigervnc/archive/refs/tags/v1.13.1.tar.gz"
sha256 "b7c5b8ed9e4e2c2f48c7b2c9f21927db345e542243b4be88e066b2daa3d1ae25"
license "GPL-2.0-or-later"
# Tags with a 90+ patch are unstable (e.g., the 1.9.90 tag is used for the
# 1.10.0 beta release) and this regex should only match the stable versions.
livecheck do
@zhangyoufu
zhangyoufu / ln.py
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)
MAXPATHLEN = 0x400
# see smbfs_create_windows_symlink_data
def symlink(target: str, link: str) -> None:
@zhangyoufu
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
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x00000000deadbeed in ?? ()
=> 0x00000000deadbeed:
Cannot access memory at address 0xdeadbeed