Commits

oliver_g committed 46bd835

add test case for NDS file parser

Also, improve NDS file detection to avoid false positive in test.

  • Participants
  • Parent commits 371373d

Comments (0)

Files changed (3)

hachoir-parser/hachoir_parser/program/nds.py

         "category": "program",
         "file_ext": ("nds",),
         "mime": (u"application/octet-stream",),
-        "min_size": 12 * 8,
+        "min_size": 512 * 8, # just a minimal header
         "description": "Nintendo DS game file",
     }
 
     endian = LITTLE_ENDIAN
 
     def validate(self):
-        # TODO: improve detection (candidates: rom_size, header_size, various CRCs; game_title and game_code always must start with character)
-        return self.stream.readBytes(0, 1) != "\0" and ((self["header"]["device_code"].value & 7) == 0) and self.size >= 512 * 8
+        return (self.stream.readBytes(0, 1) != "\0"
+            and ((self["header"]["device_code"].value & 7) == 0)
+            and self["header"]["header_size"].value >= 512
+            and self["header"]["arm9_bin_size"].value > 0
+            and self["header"]["arm7_bin_size"].value > 0
+            and self["header"]["arm9_source"].value + self["header"]["arm9_bin_size"].value < self._size
+            and self["header"]["arm7_source"].value + self["header"]["arm7_bin_size"].value < self._size
+            )
 
     def createFields(self):
         # Header

hachoir-parser/tests/download_testcase.py

     (u"radpoor.doc", 103936, "114835a03be92e02029c74ece1162c3e"),
     (u"quicktime.mp4", 245779, "dc77a8de8c091c19d86df74280f6feb7"),
     (u"swat.blp", 55753, "a47a2d6ef61c9005c3f5faf1bca253af"),
+    (u"nitrodir.nds", 217624, "4d81b4dec82e0abbdf6c793ed3280f70"),
 )
 
 def stringMD5(text):

hachoir-parser/tests/run_testcase.py

     checkValue(parser, "jpeg_header_len", 10),
 )
 
+def checkNds(parser): return (
+    checkValue(parser, "/header/game_title", '.'),
+    checkValue(parser, "/header/header_crc16", 29398),
+    checkValue(parser, "/filename_table/directory[4]/entry[0]/name", "file2.txt"),
+)
+
 def checkFile(filename, check_parser):
     sys.stdout.write("  - Create parser: ")
     sys.stdout.flush()
     # radpoor.doc
     # quicktime.mp4
     (u"swat.blp", checkSwat),
+    (u"nitrodir.nds", checkNds),
 )
 
 if __name__ == "__main__":