Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / lowrez.py
Created November 8, 2016 21:57
Enable the "Open in Low Resolution" setting for an arbitrary application in macOS
#!/usr/bin/python
# Some notes about using this script:
# - Configure the application path and bundle id below
# - This script needs to be run as the user you need to set the checkmark for
# - The setting will not take effect until they log out and log back in at least once
import os.path
from Foundation import NSHomeDirectory, CFPreferencesCopyMultiple, CFPreferencesSetMultiple, kCFPreferencesAnyUser, kCFPreferencesCurrentHost, NSMutableDictionary, NSURL, NSURLBookmarkCreationMinimalBookmark, NSMutableArray
@pudquick
pudquick / nvram.py
Created November 3, 2016 16:29
Get nvram values via python and pyobjc on macOS
import objc
from Foundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [
("IORegistryEntryFromPath", b"II*"),
("IORegistryEntryCreateCFProperty", b"@I@@I"),
]
@pudquick
pudquick / ldap_ping_decoder.swift
Last active March 26, 2017 00:35
This is a quick-n-dirty implementation of decoding the LDAP Ping netlogon response in Swift
import Foundation
//-------------------------------------------------------
// this is just setup / test environment stuff
// we would normally have the output from ldapsearch here
//-------------------------------------------------------
let fakeout = "netlogon: FwAA...\n" +
" lYXMw...........\n" +
" bGFy......="
@pudquick
pudquick / remove_bt.py
Created October 7, 2016 19:53
Remove all Bluetooth devices from OS X / macOS in the style of the Bluetooth debug menu "Remove all devices" with python and pyobjc
#!/usr/bin/python
from Foundation import NSBundle
IOBluetooth = NSBundle.bundleWithIdentifier_('com.apple.Bluetooth')
IOBluetoothDevice = IOBluetooth.classNamed_('IOBluetoothDevice')
# remove configured devices
try:
devices = list(IOBluetoothDevice.configuredDevices())
except:
@pudquick
pudquick / google_chrome_update_checker.py
Last active February 10, 2025 04:36 — forked from bruienne/google_chrome_update_checker.py
Basic concept for querying for Google Chrome updates based on current Chrome version/OS/arch
#!/usr/bin/python
import xml.etree.ElementTree as ET
import requests
import uuid
params = {'cup2hreq': 'foo', 'cup2key': 'bar'}
platform = 'mac'
os_version = '10.12'
@pudquick
pudquick / statfs.py
Last active August 27, 2020 05:10
Calling statfs from python on OS X via ctypes for inspecting filesystem information
from ctypes import CDLL, Structure, c_uint32, c_int64, c_uint64, c_char, create_string_buffer, byref, c_ubyte, c_int16, c_int64, c_int32
# when _DARWIN_FEATURE_64_BIT_INODE is not defined
class statfs32(Structure):
_fields_ = [
("f_otype", c_int16),
("f_oflags", c_int16),
("f_bsize", c_int64),
("f_iosize", c_int64),
("f_blocks", c_int64),
@pudquick
pudquick / pyobjc_ctypes_bridging.py
Created September 10, 2016 19:19
An example of conversion of ctypes pointers to pyobjc objects that's compatible with pyobjc versions earlier than 2.5
# Using: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef
# Thank you to this for inspiration: https://github.com/MacLeek/trackmac/blob/master/trackmac/cocoa.py
import objc
from ctypes import CDLL, c_void_p, byref, c_char_p
from ctypes.util import find_library
from Foundation import NSMutableArray
Security = CDLL(find_library("Security"))
AuthorizationRightGet = Security.AuthorizationRightGet
@pudquick
pudquick / flag_to_string.rb
Created September 5, 2016 18:23 — forked from djberg96/flag_to_string.rb
Trying to stringify filesystem flags
require 'ffi'
class Filesystem
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function(:strerror, [:int], :string)
attach_function(:getmntinfo64, [:pointer, :int], :int)
class Statfs < FFI::Struct
@pudquick
pudquick / symfind.py
Created August 27, 2016 00:50
Automatic symbol definition discovery for OS X binaries and their linked shared libraries
#!/usr/bin/python
"""Usage: symfind BINARY_PATH SEARCH_STR
symfind automates the usage of otool and nm to attempt to find out which
binary a symbol is defined in that's used within BINARY_PATH's code.
"""
import subprocess, os.path, sys, getopt
@pudquick
pudquick / autotimezone.py
Last active February 11, 2020 15:55
Forcing automatic timezone discovery with pyobjc on OS X
# Tested on 10.11
# Assumes your network is in a state to actually do the discovery and that you have
# automatic timezone discovery enabled in Date & Time and Location services enabled
# (Generally this means wifi enabled on your device and network stack is up)
# For enabling location services and auto, check Allister's work here:
# https://gist.github.com/arubdesu/b72585771a9f606ad800
from Foundation import NSBundle
TZPP = NSBundle.bundleWithPath_("/System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/TimeZone.prefPane")