From 93a9b77d427393cafbe2dab2dda72ef67956a2f6 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 20:35:32 -0400 Subject: ut_binaryFileFormat Matching --- src/nw4r/ut/ut_binaryFileFormat.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/nw4r/ut/ut_binaryFileFormat.cpp (limited to 'src/nw4r/ut/ut_binaryFileFormat.cpp') diff --git a/src/nw4r/ut/ut_binaryFileFormat.cpp b/src/nw4r/ut/ut_binaryFileFormat.cpp new file mode 100644 index 00000000..1b62b51c --- /dev/null +++ b/src/nw4r/ut/ut_binaryFileFormat.cpp @@ -0,0 +1,28 @@ +#include + +namespace nw4r { +namespace ut { + +/* 8042a9e0 */ +bool IsValidBinaryFile(const BinaryFileHeader *header, unsigned long magic, u16 version, u16 numBlocks) { + if (header->magic != magic) { + return false; + } + if (header->byteOrder != 0xFEFF) { + return false; + } + if (header->version != version) { + return false; + } + if (header->fileSize < (numBlocks * sizeof(BinaryBlockHeader) + sizeof(BinaryFileHeader))) { + return false; + } + + if (header->numBlocks < numBlocks) { + return false; + } + return true; +} + +} // namespace ut +} // namespace nw4r -- cgit v1.2.3