From cd110eafa61c4c408d7a6eb11b12abd2df227112 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Wed, 22 Apr 2020 19:25:36 +0300 Subject: [PATCH] Provide workaround for #196 --- common/ffsparser.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index 5bc0ef8..fb309a4 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -3360,13 +3360,22 @@ USTATUS FfsParser::checkProtectedRanges(const UModelIndex & index) // Calculate digest for BG-protected ranges UByteArray protectedParts; bool bgProtectedRangeFound = false; - for (UINT32 i = 0; i < (UINT32)bgProtectedRanges.size(); i++) { - if (bgProtectedRanges[i].Type == BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB) { - bgProtectedRangeFound = true; - bgProtectedRanges[i].Offset -= (UINT32)addressDiff; - protectedParts += openedImage.mid(bgProtectedRanges[i].Offset, bgProtectedRanges[i].Size); - markProtectedRangeRecursive(index, bgProtectedRanges[i]); + try { + for (UINT32 i = 0; i < (UINT32)bgProtectedRanges.size(); i++) { + if (bgProtectedRanges[i].Type == BG_PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB && bgProtectedRanges[i].Size > 0) { + bgProtectedRangeFound = true; + if ((UINT64)bgProtectedRanges[i].Offset >= addressDiff) { + bgProtectedRanges[i].Offset -= (UINT32)addressDiff; + } else { + // TODO: Explore this. + msg(usprintf("%s: Suspicious BG protection offset", __FUNCTION__), index); + } + protectedParts += openedImage.mid(bgProtectedRanges[i].Offset, bgProtectedRanges[i].Size); + markProtectedRangeRecursive(index, bgProtectedRanges[i]); + } } + } catch (...) { + bgProtectedRangeFound = false; } if (bgProtectedRangeFound) {