Companion viruses make use of a DOS quirk that runs COM files before EXE files. The virus infects EXE files by installing a same-named COM file.
Would you believe that a virus can infect your files without changing a single byte in the infected file? Well, it's true! The more common of two kinds is called the companion or spawning virus (the other is a cluster virus). The companion virus infects your files by locating all files with names ending in .EXE. The virus then creates a matching file name ending in .COM that contains the viral code.
Here's what happens: Let's say a companion virus is executing on your PC and decides it's time to infect a file. It looks around and happens to find a file called PGM.EXE. It now creates a file called PGM.COM containing the virus. The virus usually plants this file in the same directory as the .EXE file but it could place it in any directory on your DOS path. If you type PGM and hit enter, DOS will execute PGM.COM instead of PGM.EXE. (In order, DOS will execute .COM, then .EXE, then .BAT files of the same root name, if they are all in the same directory.) The virus executes, possibly infecting more files and then loads and executes PGM.EXE. The user probably won't notice anything wrong.
This type of virus is fairly easy to detect by the presence of the extra .COM files. Sometimes the virus attempts to hide the extra files by either placing them into a different directory (but one on the PATH) or gives them a hidden attribute so a normal DIR command will not show them. And, of course, when the virus is active in memory it can effectively hide the .COM files as well (but, unlike many viruses, a companion infector need not remain in memory to do its work).
A good integrity map of what should be on the hard disk can be used to easily detect and clean companion viruses.
Note: There are some instances where it is normal to have both .COM and .EXE files of the same name (such as DOS 5's DOSSHELL) but this is relatively rare. When this is the case, the companion virus will usually not change the existing .COM file.
A companion virus installs a COM file (the virus) for every EXE file found on the disk.
DOS runs COM files before EXE files and so the virus will run first, going into memory and then will execute the
related EXE file.
Companion viruses are relatively easy to find and eliminate if you have a good integrity map of what should be on your disk.