Skip to content

Instantly share code, notes, and snippets.

View leiless's full-sized avatar
🎯
Focusing

Fishbone° leiless

🎯
Focusing
  • China
  • 18:00 (UTC +08:00)
View GitHub Profile
@leiless
leiless / debj32_first_4096.txt
Last active April 28, 2021 00:24
List of first 4096 32-bit De Bruijn constants for LSB
0x04653adf 0x04653b5f 0x04653eb7 0x04653ed7 0x046569df 0x046569f7 0x04656e9f 0x04656fa7
0x0465769f 0x04657da7 0x0465a9df 0x0465a9f7 0x0465ba9f 0x0465bea7 0x0465da9f 0x0465f6a7
0x04674adf 0x046752df 0x0467695f 0x04676a5f 0x0467d2b7 0x0467d4b7 0x0467da57 0x0467da97
0x046959df 0x046959f7 0x04695cfb 0x04695d9f 0x04695f3b 0x04695f67 0x0469cafb 0x0469d95f
0x0469df2b 0x0469f2bb 0x0469f657 0x0469f72b 0x046a59df 0x046a59f7 0x046a5cfb 0x046a5d9f
0x046a5f3b 0x046a5f67 0x046a72fb 0x046a765f 0x046a77cb 0x046a7cbb 0x046a7d97 0x046a7dcb
0x046b29df 0x046b29f7 0x046b94fb 0x046bb29f 0x046be53b 0x046beca7 0x046ca75f 0x046ca7d7
0x046cae9f 0x046cafa7 0x046cba9f 0x046cbea7 0x046ce95f 0x046cea5f 0x046cfa57 0x046cfa97
0x046e53eb 0x046e7d2b 0x046e7d4b 0x046e959f 0x046e9f2b 0x046ea59f 0x046ea7cb 0x046eb29f
0x046f94eb 0x046f9d2b 0x046f9d4b 0x046fa567 0x046fa72b 0x046fa967 0x046fa9cb 0x046faca7
@leiless
leiless / fetch_all_bsd_proc.c
Created November 29, 2018 02:11
(macOS) Fetch all BSD procs into a proc list
/*
* Created 181128 lynnl
*/
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#ifndef __nullable
@leiless
leiless / probeRemovableMountedVolumes.m
Created November 29, 2018 11:31
(macOS) Fetch local removable mounted volumes
/**
* Probe local removable mounted volumes
* @return An array with NSURL objects
*/
+ (NSArray<NSURL *> *)probeRemovableMountedVolumes {
NSArray *keys = [NSArray arrayWithObjects:NSURLVolumeIsEjectableKey,
NSURLVolumeIsLocalKey, NSURLVolumeIsReadOnlyKey,
NSURLVolumeIsRemovableKey, nil];
NSArray *flags = [NSArray arrayWithObjects:@YES, @YES, @NO, @YES, nil];
@leiless
leiless / BUILD_BUG_ON.h
Last active November 30, 2018 02:30
Simplified BUILD_BUG_ON(condition) macro
#ifdef DEBUG
#define BUILD_BUG_ON(cond) ((void) sizeof(char[-!(cond)]))
#define BUILD_BUG_ON2(cond) ((void) (char[1]){[!(cond)] = 0}) /* Nonoptimal */
#else
#define BUILD_BUG_ON(cond) ((void) (cond))
#define BUILD_BUG_ON2(cond) ((void) (cond))
#endif
@leiless
leiless / QSTRLEN.h
Created November 30, 2018 03:36
static strlen() macro for char[]
/*
* XXX: Should used only for `char[]'(NOT `char *')
*/
#define QSTRLEN(s) (sizeof(s) - 1)
@leiless
leiless / xcrun_mac_sdk_path.sh
Created December 11, 2018 06:15
Find macOS SDK path
xcrun --sdk macosx --show-sdk-path
#
# see:
# https://stackoverflow.com/questions/18741675/how-to-get-the-path-of-latest-sdk-available-on-mac
#
@leiless
leiless / xcode_10.1_10B61_kext_build.log
Created December 11, 2018 06:27
Bare-bone kext build log from XCode 10.1(10B61) in macOS Mojave(18C54)
Showing All Messages
Prepare build
note: Using new build systemnote: Planning buildnote: Using build description from memory
Build target kext-test of project kext-test with configuration Debug
CreateBuildDirectory /Users/lynnl/Library/Developer/Xcode/DerivedData/kext-test-arzgdkduvgiifeclyjsvcrtkxtkg/Build/Products (in target: kext-test)
@leiless
leiless / dump_clang_predefined_macros.md
Created December 22, 2018 02:20
HOWTO dump clang predefined macros
$ xcrun --sdk macosx --find clang
/Library/Developer/CommandLineTools/usr/bin/clang

$ /Library/Developer/CommandLineTools/usr/bin/clang -dM -E - < /dev/null
#define OBJC_NEW_PROPERTIES 1
#define _LP64 1
#define __APPLE_CC__ 6000
#define __APPLE__ 1
#define __ATOMIC_ACQUIRE 2
@leiless
leiless / sqlite3_bom.c
Last active February 26, 2019 06:41
sqlite3_bind_text16() will discard heading BOM(UTF-16) character, i.e. BOM-aware
/*
* Created 190102
*
* gcc -Wall -Wextra -std=c11 -O0 -g -DDEBUG -lsqlite3 sqlite_bom.c -o sqlite_bom
*
* see:
* https://www.sqlite.org/cintro.html
* https://www.sqlite.org/quickstart.html
* https://www.sqlite.org/howtocompile.html
* https://en.wikipedia.org/wiki/Byte_order_mark#UTF-16
@leiless
leiless / mk_mojave_iso.sh
Created January 9, 2019 07:12
Create bootable macOS 10.14 Mojave iso
#!/bin/sh
#
# Created 190109 lynnl
#
set -e
#set -x
if [ $# -ne 1 ]; then
echo "`basename $0` installer_app"