IMO this can be handled... RtlImageGetNtHeader will do all the DOS+PE validation bits check supported magic values
const IMAGE_DATA_DIRECTORY *dir = (nthdr->Magic == 0x10b) ? ((IMAGE_NT_HEADERS32*)nthdr)->DataDirectory : ((IMAGE_NT_HEADERS64*)nthdr) + IMAGE_DIRECTORY_SECURITY;
and the rest should be transparent