1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // =========================================================================== |
5 | // File: CEEGEN.CPP |
6 | // =========================================================================== |
7 | #include "stdafx.h" |
8 | #include "iceefilegen.h" |
9 | #include "ceefilegenwriter.h" |
10 | |
11 | #ifdef EnC_SUPPORTED |
12 | #define ENC_DELTA_HACK |
13 | #endif |
14 | |
15 | #ifdef ENC_DELTA_HACK |
16 | extern BOOL g_EnCMode; |
17 | #endif |
18 | |
19 | // Deprecated |
20 | //**************************************************************************** |
21 | HRESULT ICeeFileGen::EmitMethod () |
22 | { |
23 | _ASSERTE("Deprecated" && 0); |
24 | return (E_FAIL); |
25 | } |
26 | HRESULT ICeeFileGen::EmitSignature () |
27 | { |
28 | _ASSERTE("Deprecated" && 0); |
29 | return (E_FAIL); |
30 | } |
31 | HRESULT ICeeFileGen::SetEntryClassToken () |
32 | { |
33 | _ASSERTE("Deprecated" && 0); |
34 | return (E_FAIL); |
35 | } |
36 | HRESULT ICeeFileGen::GetEntryClassToken () |
37 | { |
38 | _ASSERTE("Deprecated" && 0); |
39 | return (E_FAIL); |
40 | } |
41 | HRESULT ICeeFileGen::SetEntryPointDescr () |
42 | { |
43 | _ASSERTE("Deprecated" && 0); |
44 | return (E_FAIL); |
45 | } |
46 | HRESULT ICeeFileGen::GetEntryPointDescr () |
47 | { |
48 | _ASSERTE("Deprecated" && 0); |
49 | return (E_FAIL); |
50 | } |
51 | HRESULT ICeeFileGen::SetEntryPointFlags () |
52 | { |
53 | _ASSERTE("Deprecated" && 0); |
54 | return (E_FAIL); |
55 | } |
56 | HRESULT ICeeFileGen::GetEntryPointFlags () |
57 | { |
58 | _ASSERTE("Deprecated" && 0); |
59 | return (E_FAIL); |
60 | } |
61 | HRESULT ICeeFileGen::CreateSig () |
62 | { |
63 | _ASSERTE("Deprecated" && 0); |
64 | return (E_FAIL); |
65 | } |
66 | HRESULT ICeeFileGen::AddSigArg () |
67 | { |
68 | _ASSERTE("Deprecated" && 0); |
69 | return (E_FAIL); |
70 | } |
71 | HRESULT ICeeFileGen::SetSigReturnType () |
72 | { |
73 | _ASSERTE("Deprecated" && 0); |
74 | return (E_FAIL); |
75 | } |
76 | HRESULT ICeeFileGen::SetSigCallingConvention () |
77 | { |
78 | _ASSERTE("Deprecated" && 0); |
79 | return (E_FAIL); |
80 | } |
81 | HRESULT ICeeFileGen::DeleteSig () |
82 | { |
83 | _ASSERTE("Deprecated" && 0); |
84 | return (E_FAIL); |
85 | } |
86 | //**************************************************************************** |
87 | |
88 | EXTERN_C HRESULT __stdcall CreateICeeFileGen(ICeeFileGen** pCeeFileGen) |
89 | { |
90 | if (!pCeeFileGen) |
91 | return E_POINTER; |
92 | |
93 | ICeeFileGen *gen = new (nothrow) ICeeFileGen(); |
94 | IfNullRet(gen); |
95 | |
96 | *pCeeFileGen = gen; |
97 | return S_OK; |
98 | } |
99 | |
100 | EXTERN_C HRESULT __stdcall DestroyICeeFileGen(ICeeFileGen** pCeeFileGen) |
101 | { |
102 | if (!pCeeFileGen) |
103 | return E_POINTER; |
104 | delete *pCeeFileGen; |
105 | *pCeeFileGen = NULL; |
106 | return S_OK; |
107 | } |
108 | |
109 | HRESULT ICeeFileGen::CreateCeeFile (HCEEFILE *ceeFile) |
110 | { |
111 | return CreateCeeFileEx(ceeFile, ICEE_CREATE_FILE_PURE_IL); |
112 | } |
113 | |
114 | HRESULT ICeeFileGen::CreateCeeFileEx (HCEEFILE *ceeFile, DWORD createFlags) |
115 | { |
116 | return CreateCeeFileEx2(ceeFile, createFlags, NULL); |
117 | } |
118 | |
119 | // |
120 | // Seed file is used as the base file. The new file data will be "appended" to the seed file |
121 | // |
122 | |
123 | HRESULT ICeeFileGen::CreateCeeFileEx2 (HCEEFILE *ceeFile, DWORD createFlags, LPCWSTR seedFileName) |
124 | { |
125 | if (!ceeFile) |
126 | return E_POINTER; |
127 | |
128 | CeeFileGenWriter *gen = NULL; |
129 | HRESULT hr; |
130 | IfFailRet(CeeFileGenWriter::CreateNewInstanceEx(NULL, gen, createFlags, seedFileName)); |
131 | TESTANDRETURN(gen != NULL, E_OUTOFMEMORY); |
132 | *ceeFile = gen; |
133 | |
134 | #ifdef ENC_DELTA_HACK |
135 | // for EnC we want the RVA to be right be relative to the front of the delta IL stream rather |
136 | // than take into account the .text section and the cor header as we would for a real PE file |
137 | // However, the RVA must be non-zero, so just stick a dword on the front to push it out. |
138 | if (g_EnCMode) |
139 | { |
140 | CeeSection *sec = &gen->getIlSection(); |
141 | sec->getBlock(sizeof(DWORD), sizeof(DWORD)); |
142 | } |
143 | #endif |
144 | |
145 | return S_OK; |
146 | } |
147 | |
148 | HRESULT ICeeFileGen::CreateCeeFileFromICeeGen(ICeeGen *pICeeGen, HCEEFILE *ceeFile, DWORD createFlags) |
149 | { |
150 | if (!ceeFile) |
151 | return E_POINTER; |
152 | CCeeGen *genFrom = reinterpret_cast<CCeeGen*>(pICeeGen); |
153 | CeeFileGenWriter *gen = NULL; |
154 | HRESULT hr = CeeFileGenWriter::CreateNewInstance(genFrom, gen, createFlags); |
155 | if (FAILED(hr)) |
156 | return hr; |
157 | TESTANDRETURN(gen != NULL, E_OUTOFMEMORY); |
158 | *ceeFile = gen; |
159 | return S_OK; |
160 | } |
161 | |
162 | HRESULT ICeeFileGen::DestroyCeeFile(HCEEFILE *ceeFile) |
163 | { |
164 | if (!ceeFile) |
165 | return E_POINTER; |
166 | if (!*ceeFile) |
167 | return E_POINTER; |
168 | |
169 | CeeFileGenWriter **gen = reinterpret_cast<CeeFileGenWriter**>(ceeFile); |
170 | (*gen)->Cleanup(); |
171 | delete *gen; |
172 | *ceeFile = NULL; |
173 | return S_OK; |
174 | } |
175 | |
176 | // |
177 | |
178 | HRESULT ICeeFileGen::GetRdataSection (HCEEFILE ceeFile, HCEESECTION *section) |
179 | { |
180 | TESTANDRETURNPOINTER(section); |
181 | TESTANDRETURNARG(ceeFile != 0); |
182 | |
183 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
184 | *section = &gen->getStringSection(); |
185 | return S_OK; |
186 | } |
187 | |
188 | HRESULT ICeeFileGen::GetIlSection (HCEEFILE ceeFile, HCEESECTION *section) |
189 | { |
190 | TESTANDRETURNPOINTER(section); |
191 | TESTANDRETURNARG(ceeFile != 0); |
192 | |
193 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
194 | *section = &gen->getIlSection(); |
195 | return S_OK; |
196 | } |
197 | |
198 | |
199 | HRESULT ICeeFileGen::GetSectionCreate (HCEEFILE ceeFile, const char *name, DWORD flags, |
200 | HCEESECTION *section) |
201 | { |
202 | TESTANDRETURNPOINTER(section); |
203 | TESTANDRETURNARG(ceeFile != 0); |
204 | TESTANDRETURNPOINTER(name); |
205 | |
206 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
207 | CeeSection **ceeSection = reinterpret_cast<CeeSection**>(section); |
208 | |
209 | HRESULT hr = gen->getSectionCreate(name, flags, ceeSection); |
210 | |
211 | return hr; |
212 | } |
213 | |
214 | HRESULT ICeeFileGen::SetDirectoryEntry(HCEEFILE ceeFile, HCEESECTION section, ULONG num, ULONG size, ULONG offset) |
215 | { |
216 | TESTANDRETURNPOINTER(ceeFile); |
217 | TESTANDRETURNPOINTER(section); |
218 | |
219 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
220 | CeeSection &sec = *(reinterpret_cast<CeeSection*>(section)); |
221 | return(gen->setDirectoryEntry(sec, num, size, offset)); |
222 | } |
223 | |
224 | HRESULT ICeeFileGen::GetSectionDataLen (HCEESECTION section, ULONG *dataLen) |
225 | { |
226 | TESTANDRETURNPOINTER(section); |
227 | TESTANDRETURNPOINTER(dataLen); |
228 | |
229 | CeeSection *sec = reinterpret_cast<CeeSection*>(section); |
230 | *dataLen = sec->dataLen(); |
231 | return S_OK; |
232 | } |
233 | |
234 | HRESULT ICeeFileGen::GetSectionRVA (HCEESECTION section, ULONG *rva) |
235 | { |
236 | TESTANDRETURNPOINTER(section); |
237 | TESTANDRETURNPOINTER(rva); |
238 | |
239 | CeeSection *sec = reinterpret_cast<CeeSection*>(section); |
240 | *rva = sec->getBaseRVA(); |
241 | return S_OK; |
242 | } |
243 | |
244 | HRESULT ICeeFileGen::GetSectionBlock (HCEESECTION section, ULONG len, |
245 | ULONG align, void **ppBytes) |
246 | { |
247 | TESTANDRETURNPOINTER(section); |
248 | TESTANDRETURNPOINTER(ppBytes); |
249 | |
250 | CeeSection *sec = reinterpret_cast<CeeSection*>(section); |
251 | void *bytes = sec->getBlock(len, align); |
252 | TESTANDRETURN(bytes != NULL, E_OUTOFMEMORY); |
253 | *ppBytes = bytes; |
254 | |
255 | return S_OK; |
256 | } |
257 | |
258 | HRESULT ICeeFileGen::TruncateSection (HCEESECTION section, ULONG len) |
259 | { |
260 | _ASSERTE(!"This is an obsolete function!" ); |
261 | return E_NOTIMPL; |
262 | } |
263 | |
264 | HRESULT ICeeFileGen::AddSectionReloc (HCEESECTION section, ULONG offset, HCEESECTION relativeTo, CeeSectionRelocType relocType) |
265 | { |
266 | TESTANDRETURNPOINTER(section); |
267 | |
268 | CeeSection *sec = reinterpret_cast<CeeSection*>(section); |
269 | CeeSection *relSec = reinterpret_cast<CeeSection*>(relativeTo); |
270 | |
271 | if (relSec) |
272 | { |
273 | #ifdef EMIT_FIXUPS |
274 | CeeFileGenWriter * gen = reinterpret_cast<CeeFileGenWriter*>(&sec->ceeFile()); |
275 | HRESULT hr = gen->addFixup(*sec, offset, relocType, relSec); |
276 | if (FAILED(hr)) |
277 | { |
278 | return(hr); |
279 | } |
280 | #endif |
281 | return(sec->addSectReloc(offset, *relSec, relocType)); |
282 | } |
283 | else |
284 | { |
285 | #ifdef EMIT_FIXUPS |
286 | CeeFileGenWriter * gen = reinterpret_cast<CeeFileGenWriter*>(&sec->ceeFile()); |
287 | HRESULT hr = gen->addFixup(*sec, offset, relocType); |
288 | if (FAILED(hr)) |
289 | { |
290 | return(hr); |
291 | } |
292 | #endif |
293 | return(sec->addBaseReloc(offset, relocType)); |
294 | } |
295 | } |
296 | |
297 | HRESULT ICeeFileGen::SetSectionDirectoryEntry(HCEESECTION section, ULONG num) |
298 | { |
299 | TESTANDRETURNPOINTER(section); |
300 | |
301 | printf("Warning: deprecated method. Use SetDirectoryEntry instead\n" ); |
302 | CeeSection *sec = reinterpret_cast<CeeSection*>(section); |
303 | return(sec->directoryEntry(num)); |
304 | } |
305 | |
306 | HRESULT ICeeFileGen::SetOutputFileName (HCEEFILE ceeFile, __in LPWSTR outputFileName) |
307 | { |
308 | TESTANDRETURNPOINTER(ceeFile); |
309 | TESTANDRETURNPOINTER(outputFileName); |
310 | |
311 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
312 | return(gen->setOutputFileName(outputFileName)); |
313 | } |
314 | |
315 | __success(return == S_OK) HRESULT ICeeFileGen::GetOutputFileName (HCEEFILE ceeFile, __out LPWSTR *outputFileName) |
316 | { |
317 | TESTANDRETURNPOINTER(ceeFile); |
318 | TESTANDRETURNPOINTER(outputFileName); |
319 | |
320 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
321 | TESTANDRETURNPOINTER(outputFileName); |
322 | *outputFileName = gen->getOutputFileName(); |
323 | return S_OK; |
324 | } |
325 | |
326 | |
327 | HRESULT ICeeFileGen::SetResourceFileName (HCEEFILE ceeFile, __in LPWSTR resourceFileName) |
328 | { |
329 | TESTANDRETURNPOINTER(ceeFile); |
330 | TESTANDRETURNPOINTER(resourceFileName); |
331 | |
332 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
333 | return(gen->setResourceFileName(resourceFileName)); |
334 | } |
335 | |
336 | __success(return == S_OK) |
337 | HRESULT ICeeFileGen::GetResourceFileName (HCEEFILE ceeFile, __out LPWSTR *resourceFileName) |
338 | { |
339 | TESTANDRETURNPOINTER(ceeFile); |
340 | TESTANDRETURNPOINTER(resourceFileName); |
341 | |
342 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
343 | TESTANDRETURNPOINTER(resourceFileName); |
344 | *resourceFileName = gen->getResourceFileName(); |
345 | return S_OK; |
346 | } |
347 | |
348 | |
349 | HRESULT ICeeFileGen::SetImageBase(HCEEFILE ceeFile, size_t imageBase) |
350 | { |
351 | TESTANDRETURNPOINTER(ceeFile); |
352 | |
353 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
354 | gen->setImageBase(imageBase); |
355 | return S_OK; |
356 | } |
357 | |
358 | HRESULT ICeeFileGen::SetImageBase64(HCEEFILE ceeFile, ULONGLONG imageBase) |
359 | { |
360 | TESTANDRETURNPOINTER(ceeFile); |
361 | |
362 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
363 | gen->setImageBase64(imageBase); |
364 | return S_OK; |
365 | } |
366 | |
367 | HRESULT ICeeFileGen::SetFileAlignment(HCEEFILE ceeFile, ULONG fileAlignment) |
368 | { |
369 | TESTANDRETURNPOINTER(ceeFile); |
370 | |
371 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
372 | gen->setFileAlignment(fileAlignment); |
373 | return S_OK; |
374 | } |
375 | |
376 | HRESULT ICeeFileGen::SetSubsystem(HCEEFILE ceeFile, DWORD subsystem, DWORD major, DWORD minor) |
377 | { |
378 | TESTANDRETURNPOINTER(ceeFile); |
379 | |
380 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
381 | gen->setSubsystem(subsystem, major, minor); |
382 | return S_OK; |
383 | } |
384 | |
385 | HRESULT ICeeFileGen::GetIMapTokenIface(HCEEFILE ceeFile, IMetaDataEmit *emitter, IUnknown **pIMapToken) |
386 | { |
387 | _ASSERTE(!"This is an obsolete function!" ); |
388 | return E_NOTIMPL; |
389 | } |
390 | |
391 | HRESULT ICeeFileGen::EmitMetaData (HCEEFILE ceeFile, IMetaDataEmit *emitter, |
392 | mdScope scopeE) |
393 | { |
394 | _ASSERTE(!"This is an obsolete function!" ); |
395 | return E_NOTIMPL; |
396 | } |
397 | |
398 | HRESULT ICeeFileGen::EmitLibraryName (HCEEFILE ceeFile, IMetaDataEmit *emitter, |
399 | mdScope scopeE) |
400 | { |
401 | _ASSERTE(!"This is an obsolete function!" ); |
402 | return E_NOTIMPL; |
403 | } |
404 | |
405 | HRESULT ICeeFileGen::GetMethodRVA(HCEEFILE ceeFile, ULONG codeOffset, ULONG *codeRVA) |
406 | { |
407 | TESTANDRETURNARG(ceeFile != 0); |
408 | TESTANDRETURNPOINTER(codeRVA); |
409 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
410 | gen->getMethodRVA(codeOffset, codeRVA); |
411 | return S_OK; |
412 | } |
413 | |
414 | HRESULT ICeeFileGen::EmitString(HCEEFILE ceeFile, __in LPWSTR strValue, ULONG *strRef) |
415 | { |
416 | TESTANDRETURNPOINTER(ceeFile); |
417 | |
418 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
419 | return(gen->getStringSection().getEmittedStringRef(strValue, strRef)); |
420 | } |
421 | |
422 | HRESULT ICeeFileGen::LinkCeeFile (HCEEFILE ceeFile) |
423 | { |
424 | TESTANDRETURNPOINTER(ceeFile); |
425 | |
426 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
427 | return gen->link(); |
428 | } |
429 | |
430 | HRESULT ICeeFileGen::FixupCeeFile (HCEEFILE ceeFile) |
431 | { |
432 | TESTANDRETURNPOINTER(ceeFile); |
433 | |
434 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
435 | return gen->fixup(); |
436 | } |
437 | |
438 | HRESULT ICeeFileGen:: (HCEEFILE ceeFile, PIMAGE_NT_HEADERS *, PIMAGE_SECTION_HEADER *ppSections, ULONG *pNumSections) |
439 | { |
440 | TESTANDRETURNPOINTER(ceeFile); |
441 | |
442 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
443 | gen->getPEWriter().getHeaderInfo(ppNtHeaders, ppSections, pNumSections); |
444 | return S_OK; |
445 | } |
446 | |
447 | HRESULT ICeeFileGen::GenerateCeeFile (HCEEFILE ceeFile) |
448 | { |
449 | SO_NOT_MAINLINE_FUNCTION; |
450 | |
451 | TESTANDRETURNPOINTER(ceeFile); |
452 | |
453 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
454 | return gen->generateImage(NULL); // NULL means don't write in-memory buffer, uses outputFileName |
455 | } |
456 | |
457 | // GenerateCeeMemoryImage - returns in ppImage an in-memory PE image allocated by CoTaskMemAlloc() |
458 | // the caller is responsible for calling CoTaskMemFree on this memory image |
459 | HRESULT ICeeFileGen::GenerateCeeMemoryImage (HCEEFILE ceeFile, void **ppImage) |
460 | { |
461 | TESTANDRETURNPOINTER(ceeFile); |
462 | TESTANDRETURNPOINTER(ppImage); |
463 | |
464 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
465 | return gen->generateImage(ppImage); |
466 | } |
467 | |
468 | HRESULT ICeeFileGen::SetEntryPoint(HCEEFILE ceeFile, mdMethodDef method) |
469 | { |
470 | TESTANDRETURNPOINTER(ceeFile); |
471 | |
472 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
473 | return gen->setEntryPoint(method); |
474 | } |
475 | |
476 | HRESULT ICeeFileGen::GetEntryPoint(HCEEFILE ceeFile, mdMethodDef *method) |
477 | { |
478 | TESTANDRETURNPOINTER(ceeFile); |
479 | |
480 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
481 | TESTANDRETURNPOINTER(method); |
482 | *method = gen->getEntryPoint(); |
483 | return S_OK; |
484 | } |
485 | |
486 | |
487 | HRESULT ICeeFileGen::SetComImageFlags (HCEEFILE ceeFile, DWORD mask) |
488 | { |
489 | TESTANDRETURNPOINTER(ceeFile); |
490 | |
491 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
492 | return gen->setComImageFlags(mask); |
493 | } |
494 | |
495 | HRESULT ICeeFileGen::ClearComImageFlags (HCEEFILE ceeFile, DWORD mask) |
496 | { |
497 | TESTANDRETURNPOINTER(ceeFile); |
498 | |
499 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
500 | return gen->clearComImageFlags(mask); |
501 | } |
502 | |
503 | HRESULT ICeeFileGen::GetComImageFlags (HCEEFILE ceeFile, DWORD *mask) |
504 | { |
505 | TESTANDRETURNPOINTER(ceeFile); |
506 | |
507 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
508 | TESTANDRETURNPOINTER(mask); |
509 | *mask = gen->getComImageFlags(); |
510 | return S_OK; |
511 | } |
512 | |
513 | |
514 | HRESULT ICeeFileGen::SetDllSwitch (HCEEFILE ceeFile, BOOL dllSwitch) |
515 | { |
516 | TESTANDRETURNPOINTER(ceeFile); |
517 | |
518 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
519 | return(gen->setDllSwitch(dllSwitch==TRUE)); |
520 | } |
521 | |
522 | HRESULT ICeeFileGen::GetDllSwitch (HCEEFILE ceeFile, BOOL *dllSwitch) |
523 | { |
524 | TESTANDRETURNPOINTER(ceeFile); |
525 | |
526 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
527 | TESTANDRETURNPOINTER(dllSwitch); |
528 | *dllSwitch = gen->getDllSwitch(); |
529 | return S_OK; |
530 | } |
531 | |
532 | HRESULT ICeeFileGen::SetObjSwitch (HCEEFILE ceeFile, BOOL objSwitch) |
533 | { |
534 | TESTANDRETURNPOINTER(ceeFile); |
535 | |
536 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
537 | return(gen->setObjSwitch(objSwitch==TRUE)); |
538 | } |
539 | |
540 | HRESULT ICeeFileGen::GetObjSwitch (HCEEFILE ceeFile, BOOL *objSwitch) |
541 | { |
542 | TESTANDRETURNPOINTER(ceeFile); |
543 | |
544 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
545 | TESTANDRETURNPOINTER(objSwitch); |
546 | *objSwitch = gen->getObjSwitch(); |
547 | return S_OK; |
548 | } |
549 | |
550 | |
551 | HRESULT ICeeFileGen::SetLibraryName (HCEEFILE ceeFile, __in LPWSTR LibraryName) |
552 | { |
553 | TESTANDRETURNPOINTER(ceeFile); |
554 | TESTANDRETURNPOINTER(LibraryName); |
555 | |
556 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
557 | return(gen->setLibraryName(LibraryName)); |
558 | } |
559 | |
560 | HRESULT ICeeFileGen::SetLibraryGuid (HCEEFILE ceeFile, __in LPWSTR LibraryGuid) |
561 | { |
562 | TESTANDRETURNPOINTER(ceeFile); |
563 | TESTANDRETURNPOINTER(LibraryGuid); |
564 | |
565 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
566 | return(gen->setLibraryGuid(LibraryGuid)); |
567 | } |
568 | |
569 | __success(return == S_OK) HRESULT ICeeFileGen::GetLibraryName (HCEEFILE ceeFile, __out LPWSTR *LibraryName) |
570 | { |
571 | TESTANDRETURNPOINTER(ceeFile); |
572 | TESTANDRETURNPOINTER(LibraryName); |
573 | |
574 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
575 | *LibraryName = gen->getLibraryName(); |
576 | return S_OK; |
577 | } |
578 | |
579 | |
580 | |
581 | HRESULT ICeeFileGen::EmitMetaDataEx (HCEEFILE ceeFile, IMetaDataEmit *emitter) |
582 | { |
583 | TESTANDRETURNPOINTER(ceeFile); |
584 | TESTANDRETURNPOINTER(emitter); |
585 | |
586 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
587 | return(gen->emitMetaData(emitter)); |
588 | } |
589 | |
590 | HRESULT ICeeFileGen::EmitMetaDataAt (HCEEFILE ceeFile, IMetaDataEmit *emitter, HCEESECTION section, DWORD offset, BYTE* buffer, unsigned buffLen) |
591 | { |
592 | TESTANDRETURNPOINTER(ceeFile); |
593 | TESTANDRETURNPOINTER(emitter); |
594 | |
595 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
596 | CeeSection* sec = reinterpret_cast<CeeSection*>(section); |
597 | |
598 | return(gen->emitMetaData(emitter, sec, offset, buffer, buffLen)); |
599 | } |
600 | |
601 | HRESULT ICeeFileGen::EmitLibraryNameEx (HCEEFILE ceeFile, IMetaDataEmit *emitter) |
602 | { |
603 | TESTANDRETURNPOINTER(ceeFile); |
604 | TESTANDRETURNPOINTER(emitter); |
605 | |
606 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
607 | return(gen->emitLibraryName(emitter)); |
608 | } |
609 | |
610 | HRESULT ICeeFileGen::GetIMapTokenIfaceEx(HCEEFILE ceeFile, IMetaDataEmit *emitter, IUnknown **pIMapToken) |
611 | { |
612 | TESTANDRETURNPOINTER(ceeFile); |
613 | TESTANDRETURNPOINTER(pIMapToken); |
614 | |
615 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
616 | return gen->getMapTokenIface(pIMapToken); |
617 | } |
618 | |
619 | HRESULT ICeeFileGen::AddNotificationHandler(HCEEFILE ceeFile, |
620 | IUnknown *pHandler) |
621 | { |
622 | TESTANDRETURNPOINTER(ceeFile); |
623 | TESTANDRETURNPOINTER(pHandler); |
624 | |
625 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
626 | return gen->addNotificationHandler(pHandler); |
627 | } |
628 | |
629 | HRESULT ICeeFileGen::EmitMacroDefinitions(HCEEFILE ceeFile, void *pData, DWORD cData) |
630 | { |
631 | TESTANDRETURNPOINTER(ceeFile); |
632 | |
633 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
634 | return gen->EmitMacroDefinitions(pData, cData); |
635 | } |
636 | |
637 | HRESULT ICeeFileGen::SetManifestEntry(HCEEFILE ceeFile, ULONG size, ULONG offset) |
638 | { |
639 | TESTANDRETURNPOINTER(ceeFile); |
640 | |
641 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
642 | return gen->setManifestEntry(size, offset); |
643 | } |
644 | |
645 | HRESULT ICeeFileGen::SetStrongNameEntry(HCEEFILE ceeFile, ULONG size, ULONG offset) |
646 | { |
647 | TESTANDRETURNPOINTER(ceeFile); |
648 | |
649 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
650 | return gen->setStrongNameEntry(size, offset); |
651 | } |
652 | |
653 | HRESULT ICeeFileGen::ComputeSectionOffset(HCEESECTION section, __in char *ptr, |
654 | unsigned *offset) |
655 | { |
656 | TESTANDRETURNPOINTER(section); |
657 | |
658 | CeeSection &sec = *(reinterpret_cast<CeeSection*>(section)); |
659 | |
660 | *offset = sec.computeOffset(ptr); |
661 | |
662 | return S_OK; |
663 | } |
664 | |
665 | __success(return == S_OK) |
666 | HRESULT ICeeFileGen::ComputeSectionPointer(HCEESECTION section, ULONG offset, |
667 | __out char **ptr) |
668 | { |
669 | TESTANDRETURNPOINTER(section); |
670 | |
671 | CeeSection &sec = *(reinterpret_cast<CeeSection*>(section)); |
672 | |
673 | *ptr = sec.computePointer(offset); |
674 | |
675 | return S_OK; |
676 | } |
677 | |
678 | HRESULT ICeeFileGen::ComputeOffset(HCEEFILE ceeFile, __in char *ptr, |
679 | HCEESECTION *pSection, unsigned *offset) |
680 | { |
681 | TESTANDRETURNPOINTER(pSection); |
682 | |
683 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
684 | |
685 | CeeSection *section; |
686 | |
687 | HRESULT hr = gen->computeOffset(ptr, §ion, offset); |
688 | |
689 | if (SUCCEEDED(hr)) |
690 | *pSection = reinterpret_cast<HCEESECTION>(section); |
691 | |
692 | return hr; |
693 | } |
694 | |
695 | HRESULT ICeeFileGen::SetEnCRVABase(HCEEFILE ceeFile, ULONG dataBase, ULONG rdataBase) |
696 | { |
697 | TESTANDRETURNPOINTER(ceeFile); |
698 | |
699 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
700 | return gen->setEnCRvaBase(dataBase, rdataBase); |
701 | } |
702 | |
703 | HRESULT ICeeFileGen::(HCEEFILE ceeFile, |
704 | IMAGE_COR20_HEADER **) |
705 | { |
706 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
707 | return gen->getCorHeader(header); |
708 | } |
709 | |
710 | HRESULT ICeeFileGen::SetVTableEntry(HCEEFILE ceeFile, ULONG size, ULONG offset) |
711 | { |
712 | TESTANDRETURNPOINTER(ceeFile); |
713 | |
714 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
715 | return gen->setVTableEntry(size, offset); |
716 | } |
717 | |
718 | HRESULT ICeeFileGen::SetVTableEntry64(HCEEFILE ceeFile, ULONG size, void* ptr) |
719 | { |
720 | TESTANDRETURNPOINTER(ceeFile); |
721 | |
722 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
723 | return gen->setVTableEntry64(size, ptr); |
724 | } |
725 | |
726 | HRESULT ICeeFileGen::GetFileTimeStamp (HCEEFILE ceeFile, DWORD *pTimeStamp) |
727 | { |
728 | TESTANDRETURNPOINTER(ceeFile); |
729 | TESTANDRETURNPOINTER(pTimeStamp); |
730 | |
731 | CeeFileGenWriter *gen = reinterpret_cast<CeeFileGenWriter*>(ceeFile); |
732 | return(gen->getFileTimeStamp(pTimeStamp)); |
733 | } |
734 | |
735 | |