This is probably a stupid question, but if you want to be careful about parsing, why not have a file something like this ?:
- current module
- fixed-size length of signature
- fixed-size magic string
In that case you go to the end of the file (maybe refuse to load modules larger than size Z ?), get the last X bytes, check if it is the magic string. Then take the Y bytes before it and use that as a length (obviously checking some boundry and that the size isn't bigger than the file). And get the signature that way. Everything else is just the module.
Wouldn't that be very little code with very few things to check ?