From bfe937f58fc14dfc51ebca9e9b3331d68b990041 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:43:18 -0400 Subject: [PATCH] Add a check to wad.py that ensures the file being loaded is a WAD --- src/libWiiPy/wad.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libWiiPy/wad.py b/src/libWiiPy/wad.py index 9ed2337..ad454ee 100644 --- a/src/libWiiPy/wad.py +++ b/src/libWiiPy/wad.py @@ -39,6 +39,15 @@ class WAD: self.wad_meta_offset: int # Load header data from WAD stream with io.BytesIO(self.wad) as wad_data: + # Read the first 8 bytes of the file to ensure that it's a WAD. This will currently reject boot2 WADs, but + # this tool cannot handle them correctly right now anyway. + wad_data.seek(0x0) + wad_magic_bin = wad_data.read(8) + wad_magic_hex = binascii.hexlify(wad_magic_bin) + wad_magic = str(wad_magic_hex.decode()) + if wad_magic != "0000002049730000": + raise TypeError("This does not appear to be a valid WAD file, or is a boot2 WAD, which is not currently" + "supported by this library.") # ==================================================================================== # Get the sizes of each data region contained within the WAD. # ====================================================================================