Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / lzma_decompress.py
Created April 8, 2015 21:47
Python ctypes wrapper around liblzma for the purposes of (naive) lzma file decompression, for use with OS X 10.7+
# Example usage of the function:
# decompress('somefile.pack.lzma', 'somefile.pack')
# Decompresses a lzma compressed file from the first input file path to the second output file path
import sys
from ctypes import CDLL, Structure, c_void_p, c_size_t, c_uint, c_uint32, c_uint64, create_string_buffer, addressof, sizeof, byref
class lzma_stream(Structure):
_fields_ = [
@pudquick
pudquick / AppleJRE.py
Created April 9, 2015 05:40
Use Apple's PrivateFramework "JavaLaunching" functions to determine if the Apple JRE is installed (without triggering the dialog)
import sys
from ctypes import CDLL
JavaLaunching = CDLL('/System/Library/PrivateFrameworks/JavaLaunching.framework/JavaLaunching')
if (JavaLaunching.JLIsRuntimeInstalled() == 0):
print "Apple JRE is not installed."
sys.exit(1)
else:
print "Apple JRE is installed."
sys.exit(0)
@pudquick
pudquick / bom.py
Last active November 18, 2021 15:55
Parsing of bom files in pure python
# Python routines for parsing bom files
#
# Examples so far:
#
# dump_bom(filename) - prints diagnostic structure information about bom file (including path list)
from ctypes import BigEndianStructure, c_char, c_uint8, c_uint16, c_uint32, sizeof, memmove, addressof
class BOMHeader(BigEndianStructure):
_pack_ = 1
@pudquick
pudquick / 00_explanation.md
Last active August 26, 2016 20:40
An explanation of why "createmobileaccount" breaks in OS X 10.10.3 (and why a particular workaround works)

10.10.3: createmobileaccount

Today, @osxreverser on Twitter announced their analysis of Apple's OS X 10.10.3 fix for CVE-2015-113 privilege escalation (aka "rootpipe") and an adapted unofficial fix for OS X 10.9:

https://twitter.com/osxreverser/status/587639173919727616

Apple apparently added a new private entitlement named "com.apple.private.admin.writeconfig" and made it required for calling the XPC service "writeconfig".

Shortly after 10.10.3 was released, it was discovered that the tool "createmobileaccount" (which can be used to pre-create a mobile account and home path prior to a user with network credentials logging into a machine) was no longer functioning properly.

@pudquick
pudquick / pyCacher.py
Last active September 18, 2015 16:09
Playing with parsing Server caching service logs
import tempfile, os.path, shutil, glob, os, subprocess, re
debug = True
# It should take the logs from tmp and clone them somewhere
# It can then bunzip and combine them
def log(s):
global debug
if debug:
print s
@pudquick
pudquick / gist:7bd261da0a8d731b7710
Created April 18, 2015 18:34
Pacifist extracting Ruby.framework
This file has been truncated, but you can view the full file.
mike 16214 39.8 0.0 2442144 1048 ?? S 11:04AM 0:06.65 /bin/pax -r -d -s ,^/,\./\./\./ -s ,^\.\./,PacifistPaxUnarchiverParentPlaceholder/ -s ,/\.\./,/PacifistPaxUnarchiverParentPlaceholder/ ./System/Library/Frameworks/Ruby.framework ./System/Library/Frameworks/Ruby.framework/Resources ./System/Library/Frameworks/Ruby.framework/Ruby ./System/Library/Frameworks/Ruby.framework/Versions ./System/Library/Frameworks/Ruby.framework/Versions/2.0 ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources/BridgeSupport ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources/BridgeSupport/Ruby.bridgesupport ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources/BridgeSupport/Ruby.dylib ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources/English.lproj ./System/Library/Frameworks/Ruby.framework/Versions/2.0/Resources/English.lproj/InfoPlist.strings ./System/Library/Frameworks/Ruby.framework
@pudquick
pudquick / idea.py
Created April 29, 2015 21:51
A suggestion
cmd = [pkgbuild,
"--root", root,
"--identifier", pkg_identifier,
"--version", version,
"--scripts", script_root,
pkg_output_path]
if opts.sign:
# Use slice assignment to insert an additional option before the final argument
cmd[-1:] = ["--sign", opts.sign, pkg_output_path]
@pudquick
pudquick / defaut_ip.py
Created June 2, 2015 17:17
This snippet gets you the default routing interface for a machine for general traffic
def default_interface():
# 203.0.113.1 is reserved in TEST-NET-3 per RFC5737
# Should never be local, essentially equal to "internet"
# This should get the 'default' interface
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# Uses UDP for instant 'connect' and port 9 for discard
# protocol: http://en.wikipedia.org/wiki/Discard_Protocol
s.connect(('203.0.113.1', 9))
client = s.getsockname()[0]
@pudquick
pudquick / purl.py
Last active May 14, 2020 15:44
This example builds on the Gurl class from gurl.py in munki and creates a POST variant called Purl
# Based on: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836-SW5
from gurl import *
from Foundation import NSData, NSString
class Purl(Gurl):
'''A POST variant of Gurl'''
def initWithOptions_(self, options):
'''Set up our Purl object'''
# Inherit our basic setup from Gurl
#!/usr/bin/python
# As written, this requires the following:
# - OS X 10.6+ (may not work in 10.10, haven't tested)
# - python 2.6 or 2.7 (for collections.namedtuple usage, should be fine as default python in 10.6 is 2.6)
# - pyObjC (as such, recommended to be used with native OS X python install)
# Only tested and confirmed to work against 10.9.5
# Run with root