COM file
This article needs additional citations for verification. (February 2009) |
Filename extension |
.COM |
---|---|
Internet media type | application/x-dosexec |
Type of format | Executable |
Extended to | DOS MZ executable |
A COM file is a type of simple
.COM
was used as a filename extension for text files containing commands to be issued to the operating system (similar to a batch file).[1] With the introduction of Digital Research's CP/M (a microcomputer operating system), the type of files commonly associated with COM extension changed to that of executable files. This convention was later carried over to DOS. Even when complemented by the more general EXE file formatThe .COM
file name extension has no relation to the .com (for "commercial") top-level Internet domain name. However, this similarity in name has been exploited by malware writers.
DOS binary format
The COM format is the original binary executable format used in
Since it lacks
In the
Although the file format is the same in DOS and CP/M, .COM files for the two operating systems are not compatible; DOS COM files contain x86 instructions and possibly DOS system calls, while CP/M COM files contain 8080 instructions and CP/M system calls (programs restricted to certain machines could also contain additional instructions for 8085 or Z80).
.COM files in DOS set all x86 segment registers to the same value and the SP (stack pointer) register to the offset of the last word available in the first 64 KB segment (typically FFFEh) or the maximum size of memory available in the block the program is loaded into for both, the program plus at least 256 bytes stack, whatever is smaller, thus the stack begins at the very top of the corresponding memory segment and works down from there.[3][4]
In the original DOS 1.x API, which was a derivative of the CP/M API, program termination of a .COM file would be performed by calling the INT 20h (Terminate Program) function or else INT 21h Function 0, which served the same purpose, and the programmer also had to ensure that the code and data segment registers contained the same value at program termination to avoid a potential system crash. Although this could be used in any DOS version, Microsoft recommended the use of INT 21h Function 4Ch for program termination from DOS 2.x onward, which did not require the data and code segment to be set to the same value.
It is possible to make a .COM file to run under both operating systems in form of a fat binary. There is no true compatibility at the instruction level; the instructions at the entry point are chosen to be equal in functionality but different in both operating systems, and make program execution jump to the section for the operating system in use. It is basically two different programs with the same functionality in a single file, preceded by code selecting the one to use.
Under CP/M 3, if the first byte of a COM file is C9h, there is a 256-byte header;
Files may have names ending in .COM, but not be in the simple format described above; this is indicated by a
Large programs
Under
Platform support
The format is still
Use for compatibility reasons
Execution preference
In DOS, if a directory contains both a COM file and an
foo.com
and foo.exe
, the following would execute foo.com
:
C:\>foo
A user wishing to run foo.exe
can explicitly use the complete filename:
C:\>foo.exe
Taking advantage of this default behaviour,
notepad.exe
On Windows NT and derivatives (Windows 2000, Windows XP, Windows Vista, and Windows 7), the PATHEXT variable is used to override the order of preference (and acceptable extensions) for calling files without specifying the extension from the command line. The default value still places .com
files before .exe
files. This closely resembles a feature previously found in JP Software's line of extended command line processors 4DOS, 4OS2, and 4NT.
Malicious usage of the .com extension
Some computer virus writers have hoped to take advantage of modern computer users' likely lack of knowledge of the .com file extension and associated binary format, along with their more likely familiarity with the .com Internet domain name. E-mails have been sent with attachment names similar to "www.example.com". Unwary Microsoft Windows users clicking on such an attachment would expect to begin browsing a site named http://www.example.com/
, but instead would run the attached binary command file named www.example
, giving it full permission to do to their machine whatever its author had in mind.[citation needed]
There is nothing malicious about the COM file format itself; this is an exploitation of the coincidental name collision between .com command files and .com commercial web sites.
See also
Notes
- ^ TRS-80 Model III, where programs were loaded at offset +0h.
References
- ^ Christian, Brian; Markson, Tom; Skrenta, Rich (eds.). "Section 5.3". The PDP-11 How-To Book (Revision 1 ed.). Archived from the original on 2018-08-01. Retrieved 2018-08-01. (NB. Has a reference for the RT-11 operating system running on the PDP-11 minicomputer, which shows in section 5.3 that .COM is used to refer to a command file.)
- ^ a b Elliott, John C.; Lopushinsky, Jim (2002) [1998-04-11]. "CP/M 3 COM file header". Seasip.info. Archived from the original on 2018-08-01.
- ^ Paul, Matthias R. (2002-10-07) [2000]. "Re: Run a COM file". Newsgroup: alt.msdos.programmer. Archived from the original on 2017-09-03. Retrieved 2017-09-03. [1] (NB. Has details on the DOS COM program calling conventions.)
- ^ Lunt, Benjamin "Ben" D. (2020). "DOS .COM startup registers". Forever Young Software. Archived from the original on 2020-11-12. Retrieved 2021-12-14.
- ISBN 0-8306-7649-X.
- ^ "Windows Commands". Microsoft. 2023-04-26.