using unreliable shitty hack code..
but it's RA, so expected.
You either have a database, or you have a header, or you're going to get false positives.
Database approach (aka Software Lists) is preferable for me, allows us to document, in readable text, what is in the cartridges. Allows us to update it, if new information appears, or we're wrong, without forcing everybody to update fake data attached to rom files. Means current 'correct to best of our knowledge' information can always be found in the source.
I think MAME should have a 'cartridge template' model too, so that you can specify a template (defining sram, banking scheme etc.) to load a headerless file into, this would be handy for homebrew development.