2 * Dump an EMF Spool File
4 * Copyright 2022 Piotr Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define EMFSPOOL_VERSION 0x10000
38 EMRI_BW_FORM_METAFILE
,
44 EMRI_DESIGNVECTOR_EXT
,
53 unsigned int dwVersion
;
55 unsigned int dpszDocName
;
56 unsigned int dpszOutput
;
65 static inline void print_longlong(ULONGLONG value
)
67 if (sizeof(value
) > sizeof(unsigned long) && value
>> 32)
68 printf("0x%lx%08lx", (unsigned long)(value
>> 32), (unsigned long)value
);
70 printf("0x%lx", (unsigned long)value
);
73 static const WCHAR
* read_wstr(unsigned long off
)
75 const WCHAR
*beg
, *end
;
80 beg
= end
= PRD(off
, sizeof(WCHAR
));
83 fatal("can't read Unicode string, corrupted file\n");
87 end
= PRD(off
, sizeof(WCHAR
));
90 fatal("can't read Unicode string, corrupted file\n");
95 #define EMRICASE(x) case x: printf("%-24s %08x\n", #x, hdr->cjSize); break
96 static unsigned long dump_emfspool_record(unsigned long off
)
98 const record_hdr
*hdr
;
100 hdr
= PRD(off
, sizeof(*hdr
));
106 EMRICASE(EMRI_METAFILE
);
107 EMRICASE(EMRI_ENGINE_FONT
);
108 EMRICASE(EMRI_DEVMODE
);
109 EMRICASE(EMRI_TYPE1_FONT
);
110 EMRICASE(EMRI_PRESTARTPAGE
);
111 EMRICASE(EMRI_DESIGNVECTOR
);
112 EMRICASE(EMRI_SUBSET_FONT
);
113 EMRICASE(EMRI_DELTA_FONT
);
114 EMRICASE(EMRI_FORM_METAFILE
);
115 EMRICASE(EMRI_BW_METAFILE
);
116 EMRICASE(EMRI_BW_FORM_METAFILE
);
117 EMRICASE(EMRI_METAFILE_DATA
);
118 EMRICASE(EMRI_METAFILE_EXT
);
119 EMRICASE(EMRI_BW_METAFILE_EXT
);
120 EMRICASE(EMRI_ENGINE_FONT_EXT
);
121 EMRICASE(EMRI_TYPE1_FONT_EXT
);
122 EMRICASE(EMRI_DESIGNVECTOR_EXT
);
123 EMRICASE(EMRI_SUBSET_FONT_EXT
);
124 EMRICASE(EMRI_DELTA_FONT_EXT
);
125 EMRICASE(EMRI_PS_JOB_DATA
);
126 EMRICASE(EMRI_EMBED_FONT_EXT
);
128 printf("%u %08x\n", hdr
->ulID
, hdr
->cjSize
);
135 case EMRI_FORM_METAFILE
:
136 case EMRI_BW_METAFILE
:
137 case EMRI_BW_FORM_METAFILE
:
138 case EMRI_METAFILE_DATA
:
140 unsigned long emf_off
= off
+ sizeof(*hdr
);
141 while ((emf_off
= dump_emfrecord(" ", emf_off
)) && emf_off
< off
+ sizeof(*hdr
) + hdr
->cjSize
);
145 case EMRI_METAFILE_EXT
:
146 case EMRI_BW_METAFILE_EXT
:
148 const ULONGLONG
*emf_off
= PRD(off
+ sizeof(*hdr
), sizeof(*emf_off
));
150 fatal("truncated file\n");
151 printf(" %-20s ", "offset");
152 print_longlong(*emf_off
);
153 printf(" (absolute position ");
154 print_longlong(off
- *emf_off
);
160 dump_data((const unsigned char *)(hdr
+ 1), hdr
->cjSize
, "");
164 return off
+ sizeof(*hdr
) + hdr
->cjSize
;
167 enum FileSig
get_kind_emfspool(void)
171 hdr
= PRD(0, sizeof(*hdr
));
172 if (hdr
&& hdr
->dwVersion
== EMFSPOOL_VERSION
)
177 void emfspool_dump(void)
179 const WCHAR
*doc_name
, *output
;
183 hdr
= PRD(0, sizeof(*hdr
));
186 doc_name
= read_wstr(hdr
->dpszDocName
);
187 output
= read_wstr(hdr
->dpszOutput
);
189 printf("File Header\n");
190 printf(" %-20s %#x\n", "dwVersion:", hdr
->dwVersion
);
191 printf(" %-20s %#x\n", "cjSize:", hdr
->cjSize
);
192 printf(" %-20s %#x %s\n", "dpszDocName:", hdr
->dpszDocName
, get_unicode_str(doc_name
, -1));
193 printf(" %-20s %#x %s\n", "dpszOutput:", hdr
->dpszOutput
, get_unicode_str(output
, -1));
197 while ((off
= dump_emfspool_record(off
)));