Skip to content

Instantly share code, notes, and snippets.

@devanlai
devanlai / read-static-shell-commands.py
Created March 15, 2022 02:18
Sample script to parse Zephyr shell command trees from an ELF file
#!/usr/bin/python
"""
Parse a Zephyr firmware ELF file to extract its statically registered
shell commands using the linker section data structure.
This script requires pyelftools, which can be installed using:
pip install pyelftools
"""
@devanlai
devanlai / __init__.py
Created April 12, 2020 18:28
WIP pure-python sigrok decoder host
__all__ = ["Decoder", "OUTPUT_ANN", "OUTPUT_PYTHON", "OUTPUT_BINARY", "OUTPUT_META", "SRD_CONF_SAMPLERATE"]
from .decoder import Decoder
from .constants import OUTPUT_ANN, OUTPUT_PYTHON, OUTPUT_BINARY, OUTPUT_META, SRD_CONF_SAMPLERATE
@devanlai
devanlai / ssh-via-dns-proxy.sh
Last active April 9, 2020 20:27
Script to resolve a target host via secondary SSH host, then ssh to the target IP directly
#!/bin/bash
# Utility script to first resolve the IP address of the target host to SSH into
# by SSHing into a secondary proxy host. For example, this can be used when
# the origin host does not support resolving names via mDNS, but the jump host
# does, while avoiding the overhead of routing the SSH connection through the
# jump host when the origin and target are already both in the same network.
set -e
set -o pipefail
@devanlai
devanlai / test_unconfigured_device_request.html
Created December 3, 2019 04:26
WebUSB descriptor read test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebUSB Control Transfer Request to Device Endpoint while unconfigured</title>
<script>
async function readDeviceDescriptor(device) {
const GET_DESCRIPTOR = 0x06;
const DT_DEVICE = 0x01;
@devanlai
devanlai / svd-dump.py
Last active March 3, 2023 11:03
gdb script for dumping STM32 registers
"""
Utilities for dumping STM32 peripheral registers with tab-completion
Based on a script by vampi-the-frog
Dependencies:
pip install -U cmsis-svd
Usage (inside gdb):
(gdb) source /path/to/svd-dump.py
@devanlai
devanlai / can.targets.md
Last active August 29, 2015 14:18
mbed targets with CAN enabled
def slice_arg(string):
try:
if ":" in string:
parts = string.split(":")
args = []
for part in parts:
if not part.strip():
args.append(None)
else:
args.append(int(part))