Skip to content

Instantly share code, notes, and snippets.

View Brandon7CC's full-sized avatar
🌉

Brandon Dalton Brandon7CC

🌉
View GitHub Profile
@Brandon7CC
Brandon7CC / graph_list_messages.ps1
Created October 16, 2024 22:08
List emails in at a target email using the Graph REST `mailbox/messages` API
$secretsFilePath = "secrets.json"
if (-Not (Test-Path -Path $secretsFilePath)) {
Write-Output "secrets.json not found... creating..."
$tenantId = Read-Host -Prompt "Enter your Tenant ID"
$clientId = Read-Host -Prompt "Enter your Client ID"
$clientSecret = Read-Host -Prompt "Enter your Client Secret"
$secretsContent = @{
tenantId = $tenantId
clientId = $clientId
@Brandon7CC
Brandon7CC / pyenv_ubuntu.sh
Last active September 13, 2024 16:45
Install `pyenv` on Linux in Bash shell.
#!/usr/bin/env bash
# Update package lists
sudo apt update
# Install dependencies for building Python versions
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils \
tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
@Brandon7CC
Brandon7CC / archive_utility_types.py
Last active August 30, 2024 12:17
(Reference POSIX AtomicTestHarnesses) Returns the list of file types supported by `Archive Utility.app`.
#
# Brandon Dalton
# Date: 20240828 / Original Red Canary ATH 20240116
#
# Description: Returns the list of supported file types (CFBundleDocumentTypes) in Archive Utility.app
# Reference: https://github.com/redcanaryco/AtomicTestHarnesses/blob/6b00e8f41062da2c424ab4e7ec71bd3ec3a6f112/posix/src/posixath/utils/common.py#L530
#
import os
import json
@Brandon7CC
Brandon7CC / x2p.c
Created April 10, 2024 23:53
Given an XPC service name return the program's path using the mach bootstrap port to talk to `launchd` over an XPC pipe.
//
// x2p.c
// MachXPC
//
// Created by Brandon Dalton on 04/09/2024.
//
#include <xpc/xpc.h>
#include <stdio.h>
#include <stdlib.h>
@Brandon7CC
Brandon7CC / lzfse_compress.swift
Created April 8, 2024 16:53
Compress a string with LZFSE
import Foundation
import Compression
import OSLog
// Compress JSON representation with the Apple recommended compression algo LZFSE
// https://developer.apple.com/documentation/compression/algorithm/lzfse
public func getCompressedJSON(from jsonString: String) -> Data {
var sourceBuffer = Array(jsonString.utf8)
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: jsonString.count)
let algorithm = COMPRESSION_LZFSE
@Brandon7CC
Brandon7CC / SystemConfigurationHelpers.swift
Created April 8, 2024 04:07
What SIP flags are enabled / disabled on macOS using the csr_get_active_config and csr_check syscalls?
//
// csr_check.swift
// csr_check
//
// Created by Brandon Dalton on 01/11/24.
//
// Compile: `swiftc -import-objc-header SystemConfig-Bridging-Header.h csr_check.swift -o csr_check.o`
//
import Foundation
@Brandon7CC
Brandon7CC / FileMetadataHelpers.swift
Created April 6, 2024 04:40
Given a file path is this file quarantined? To do this we use `getxattr` and look for `com.apple.quarantine` which is applied by File Quarantine-aware applications.
//
// FileMetadataHelpers.swift
// FileMetadataHelpers
//
// Created by Brandon Dalton on 10/7/23.
//
import Foundation
/// Helper functions for working with file metadata.
@Brandon7CC
Brandon7CC / chrome_page_save.zsh
Created March 24, 2024 23:33
Google Chrome page save after JS
#!/bin/zsh
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--headless --incognito --dump-dom https://github.com > /tmp/github.html
@Brandon7CC
Brandon7CC / gcloud_install.sh
Created January 4, 2024 03:01
Install Google Cloud Command Line Interface (gcloud CLI)
#!/bin/sh
# Set up `gcloud` cli on macOS and Linux
# Check which OS we're on
if [[ "$OSTYPE" == "linux-gnu" ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="darwin"
else
echo "Unsupported OS: $OSTYPE"
@Brandon7CC
Brandon7CC / speak_ollama.sh
Created December 29, 2023 23:38
📣 Giving Ollama a voice with the macOS `say` command! NOTE: Change to Siri in `System Settings.app` for the best results.
function speak_ollama() {
if ! command -v ollama &> /dev/null; then
echo "Error: ollama is not installed."
return 1
fi
if [ "$#" -ne 2 ]; then
echo "Usage: speak_ollama <file_path> <model>"
return 1
fi