Methods, apparati, and computer-readable media for countering malicious
code infections to computer files (20). A preferred embodiment comprises
selecting (40) an invariant section of each file (20), wherein said
invariant section is invariant to malicious code infections and to repair
thereof; for each of a set of known malicious code files, using an
algorithm to generate (41) a template corresponding to the invariant
section; using said algorithm to define a target (29), corresponding to
said invariant section, within a test file (20); comparing (46) the
target (29) with the templates; and declaring (48) the presence of
malicious code in the test file (20) when the target (29) matches a
template.