Skip to content

Instantly share code, notes, and snippets.

Avatar

Joel Bruner brunerd

View GitHub Profile
@brunerd
brunerd / kcpasswordDecode.sh
Last active Sep 18, 2021
De-obfuscates macOS /etc/kcpassword file used for automatic login
View kcpasswordDecode.sh
#!/bin/bash
#kcpasswordDecode (20210911) Copyright (c) 2021 Joel Bruner (https://github.com/brunerd)
#Licensed under the MIT License
#input a string to decode as argument $1 or to read in a file call like this:
#kcpasswordDecode.sh "$(< filepath)"
#given a string from /etc/kcpassword will XOR it back and truncate padding
function kcpasswordDecode {
@brunerd
brunerd / kcpasswordEncode.sh
Last active Sep 11, 2021
Encode a string for use in macOS /etc/kcpassword using shell, printf, sed, awk and xxd
View kcpasswordEncode.sh
#!/bin/bash
#kcpasswordEncode (20210911) Copyright (c) 2021 Joel Bruner (https://github.com/brunerd)
#Licensed under the MIT License
#given a string creates data for /etc/kcpassword
function kcpasswordEncode {
#ascii string
local thisString="${1}"
local i
@brunerd
brunerd / kcpasswordEncode_perl.sh
Created Aug 24, 2021
Encode password for macOS /etc/kcpassword (does not handle blank passwords)
View kcpasswordEncode_perl.sh
#!/bin/bash
function kcpasswordEncode_perl {
local PASSWORD="${1}";
#one-liner variation of Gavin Brock's kcpassword.pl
perl -ne 'sub kcpassword_xor { my ($pass)=@_; my @key=qw( 125 137 82 35 210 188 221 234 163 185 31 ); my $key=pack "C*", @key; my $key_len=length $key; for (my $n=0; $n<length($pass); $n+=$key_len) { substr($pass,$n,$key_len) ^= $key; }; return $pass; }; $userinput = $_; chomp ($userinput); print(kcpassword_xor($userinput));' <<< "${PASSWORD}"
}
kcpasswordEncode_perl "${1}"
@brunerd
brunerd / CFAbsoluteTime_Unix_Epoch.sh
Created Aug 2, 2021
Working with CFAbsoluteTime and epoch time in shell
View CFAbsoluteTime_Unix_Epoch.sh
#work with CFAbsoluteTime in shell
#https://developer.apple.com/documentation/corefoundation/cfabsolutetime
#https://developer.apple.com/documentation/corefoundation/1543542-cfabsolutetimegetcurrent
#get epoch time for CFAbsoluteTime 0 (978307200)
#same as the constant kCFAbsoluteTimeIntervalSince1970 in https://github.com/opensource-apple/CF/blob/master/CFDate.c
/bin/date -j -f "%b %d %T %Z %Y" "Jan 1 00:00:00 GMT 2001" "+%s"
#Now in CFAbsoluteTime
echo $(( $(date +"%s") - 978307200 ))
@brunerd
brunerd / macOSScreenLockDetection.sh
Created Mar 20, 2021
Detect the macOS CoreGraphics Screen Lock status of the console user via ioreg
View macOSScreenLockDetection.sh
#!/bin/sh
#Joel Bruner (https://github.com/brunerd)
function screenIsLocked { [ "$(/usr/libexec/PlistBuddy -c "print :IOConsoleUsers:0:CGSSessionScreenIsLocked" /dev/stdin 2>/dev/null <<< "$(ioreg -n Root -d1 -a)")" = "true" ] && return 0 || return 1; }
function screenIsUnlocked { [ "$(/usr/libexec/PlistBuddy -c "print :IOConsoleUsers:0:CGSSessionScreenIsLocked" /dev/stdin 2>/dev/null <<< "$(ioreg -n Root -d1 -a)")" != "true" ] && return 0 || return 1; }
if screenIsLocked; then
echo "Screen locked"
fi
@brunerd
brunerd / macOSCompatibilityMatrix.csv
Last active Jan 27, 2021
CSV of macOS compatibility and Apple Hardware (Intel and Apple Silicon) and VMs created with macOSCompatibility.sh
View macOSCompatibilityMatrix.csv
ModelID 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13 10.14 10.15 11
iMac4,1 10.4 10.5 10.6
iMac4,2 10.4 10.5 10.6
iMac5,1 10.4 10.5 10.6 10.7
iMac5,2 10.4 10.5 10.6 10.7
iMac6,1 10.4 10.5 10.6 10.7
iMac7,1 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11
iMac8,1 10.5 10.6 10.7 10.8 10.9 10.10 10.11
iMac9,1 10.5 10.6 10.7 10.8 10.9 10.10 10.11
iMac10,1 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13
@brunerd
brunerd / csv2csv.function.min.no_help.sh
Last active Dec 18, 2020
Minified, functionalized version of Lorance Stinson's csv2csv shell utility minus the help, truly a one-liner
View csv2csv.function.min.no_help.sh
#!/bin/sh
# csv2csv.function.min.no_help
# csv2csv by Lorance Stinson, 2007
# This file is in the public domain.
# For more information email LoranceStinson+csv@gmail.com.
# Or see http://lorance.freeshell.org/csvutils/
# Additions by Joel Bruner, 2020 (https://github.com/brunerd)
#csv2csv function minified
function csv2csv { IFS=$' \t\n'; local NL=$'\n'; local TAB=$'\t';local CSV_ESCAPE=${CSV_ESCAPE:='"'}; local CSV_SEPARATOR=${CSV_SEPARATOR:=","}; local CSV_QUOTE=${CSV_QUOTE:='"'}; local OCSV_ESCAPE=${CSV_ESCAPE:='"'}; local OCSV_SEPARATOR=${CSV_SEPARATOR:=","}; local OCSV_QUOTE=${CSV_QUOTE:='"'}; local FILE="-"; local NL_TEXT=""; local NUM_COLS=""; local OUTPUT=""; local QUOTE_LEVEL="0"; local SKIP_ROWS="0"; local TAB_TEXT=""; while [ "$#" -gt 0 ] ; do case "$1" in -c) [ "$2" ] && local COL_LIST="$2" || usage="$1 requires an argument."; shift 2;; -e) [ "$2" ] && CSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -E) [ "$2" ] && OCSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -h
@brunerd
brunerd / csv2csv.function.min.sh
Last active Dec 18, 2020
Minified, functionalized version of Lorance Stinson's csv2csv shell utility
View csv2csv.function.min.sh
#!/bin/sh
# csv2csv.function.min
# csv2csv by Lorance Stinson, 2007
# This file is in the public domain.
# For more information email LoranceStinson+csv@gmail.com.
# Or see http://lorance.freeshell.org/csvutils/
# Additions by Joel Bruner, 2020 (https://github.com/brunerd)
#csv2csv function minified
function csv2csv { IFS=$' \t\n'; local NL=$'\n'; local TAB=$'\t';local CSV_ESCAPE=${CSV_ESCAPE:='"'}; local CSV_SEPARATOR=${CSV_SEPARATOR:=","}; local CSV_QUOTE=${CSV_QUOTE:='"'}; local OCSV_ESCAPE=${CSV_ESCAPE:='"'}; local OCSV_SEPARATOR=${CSV_SEPARATOR:=","}; local OCSV_QUOTE=${CSV_QUOTE:='"'}; local FILE="-"; local NL_TEXT=""; local NUM_COLS=""; local OUTPUT=""; local QUOTE_LEVEL="0"; local SKIP_ROWS="0"; local TAB_TEXT=""; while [ "$#" -gt 0 ] ; do case "$1" in -c) [ "$2" ] && local COL_LIST="$2" || usage="$1 requires an argument."; shift 2;; -e) [ "$2" ] && CSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -E) [ "$2" ] && OCSV_ESCAPE="$2" || usage="$1 requires an argument."; shift 2;; -h) usage=
@brunerd
brunerd / Malformed-macOS-11.1.csv
Created Dec 16, 2020
macOS JSON files that fail to parse with json_pp (but jpt can parse them)
View Malformed-macOS-11.1.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
Status,Issue Notes,Path,Error Output
ERROR,"""JSON Lines""/Concatenated",/System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/Resources/defaultConfig.json,"garbage after JSON object, at character offset 143 (before """"addTransform"":{""uui..."") at /usr/bin/json_pp5.28 line 44."
ERROR,*** Comment ***,/private/var/db/ionodecache.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before ""*** Device Tree ***\n..."") at /usr/bin/json_pp5.28 line 44."
ERROR,# comment,/System/Library/CoreServices/Pass Viewer.app/Contents/Library/SharedWebCredentials/wallet.apple.com.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 210 (before ""]\n }]\n }..."") at /usr/bin/json_pp5.28 line 44."
ERROR,# comment,/System/Library/Frameworks/GameController.framework/Versions/A/Resources/XboxHapticCapabilityGraph.json,"unexpected end of string while parsing JSON string, at character offset 500 (before "",\n {\
@brunerd
brunerd / Malformed-macOS-10.15.csv
Last active Dec 16, 2020
macOS JSON files that fail to parse with json_pp (but jpt can parse them)
View Malformed-macOS-10.15.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 4 columns, instead of 3. in line 5.
Status,Issue Notes,Path,Error Output
ERROR,"""JSON Lines""/Concatenated",/System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/Resources/defaultConfig.json,"garbage after JSON object, at character offset 143 (before """"addTransform"":{""uui..."") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Comma,/Library/Developer/CommandLineTools/usr/lib/swift/migrator/overlay4.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 41290 (before ""]\n"") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Comma,/Library/Developer/CommandLineTools/usr/lib/swift/migrator/overlay42.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 608 (before ""]\n"") at /usr/bin/json_pp5.18 line 45."
ERROR,*** Comment ***,/private/var/db/ionodecache.json,"malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before ""*** Device Tree ***\n..."") at /usr/bin/json_pp5.18 line 45."
ERROR,Trailing Commas,/S