Windows Metafile
{{Short description|File format for images}}
Windows Metafile (WMF) is an image file format originally designed for Microsoft Windows in the 1990s. The original Windows Metafile format was not device-independent (though could be made more so with placement headers) and may contain both vector graphics and bitmap components. It acts in a similar manner to SVG files. WMF files were later superseded by Enhanced Metafiles (EMF files) which did provide for device-independence. EMF files were then themselves enhanced via EMF+ files.
Essentially, a metafile stores a list of records consisting of drawing commands, property definitions and graphics objects to display an image on screen.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|page=16}} The drawing commands used are closely related to the commands of the Graphics Device Interface (GDI) API used for drawing in Microsoft Windows.
There are three major types of metafiles – a WMF is a 16-bit format introduced in Windows 3.0. It is the native vector format for Microsoft Office applications such as Word, PowerPoint, and Publisher. {{As of|2024|April}}, revision 18 of the Windows Metafile Format specification is available.{{cite web |date=2021-04-26 |title=
History
The original 16 bit WMF file format was fully specified in volume 4 of the 1992 Windows 3.1 SDK documentationMicrosoft Windows 3.1 Programmers Reference, Volume 4 Resources, Microsoft Press 1992, {{ISBN|1-55615-494-1}}, chapter 3 pp. 21-45 (at least if combined with the descriptions of the individual functions and structures in the other volumes), but that specification was vague about a few details. These manuals were published as printed books available in bookstores with no click through EULA or other unusual licensing restrictions (just a general warning that if purchased as part of a software bundle, the software would be subject to one).
Over time the existence of that historic specification was largely forgotten and some alternative implementations resorted to reverse engineering to figure out the file format from existing WMF files, which was difficult and error prone.{{cite web | url=http://wvware.sourceforge.net/caolan/support.html | title=Window Metafile (wmf) Reference | quote=These opcodes are unimplemented, for the reason that i dont know what they are, no known documentation | author=Caolan McNamara | access-date=2008-06-01}} In September 2006, Microsoft again published the WMF file format specification in a more complete form{{cite web | url=http://msdn.microsoft.com/en-us/library/cc215212.aspx | title=
Microsoft later deprecated WMF files in favour of 32-bit EMF files as WMF files had real issues with device independence, despite the use of a "placeable" file header which provided basic device independence. Microsoft found that developers who use the format were "[embedding] application, location, or scaling comments in the metafiles... Others added headers to the metafile that provided various application-specific information", causing major compatibility issues.{{citation|title=Enhanced Metafiles in Win32|publisher=Microsoft Developer Network Technology Group|date=June 10, 1993|url=http://www.massmind.org/techref/fileext/emf/enh_meta.htm}} Thus, in 1992 with Windows NT 3.1, Microsoft introduced the Enhanced Metafile format (EMF){{cite IETF|title = Windows Image Media Types|rfc = 7903|sectionname = Windows Metafiles|page = 1|last1 = Leonard|first1 = Sean|date = September 2016|publisher = IETF|access-date = February 8, 2020|issn = 2070-1721|doi = 10.17487/RFC7903}} — a format which was based on the Win32 API and with which they built-in device independence.{{citation|url=https://wiki.fileformat.com/image/emf/|title=EMF|work=FileFormat|date=11 October 2019|publisher=Aspose Pty Ltd|access-date=2020-01-20}} — these were also known as NT metafiles.{{citation|title=NT Metafiles and GDI Objects|first=Charles|last=Petzold|author-link=Charles Petzold|work=PC Magazine|date=October 11, 1994|pages=343–347|url=https://books.google.com/books?id=fy_G-xlQbE8C&pg=PA345}} With the release of Windows XP and GDI+, the set of records had to be significantly increased and so Microsoft released EMF+ as an extension to the existing EMF file format.{{cite book|title=Graphics Programming with GDI+ & DirectX|publisher=A-List Publishing|page=68|year=2005|first1=Alex|last1=Polyakov|first2=Vitaly|last2=Brusentsev|isbn=1-931769-39-7|url=https://books.google.com/books?id=MJ_VAwAAQBAJ&pg=PA68}}
Metafile structure
File:Microsoft Metafile comparisons.svg
WMF, EMF and EMF+ files all consist of a series of records that are played back to produce graphical output. Some records define objects which can specify graphical objects used to determine how graphics should be drawn (e.g. pens specify the color and width of lines). Each of these objects are stored in metafiles and are placed into an object table, which tracks the usage of graphic objects while processing the metafile. The object table is an associative array of indexes to graphical object structures defined within the metafile.
WMF and EMF files handle object processing differently to EMF+ records in EMF files. As a WMF and EMF file is being processed, the records are read into an object table once an object is defined. If an object is deleted then the object is released from the table and the identifier can be reused. Notably an object will not be used until it is specifically selected during record playback.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=
=WMF=
{{Infobox file format
| name = Windows Metafile
| icon =
| logo =
| extension = .wmf
| type code =
| uniform type = com.microsoft.wmf
| magic =
| released =
| latest release version =
| latest release date =
| type = Vector graphics
| container for =
| contained by =
| extended from =
| extended to = EMF
| standard =
| open =
| free =
}}
WMF files were not originally designed to be device independent, meaning that a file could not be played back on output devices that differed from the original device on which the file was recorded. A partial solution to this issue was invented by Aldus Corporation, who added an additional "placeable" header, called the "APM header",{{citation|title=Q66949: INFO: Windows Metafile Functions & Aldus Placeable Metafiles|publisher=Microsoft|url=https://jeffpar.github.io/kbarchive/kb/066/Q66949/|via=KnowledgeBase Archive: An Archive of Early Microsoft KnowledgeBase }} which added a bounding rectangle, a metafile version, metafile size, number of objects in the metafile and the size of the largest single record in the metafile.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|page=17|section=1.3.1 Metafile Structure}}{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|section=2.3.2.3 META_PLACEABLE Record|page=115}} This was later incorporated into the WMF format by Microsoft, starting in Windows 2000.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|page=55|quote=<55> Section 2.3.2.3: Windows NT 3.1, Windows NT 3.5, Windows NT 3.51, and Windows 95: This feature is not supported.}}
WMF files are structured by a series of records, starting with a number of control records: the header record,{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|section=2.3.2.2 MTF_HEADERRECORD Record|page=114}} the aforementioned optional placeable record,{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|section=2.3.2.2 MTF_HEADERRECORD Record|page=114}} and finished by an end of file record.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=Windows Metafile Format|publisher=Microsoft|section=2.3.2.1 MTF_EOF Record|page=114}}
Encapsulated by the control records are the records that make up the image itself. These records work within what is known as the playback device context, which is the collection of properties and objects that make up a device's graphical environment as the metafile is being "played back" onto this output device.{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf | title=
Records other than control records can be largely grouped into bitmap records, drawing records, object records, state records and escape records.
{{Clear}}
==Bitmap records==
Bitmap records manage and output bitmap images.
==Drawing records==
Drawing records produce graphics output.
==Object records==
Object records create and manage graphics objects. In WMF files there are two broad categories of objects – graphics objects and structure objects. Structure objects are not explicitly created or deleted in a WMF, they are instead of complex structures. For example, the BitmapCoreHeader contains information about the dimensions and color format of a device-independent bitmap,{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=
Graphics objects can be brushes (defines the style, color and pattern of a brush which defines how to paint an area of the graphic), fonts (defines properties that affect how text is displayed), palettes (specifies colors as device-independent values, defined by an application), pens (specifies the graphical attributes of a line), and regions (which specify line and curve segments that define a shape).
==State records==
State records manage the graphics properties of the playback device context.{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-WMF/%5bMS-WMF%5d.pdf|title=
==Escape records==
Escape records are a means to extend metafile functionality via records that are not otherwise defined as a WMF record type. Each escape record contains a record function, an escape function and potentially escape data.
The following escape records make up a WMF file.
There was a major vulnerability found in escape records around the Abort escape record, which stores the abort procedure code within the record itself. This affected Windows systems (see {{CVE|2005-4560}}) and the Wine project (see {{CVE|2006-0106}}). According to Secunia, "The vulnerability is caused due to an error in the handling of Windows Metafile files ('.wmf') containing specially crafted SETABORTPROC 'Escape' records. Such records allow arbitrary user-defined function to be executed when the rendering of a WMF file fails."{{cite web|archive-url=https://web.archive.org/web/20060102123654/http://secunia.com/advisories/18255/|archive-date=January 2, 2006|url=http://secunia.com/advisories/18255/|title=Microsoft Windows WMF "SETABORTPROC" Arbitrary Code Execution|id=Secunia Advisory: SA18255|publisher=Secunia}} According to the Windows 3.1 SDK documentation, the SETABORTPROC escape was obsoleted and replaced by the function of the same name in Windows 3.1, long before the WMF vulnerability was discovered.{{citation|url=https://docs.microsoft.com/en-us/windows-hardware/drivers/print/pscript-supported-escapes|title=Pscript-Supported Escapes|publisher=Microsoft|access-date=2020-01-28}} However the obsoleted escape code was retained for compatibility with 16 bit programs written for (or at least backwards compatible with) Windows 3.0. This change happened at approximately the same time as Microsoft was creating the 32 bit reimplementation of GDI for Windows NT, and it is likely that the vulnerability occurred during this effort.
After Steve Gibson accused Microsoft of deliberately implementing a backdoor into their code,{{cite podcast|url=https://media.grc.com/sn/sn-022.mp3|title=The Windows MetaFile Backdoor?|website=GRC Security Now!|publisher=Gibson Research Corporation|date=January 12, 2006|access-date=2020-01-28}}{{citation|title = Re: You won't want to miss tonight's Security Now!, #22|first=Steve|last=Gibson|author-link=Steve Gibson (computer programmer)|date=January 12, 2006|work=grc.news.feedback|url=https://www.grc.com/x/news.exe?cmd=article&group=grc.news.feedback&item=60006|access-date=2020-01-28}} Mark Russinovich provided a rebuttal, and stated that:
{{blockquote|...things were different when the format was architected. In the Windows 3.1 “large” memory model code is inherently location-independent and Windows was never patched, so both Windows and an application could simply copy an application function into the WMF file and assume it would work when played back by the same application in a later run session. In any case, its not clear that the developers envisioned applications creating on-disk metafiles with abort procedures. Also, as Microsoft’s Stephen Toulouse pointed out in [https://web.archive.org/web/20060116042756/http://blogs.technet.com/msrc/archive/2006/01/13/417431.aspx Microsoft’s rebuttal] to Steve’s claims, the security landscape in the early 1990s was very different than today and all code, including that stored in a WMF file, was inherently trusted.{{citation|url=https://techcommunity.microsoft.com/t5/windows-blog-archive/inside-the-wmf-backdoor/ba-p/723489|first=Mark|last=Russinovich|author-link=Mark Russinovich|title=Inside the WMF Backdoor|publisher=Microsoft|work=TechNet|via=Microsoft Tech Community|date=January 18, 2006}}}}
Peter Ferrie of Symantec Security Response, USA also disagreed with Gibson, noting that:
{{blockquote|Gibson claimed that a thread is created to run the SetAbortProc handler. In fact, no thread is created to run the handler – it is a callback, which is called by the parser, and the parser has to wait until the callback returns, otherwise the whole point of the function (to abort the printing) is lost. By his own admission, Gibson did not read the documentation (in fact, he claimed that he couldn’t find it, although it is freely available on Microsoft’s Web site), and he claimed that the device context is not available to the function handler. Of course the device context is available to the function handler — it is one of the two parameters that is passed to it (see above), and it is required in order to abort the printing. Finally, Gibson claimed that the control flow could not return to Windows. It is simply a matter of the function returning and discarding the parameters that were passed on the stack. If the record is well formed, Windows will continue to parse the file, as before. ... Gibson admits that he was guessing about a number of things. Unfortunately, he guessed poorly. I guess we know better now.{{citation|title=Inside the Windows Meta File Format|publisher=Virus Bulletin|date=February 2, 2006|first=Peter|surname=Ferrie|url=https://www.symantec.com/avcenter/reference/inside.the.windows.meta.file.format.pdf|archive-url=https://web.archive.org/web/20080516052826/http://www.symantec.com/avcenter/reference/inside.the.windows.meta.file.format.pdf|url-status=dead|archive-date=May 16, 2008|via=Symantec|access-date=2020-01-24}}}}
=EMF=
{{Infobox file format
| name = Enhanced Metafile
| icon =
| logo =
| extension = .emf
| type code =
| uniform type = com.microsoft.emf
| magic =
| released =
| latest release version =
| latest release date =
| type = Vector graphics
| container for =
| contained by =
| extended from = WMF
| extended to = EMF+
| standard =
| open =
| free =
}}
EMF files have three possible versions of headers. The original headers is just a container for images, the second and third version encapsulates the original header and contains a pixel format record and support for OpenGL records, and the third version encapsulates the second header extension and increases EMF accuracy and scalability of EMFs as it adds the ability to measure distances of device surfaces using the metric system.{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-EMF/%5bMS-EMF%5d.pdf|title=
Each EMF header starts with an EMR_HEADER record, and records the relevant properties of the device on which the metafile image was recorded. The original EMF header has an 80 byte header and an optional variable length description string.{{citation|url= https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-EMF/%5bMS-EMF%5d.pdf|title=EmfMetafileHeaderExtension1
is a record that is inserted directly after the original EMF header, specifies whether there is a pixel format descriptor and the offset to the descriptor object within the header, as well as a field that specifies if OpenGL records exist in the metafile.{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-EMF/%5bMS-EMF%5d.pdf|title=EmfMetafileHeaderExtension2
is a record that is inserted directly after the EmfMetafileHeaderExtension1
record, and it contains two fields with the X and Y values to measure the device surface in micrometers.{{citation|url=https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-EMF/%5bMS-EMF%5d.pdf|title=
Like WMF files, records can be classified by function, however there are more record types in EMF files than there are in WMF files. Records can be classified as control, bitmap, clipping, comment, drawing, escape, object creation, object manipulation, OpenGL, path bracket, state and transform records.
=EMF+=
With the release of Windows XP, the Enhanced Metafile Format Plus Extensions (EMF+) format was introduced. EMF+ provides a way to serialize calls to the GDI+ API in the same way that WMF/EMF stores calls to GDI.
There are also compressed versions of Windows Metafiles known as Compressed Windows Metafile (WMZ) and Compressed Windows Enhanced Metafile (EMZ),{{cite web | url=http://support.microsoft.com/kb/895083 | archive-url=https://web.archive.org/web/20140419204933/http://support.microsoft.com/kb/895083 | url-status=dead | archive-date=2014-04-19 | title=You receive a "This file is an unsupported graphic format" error message when you try to insert a picture into a PowerPoint for Mac presentation | publisher=Microsoft | access-date=2014-04-19}} which are basically gzip compressed WMF and EMF files correspondingly.
Implementations
The WMF format was designed to be executed by the Windows GDI layer in order to restore the image, but as the WMF binary files contain the definition of the GDI graphic primitives that constitute this image, it is possible to design alternative libraries that render WMF binary files or convert them into other graphic formats.
See also
- PostScript
- Vector Markup Language (VML)
- Scalable Vector Graphics (SVG)
References
{{Reflist|30em}}
External links
- [https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/4813e7fd-52d0-4f42-965f-228c8b7488d2 Windows Metafile Format Specification from Microsoft]
- [https://docs.microsoft.com/en-us/windows/desktop/gdi/metafiles Metafiles – Windows applications]
- [https://www.fileformat.info/format/wmf/ File Format Summary at fileformat.info]
- [https://www.companionsoftware.com/support/windows-metafile-faq/ Windows Metafile FAQ]
{{Graphics file formats}}