Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@stephancasas
stephancasas / NSScreen+MenuBarHeights.h
Created July 1, 2024 20:59
An extension on NSScreen providing menubar dimensions across various system states.
//
// NSScreen+MenuBarHeights.h
//
//
// Created by Stephan Casas on 6/26/24.
//
@import Foundation;
@import AppKit;
@stephancasas
stephancasas / Process+InteractiveEscalation.swift
Created June 27, 2024 00:25
Synchronously prompt the user for permission to dispatch a new privilege-escalated Process.
//
// Process+InteractiveEscalation.swift
//
//
// Created by Stephan Casas on 6/26/24.
//
import Foundation;
import OSAKit;
@stephancasas
stephancasas / MachServiceLaunchInfo.swift
Created June 26, 2024 22:20
A type representing a Mach service's launchd info property list
//
// MachServiceLaunchInfo.swift
//
//
// Created by Stephan Casas on 6/26/24.
//
import Foundation;
/// A type representing a Mach service's `launchd` information property list.
@stephancasas
stephancasas / Bundle+EmbeddedData.swift
Created June 26, 2024 22:14
Extract embedded data from a MachO executable at runtime.
//
// Bundle+EmbeddedData.swift
//
//
// Created by Stephan Casas on 6/26/24.
//
import Foundation;
extension Bundle {
@stephancasas
stephancasas / sysctl_inet_ports_list_copy.swift
Last active June 13, 2024 22:33
Get a list of macOS' in-use network ports.
import Foundation;
/// Copy the list of in-use network ports — optionally filtering by the ports' state.
/// - Parameters:
/// - buffer: The buffer into which the port list will populate
/// - state: The port state by which to filter.
/// - Returns: Expect `KERN_SUCCESS` if the operation was successful.
@discardableResult
func sysctl_inet_ports_list_copy(_ buffer: UnsafeMutablePointer<[UInt16]>, _ state: Int32? = nil) -> kern_return_t {
var kern_return: kern_return_t;
@stephancasas
stephancasas / NSColor+HexString.swift
Last active May 22, 2024 15:51
An extension on NSColor — offering initialization from and conversion to HEX string representations
//
// NSColor+HexString.swift
//
// Created by Stephan Casas on 5/22/24.
//
import Foundation;
import AppKit;
extension NSColor {
@stephancasas
stephancasas / MachVMReadWrite.swift
Last active April 25, 2024 17:18
Modern utility functions for Mach task read/write operations.
//
// MachVMReadWrite.swift
//
// Created by Stephan Casas on 4/25/24.
//
import Foundation;
/// Starting at the given address, read the byte values into the given buffer.
/// - Parameters:
@stephancasas
stephancasas / NSViewReader.swift
Last active April 14, 2024 16:19
A SwiftUI view that can reliably access outer or inner instances of SwiftUI-managed NSView objects.
//
// NSViewReader.swift
//
// Created by Stephan Casas on 4/11/24.
//
import SwiftUI;
import AppKit;
import Combine;
@stephancasas
stephancasas / NSManagedObject+DynamicBindings.swift
Created March 31, 2024 21:07
Syntactically-clean and portable SwiftUI bindings for optional properties on CoreData entities.
//
// NSManagedObject+DynamicBindings.swift
//
// Created by Stephan Casas on 3/31/24.
//
import SwiftUI;
import CoreData;
protocol DynamicBindings: NSManagedObject { }
@stephancasas
stephancasas / DumbHTTPServer.swift
Created March 29, 2024 16:28
A low-level HTTP server offering a SwiftUI-observable lifecycle.
//
// DumbHTTPServer.swift
// DumbHTTPServer
//
// Created by Stephan Casas on 3/29/24.
//
import SwiftUI;
import Combine;