Skip to content

Replace most NVRAM parsers with ones generated from KaitaiStruct definitions#412

Merged
NikolajSchlej merged 16 commits intonew_enginefrom
dev/kty_nvram
Mar 13, 2025
Merged

Replace most NVRAM parsers with ones generated from KaitaiStruct definitions#412
NikolajSchlej merged 16 commits intonew_enginefrom
dev/kty_nvram

Conversation

@NikolajSchlej
Copy link
Copy Markdown
Collaborator

Back in 2023 the initial attempt to fuzz the parsing engine with LibFuzzer and HongFuzz quickly failed because the fuzzer found an issue with our NVRAM parsers requiring backtracking to parse things properly, and that effectively dead-looped them on way too many possible inputs to count.

As an effort to get rid of that, and rewrite manual parsers on something more declarative and saner, I've started to rewrite NVRAM parsers in KaitaiStruct, and the first one (AMI NVAR) had been in use since about A62, and proven to work better than expected. Then I had to return to the US and restart my full-day employment, so all work on UEFITool had to be postponed. Until this month that is, and this PR is the result of it.

@vit9696, please review, as I do not expect this new code to change drastically any time soon. I will be doing cross-tests between A69 and this branch, trying to catch any possible offset errors and other things that Kaitai's codegen can not cover.

@NikolajSchlej
Copy link
Copy Markdown
Collaborator Author

NikolajSchlej commented Mar 9, 2025

Will have to make a bit more changes here for the sake of optimization, turns out trying every parser on every byte got rather slow if it creates a ton of C++ objects and destroys those objects immediately.

Update: done, ready for review.

@NikolajSchlej
Copy link
Copy Markdown
Collaborator Author

NikolajSchlej commented Mar 10, 2025

Local cross-testing with about 30 different samples of Insyde H2O and Phoenix SCT based FWs (AMI NVAR parser is not affected by this change) showed no unexpected results.
Several bugs present in A69 got fixed by this PR:

  • EDK2 FTW header had the CRC value reset to 0xFFFFFFFF, now is getting parsed properly.
  • Insyde Factory Data Copy store had wrong offset (+8 from the real one), now fixed.

Copy link
Copy Markdown
Contributor

@vit9696 vit9696 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a brief review. I mostly focused on useability and safety issues, trusting you and kaitai on the format matter.

Comment thread common/ffsparser.cpp
Comment thread common/ffsparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp
Comment thread common/nvramparser.cpp Outdated
Comment thread common/nvramparser.cpp
@NikolajSchlej NikolajSchlej merged commit a12be6b into new_engine Mar 13, 2025
22 checks passed
@NikolajSchlej NikolajSchlej deleted the dev/kty_nvram branch March 13, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants