11#! /usr/bin/env bash
2+ source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /../lib.sh"
23
34# These variables are all for the deguard tool.
45# They would need to be changed if using the tool for other devices with different ME version...
@@ -9,7 +10,7 @@ ME_pch="H"
910
1011
1112# Integrity checks for the vendor provided ME blob...
12- DL_HASH =" de26085e1fbfaaa0302ec73dba411a5fd25fe13ae07e69a2287754ada6a7a196"
13+ ME_DOWNLOAD_HASH =" de26085e1fbfaaa0302ec73dba411a5fd25fe13ae07e69a2287754ada6a7a196"
1314
1415# ...and the cleaned and deguarded version from that blob.
1516DEGUARDED_ME_BIN_HASH=" 9c3eff6be017b36c819a0df3c1f6537bb26b6f3d5780787f60b91cedc789f0f0"
@@ -23,28 +24,6 @@ Download Intel ME firmware from ASRock, neutralize and shrink keeping the MFS.
2324"
2425}
2526
26- function chk_sha256sum() {
27- sha256_hash=" $1 "
28- filename=" $2 "
29- echo " $sha256_hash " " $filename " " $( pwd) "
30- sha256sum " $filename "
31- if ! echo " ${sha256_hash} ${filename} " | sha256sum --check; then
32- echo " ERROR: SHA256 checksum for ${filename} doesn't match."
33- exit 1
34- fi
35- }
36-
37- function chk_exists_and_matches() {
38- if [[ -f " $1 " ]]; then
39- if echo " ${2} ${1} " | sha256sum --check; then
40- echo " SKIPPING: SHA256 checksum for $1 matches."
41- [[ " $3 " = ME ]] && me_exists=" y"
42- return 0
43- fi
44- echo " $1 exists but checksum doesn't match. Continuing..."
45- fi
46- }
47-
4827function download_and_clean() {
4928 me_cleaner=" $( realpath " ${1} " ) "
5029 me_output=" $( realpath " ${2} " ) "
@@ -57,7 +36,7 @@ function download_and_clean() {
5736 me_installer_filename=" H110M-DGS(7.30)ROM.zip"
5837 user_agent=" Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
5938 curl -A " $user_agent " -s -O " https://download.asrock.com/BIOS/1151/${me_installer_filename} "
60- chk_sha256sum " $DL_HASH " " $me_installer_filename "
39+ chk_sha256sum " $ME_DOWNLOAD_HASH " " $me_installer_filename "
6140
6241 # Unpack the ME blob.
6342 unzip " $me_installer_filename " || exit
@@ -160,13 +139,13 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
160139 fi
161140
162141 parse_params " $@ "
163- chk_exists_and_matches " $me_deguarded " " $DEGUARDED_ME_BIN_HASH " ME
164142
165- if [[ -z " $me_exists " ]]; then
166- download_and_clean " $me_cleaner " " $me_cleaned "
167- deguard " $me_cleaned " " $me_deguarded "
168- rm -f " $me_cleaned "
169- fi
170-
171- chk_sha256sum " $DEGUARDED_ME_BIN_HASH " " $me_deguarded "
143+ check_outputs " ${DEGUARDED_ME_BIN_HASH} ${me_deguarded} " && { echo " All outputs match. Nothing to do." ; exit 0; }
144+
145+ echo " Writing cleaned and deguarded ME to ${me_deguarded} "
146+ download_and_clean " $me_cleaner " " $me_cleaned "
147+ deguard " $me_cleaned " " $me_deguarded "
148+ rm -f " $me_cleaned "
149+
150+ check_outputs " ${DEGUARDED_ME_BIN_HASH} ${me_deguarded} " || exit 1
172151fi
0 commit comments