Skip to content

Instantly share code, notes, and snippets.

@FirstLoveLife
Created May 7, 2025 08:21
Show Gist options
  • Save FirstLoveLife/66407c26d82458281819d75d1e92b171 to your computer and use it in GitHub Desktop.
Save FirstLoveLife/66407c26d82458281819d75d1e92b171 to your computer and use it in GitHub Desktop.
dump_spcr
#!/usr/bin/env bash
# dump_spcr.sh: Dump and decompile the ACPI SPCR table
set -euo pipefail
usage() {
cat <<EOF
Usage: $(basename "$0") -o OUTPUT_PREFIX
Options:
-o OUTPUT_PREFIX Prefix for output files (e.g., /tmp/spcr)
Generates two files:
OUTPUT_PREFIX.dat (binary SPCR table)
OUTPUT_PREFIX.dsl (ASL disassembly)
EOF
exit 1
}
# Parse options
while getopts ":o:" opt; do
case "$opt" in
o) output_prefix="$OPTARG" ;;
*) usage ;;
esac
done
# Check that -o was provided
if [[ -z ${output_prefix:-} ]]; then
usage
fi
# Path to SPCR table
table_path="/sys/firmware/acpi/tables/SPCR"
if [[ ! -r "$table_path" ]]; then
echo "Error: SPCR table not found at $table_path" >&2
exit 2
fi
# Dump binary table
echo "Dumping binary SPCR to ${output_prefix}.dat..."
sudo cp "$table_path" "${output_prefix}.dat"
# Disassemble to ASL
echo "Disassembling to ASL ${output_prefix}.dsl..."
# iasl expects options before input file: -d (disassemble), -p (prefix)
sudo iasl -d -p "${output_prefix}" "${output_prefix}.dat"
echo "Done."
echo "Binary: ${output_prefix}.dat"
echo "ASL: ${output_prefix}.dsl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment