Skip to content

Instantly share code, notes, and snippets.

@libcrack
Created May 9, 2024 01:37
Show Gist options
  • Select an option

  • Save libcrack/db4fe1333a2891b4f8c06aa0b433c66f to your computer and use it in GitHub Desktop.

Select an option

Save libcrack/db4fe1333a2891b4f8c06aa0b433c66f to your computer and use it in GitHub Desktop.
Script to unpack HPE iLO scexe firmware files
#!/usr/bin/env bash
# [email protected]
# Thu May 9 02:27:35 CEST 2024
# This script unpacks HPE iLO4 firmware scexe files
if [[ $# -ne 1 ]]; then
printf "Usage: $0 <CP053894.scexe>\n"
exit 1
fi
if [[ $# -eq 1 ]]; then
scexe="${1}"
printf "Using firmware update file \e[1m${1}\e[0m\n"
fi
if [[ ! -r "${scexe}" ]]; then
printf "\e[31mERROR:\e[0m Cannot locate file \"${scexe}\"\n"
exit 2
fi
dirname="${scexe%.*}"
line_total="$(wc -l "${scexe}" | awk '{print $1}')"
line_nr="$(grep -a -n '^Die $_RESULT;' "${scexe}" | cut -f1 -d:)"
line_offset="$((line_total-line_nr+1))"
printf "> line_total: $line_total\n"
printf "> line_nr: $line_nr\n"
printf "> line_offset: $line_offset\n"
printf "Extracting firmware from \e[1m${scexe}\e[0m to temp file ${$}\n"
tail -n "${line_offset}" "${scexe}" > "${$}" # scexe_tmp19058.gz
printf "Infering original filename from ${$}\n"
original_filename="$(file "${$}" | cut -f2 -d, | tr -d '"' | awk '{print $2}')"
gzip_filename="${original_filename}.gz"
if [[ -z "${original_filename}" ]]; then
printf "\e[31mERROR:\e[0m Cannot infer original filename from ${$}\n"
rm "${$}"
exit 3
fi
printf "Moving temp file ${$} to \e[1m${gzip_filename}\e[0m\n"
mv "${$}" "${gzip_filename}"
if [[ ! -r "${gzip_filename}" ]]; then
printf "\e[31mERROR:\e[0m Cannot create file \"${gzip}\"\n"
rm "${$}"
exit 4
fi
if [[ -d "${dirname}" ]]; then
printf "\e[31mERROR:\e[0m Directory \"${dirname}\" already exists\n"
rm "${gzip_filename}"
exit 5
fi
printf "Creating directory \e[1m${dirname}\e[0m\n"
mkdir "${dirname}"
printf "Unpacking ${gzip_filename} to \e[1m${dirname}\e[0m\n"
tar xvzf "${gzip_filename}" -C "${dirname}"
printf "Deleting tarball \e[1m${gzip_filename}\e[0m\n"
rm "${gzip_filename}"
printf "Firmware successfully extracted to \e[1m${dirname}\e[0m\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment