Skip to content

Instantly share code, notes, and snippets.

View justenwalker's full-sized avatar

Justen Walker justenwalker

View GitHub Profile
@justenwalker
justenwalker / string_convert_windows.go
Last active July 31, 2020 02:49
Convert Go strings to C-compatible strings for Windows API Calls
package win32
import "unicode/utf16"
// StringToCharPtr converts a Go string into pointer to a null-terminated cstring.
// This assumes the go string is already ANSI encoded.
func StringToCharPtr(str string) *uint8 {
chars := append([]byte(str), 0) // null terminated
return &chars[0]
}
@justenwalker
justenwalker / get_extended_tcp_table_windows.go
Last active June 20, 2021 16:14
Call Windows API for GetExtendedTcpTable and return a Byte Buffer containing the result.
package win32
import (
"syscall"
"unsafe"
)
var (
iphlpapiDLL = syscall.NewLazyDLL("iphlpapi.dll")
procGetExtendedTcpTable = iphlpapiDLL.NewProc("GetExtendedTcpTable")
@justenwalker
justenwalker / raw_tcp_table_iterate_windows.go
Last active January 10, 2019 03:57
Iterate through each array entry using unsafe.Pointer arithmetic
rows := make([]_MIB_TCPROW_OWNER_PID,int(pTable.dwNumEntries))
for i := 0; i < int(pTable.dwNumEntries); i++ {
rows[i] = *(*_MIB_TCPROW_OWNER_PID)(unsafe.Pointer(
uintptr(unsafe.Pointer(&pTable.table[0])) +
uintptr(i) * unsafe.Sizeof(pTable.table[0])
))
}
@justenwalker
justenwalker / boxstarter.ps1
Last active November 1, 2019 03:32
Boxstarter Script
# Based off https://gist.github.com/jessfraz/7c319b046daa101a4aaef937a20ff41f
$gistContent = "https://gist.githubusercontent.com/justenwalker/25211c0fa10ddd705a3f6077e2b7694c"
#--- Function Library ---#
# New-RegistryKey creates the specified registry key if it does not exist
# It will recursively create any parent keys
function New-RegistryKey
{
@justenwalker
justenwalker / gpg-gen.sh
Last active October 21, 2021 19:22
Generate ECC GPG Key
#!/bin/bash
# Usage: gpg-gen.sh
#
# Generates a new ECC GPG Key with a random passphrase
# It will output the resulting keys to ~/gpg-keys/
# You should save these somewhere safe like 1Password
set -euo pipefail
PRIMARY_KEY_EXPIRATION=3y
@justenwalker
justenwalker / direnv_prune.sh
Last active October 3, 2022 13:11
Direnv Prune Allow List
# removes direnv allow entries which point to nonexistent .envrc files
# or where the hash of the envrc does not match
direnv_prune () {
for entry in ~/.local/share/direnv/allow/*
do
local file=$(cat $entry)
if [ ! -f $file ]
then
rm $entry
else