Skip to content

Instantly share code, notes, and snippets.

View leiless's full-sized avatar
🎯
Focusing

Fishbone° leiless

🎯
Focusing
  • China
  • 15:48 (UTC +08:00)
View GitHub Profile
@leiless
leiless / apple_kctlsock_names.txt
Last active September 26, 2024 15:41
Dump kernel control socket registered by Apple
id name
------------------------------------
1 com.apple.flow-divert
2 com.apple.nke.sockwall
3 com.apple.content-filter
4 com.apple.packet-mangler
5 com.apple.net.necp_control
6 com.apple.net.netagent
7 com.apple.net.utun_control
8 com.apple.net.ipsec_control
@leiless
leiless / kext_get_kern_vm_addr.c
Last active September 21, 2018 11:20
How to get XNU kernel vm address and its size
#include <mach/mach_types.h>
#include <mach/mach_vm.h>
#include <libkern/libkern.h>
extern vm_map_t kernel_map; /* exported com.apple.kpi.unsupported */
#define UNUSED(arg0, ...) (void) ((void) arg0, ##__VA_ARGS__)
/*
* see:
@leiless
leiless / OSBundleLibraries.plist
Last active October 13, 2018 13:47
All dependencies for generic kernel extension(C)
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.kpi.bsd</key>
<string>8.0b1</string>
<key>com.apple.kpi.libkern</key>
<string>8.0d0</string>
<key>com.apple.kpi.mach</key>
<string>8.0d0</string>
<key>com.apple.kpi.dsep</key>
<string>8.0b1</string>
/*
* Created 181013
*/
#include <mach/mach_types.h>
#include <libkern/libkern.h>
#include <sys/mount.h>
#include <sys/vnode.h>
#define KEXTNAME_S "fs_iterator"
#define LOG(fmt, ...) printf(KEXTNAME_S ": " fmt "\n", ##__VA_ARGS__)
@leiless
leiless / mk_ei_capitan_iso.sh
Last active October 26, 2018 05:51
Make bootable EI Capitan 10.11.6 iso
#!/bin/sh
#
# Created 181026
#
if [ $# -ne 1 ]; then
cat << EOL
Usage:
$(basename $0) installer_app
EOL
@leiless
leiless / mk_yosemite_iso.sh
Created October 26, 2018 05:52
Make bootable Yosemite 10.10.5 iso
#!/bin/sh
#
# Created 181026
#
if [ $# -ne 1 ]; then
cat << EOL
Usage:
$(basename $0) installer_app
EOL
/**
* Strong version of atomic compare-and-swap
* @p pointer to cas with
* @o old value
* @n new value
* @return true if success false o.w.
* see: http://donghao.org/2015/01/30/128bit-atomic-operation-in-arm64
*
* NOTE: GCC-compatible available only
*/
/*
* Created 181102
*/
#include <libkern/OSAtomicDeprecated.h>
static volatile int __spin;
#define spin_lock() while (!OSAtomicCompareAndSwapInt(0, 1, &__spin)) continue
#define spin_unlock() do { \
bool ok = OSAtomicCompareAndSwapInt(1, 0, &__spin); \
NSCAssert(ok == 1, @"spin_unlock() failure"); \
@leiless
leiless / IntelliJ_Idea_retrial.sh
Created November 9, 2018 05:40
Retrial IntelliJ Idea 2018.2(macOS only)
#!/bin/sh
set -e
rm -f ~/Library/Preferences/IntelliJIdea2018.2/eval/idea182.evaluation.key
@leiless
leiless / is_u8path_valid.c
Last active November 23, 2018 09:39
Check if a given UTF8-encoded path is valid
#include <assert.h>
/**
* Check if a given UTF8-encoded path is valid
* @return empty string yield false
* see:
* https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#naming-conventions
* https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/CharUtils.java#L438
*/
static inline bool is_u8path_valid(const register char * __nonnull p)