Skip to content

Instantly share code, notes, and snippets.

View gsuberland's full-sized avatar

Graham Sutherland gsuberland

View GitHub Profile
@gsuberland
gsuberland / freenas_influxdb_disk_temperatures.sh
Created March 10, 2020 18:38
FreeNAS Influxdb Disk Temperature Script with NVMe Support
#!zsh
# FreeNAS Influxdb disk temperature script with NVMe support.
# For regular disks, sends the Temperature_Celsius value reported by /dev/daX and /dev/adaX devices.
# For NVMe disks, sends all temperature sensor values reported by /dev/nvmeX devices.
# Written by Graham Sutherland (gsuberland)
# https://github.com/gsuberland/
influxdb_db="graphite"
@gsuberland
gsuberland / freenas_disk_temp_monitor.py
Created June 26, 2020 19:08
FreeNAS Disk Temperature Monitoring
#!/usr/local/bin/python3
import curses
from curses import wrapper
import math
import time
import psutil
from pySMART import DeviceList, Device
REFRESH_INTERVAL = 10
@gsuberland
gsuberland / esp_dht22.ino
Created June 30, 2020 21:06
ESP8266 DHT22 Environmental Sensors for use with Prometheus
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "ssid";
const char* password = "password";
const char* hostname = "esp_dht22_bedroom";
@gsuberland
gsuberland / interrupts.h
Created July 4, 2020 05:11
Arduino interrupt template magic thing
#ifndef __INCLUDE_INTERRUPTS_H__
#define __INCLUDE_INTERRUPTS_H__
#include "Arduino.h"
#include <algorithm>
typedef void (*ISRFunctionPtr)();
@gsuberland
gsuberland / chessboard_puzzle.cs
Last active July 6, 2020 19:34
Chessboard Puzzle Solver
using System;
using System.Collections;
namespace ChessboardPuzzle
{
static class Program
{
static void Main()
{
// Inspired by 3blue1brown's excellent video on the topic: https://www.youtube.com/watch?v=wTJI_WuZSwE
@gsuberland
gsuberland / interrupt_handlers.S
Created April 10, 2021 21:49
ISR auto-generation with default handlers, in GCC AS
.intel_syntax noprefix
.altmacro
.section .data
.align 4
.globl KernelInterruptContext
KernelInterruptContext:
.long 0 // eax
.long 0 // ebx
.long 0 // ecx
@gsuberland
gsuberland / excel_shared_workbook_hash.cs
Created July 17, 2021 16:37
Excel reserved file sharing hash function (C#)
/*
This computes the 16-bit hash used to protect Excel workbooks through most versions.
When trying to open such a sheet for editing, you'll get a message such as:
blah.xlsx is reserved by [user]. Enter password for write access, or open read only.
In xl\workbook.xml the hash is stored as follows: <fileSharing userName="user" reservationPassword="ABCD" />
In that case, you'd compare the output of the hash function to 0xABCD.
For 99% of cases you can just throw a wordlist like rockyou at any hash and it'll spit out hundreds of collisions.
@gsuberland
gsuberland / le_exe_headers.h
Created August 28, 2021 03:56
Linear Executable (LE) file format structures
// ref: http://fileformats.archiveteam.org/wiki/Linear_Executable
// ref: https://moddingwiki.shikadi.net/wiki/Linear_Executable_(LX/LE)_Format
// ref: https://github.com/open-watcom/open-watcom-v2/blob/master/bld/watcom/h/exeflat.h (this is specifically for LE VXDs)
// ref: http://www.textfiles.com/programming/FORMATS/lxexe.txt (comprehensive but actually for LX, not LE)
typedef unsigned char undefined;
typedef unsigned char byte;
typedef unsigned long dword;
typedef unsigned long uint3;
@gsuberland
gsuberland / le_exe_dumper.cs
Created August 28, 2021 04:02
Linear Executable (LE) EXE header dumper for mixed 16/32-bit VXDs
// dump LE EXE headers for mixed 16/32-bit VXDs
// ref: https://faydoc.tripod.com/formats/exe-LE.htm
// ref: https://github.com/open-watcom/open-watcom-v2/blob/master/bld/watcom/h/exeflat.h
// ref: http://www.textfiles.com/programming/FORMATS/lxexe.txt (this is for LX, not LE, but layout is roughly the same)
enum Endianness : byte
{
LittleEndian = 0,
BigEndian = 1
@gsuberland
gsuberland / icm_handle_leak_fix.cpp
Last active October 13, 2021 12:55
Extremely hacky solution to close leaked handles in mscms.dll!OpenDisplay
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1201106
// see: https://twitter.com/gsuberland/status/1445547814965055488
#include <Windows.h>
#include <stdio.h>
#include <TlHelp32.h>
#include <memory>
#include <cassert>
#include <vector>