2 * File pe_module.c - handle PE module information
4 * Copyright (C) 1996, Eric Youngdale.
5 * Copyright (C) 1999-2000, Ulrich Weigand.
6 * Copyright (C) 2004-2007, Eric Pouech.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
32 #include "dbghelp_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
38 /******************************************************************
39 * pe_locate_with_coff_symbol_table
41 * Use the COFF symbol table (if any) from the IMAGE_FILE_HEADER to set the absolute address
43 * Mingw32 requires this for stabs debug information as address for global variables isn't filled in
44 * (this is similar to what is done in elf_module.c when using the .symtab ELF section)
46 static BOOL
pe_locate_with_coff_symbol_table(struct module
* module
, IMAGE_NT_HEADERS
* nth
, void* mapping
)
48 const IMAGE_SYMBOL
* isym
;
53 struct hash_table_iter hti
;
55 struct symt_data
* sym
;
56 const IMAGE_SECTION_HEADER
* sect
;
58 numsym
= nth
->FileHeader
.NumberOfSymbols
;
59 if (!nth
->FileHeader
.PointerToSymbolTable
|| !numsym
)
61 isym
= (const IMAGE_SYMBOL
*)((char*)mapping
+ nth
->FileHeader
.PointerToSymbolTable
);
62 /* FIXME: no way to get strtable size */
63 strtable
= (const char*)&isym
[numsym
];
64 sect
= IMAGE_FIRST_SECTION(nth
);
66 for (i
= 0; i
< numsym
; i
+= naux
, isym
+= naux
)
68 if (isym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
&&
69 isym
->SectionNumber
> 0 && isym
->SectionNumber
<= nth
->FileHeader
.NumberOfSections
)
71 if (isym
->N
.Name
.Short
)
73 name
= memcpy(tmp
, isym
->N
.ShortName
, 8);
76 else name
= strtable
+ isym
->N
.Name
.Long
;
77 if (name
[0] == '_') name
++;
78 hash_table_iter_init(&module
->ht_symbols
, &hti
, name
);
79 while ((ptr
= hash_table_iter_up(&hti
)))
81 sym
= GET_ENTRY(ptr
, struct symt_data
, hash_elt
);
82 if (sym
->symt
.tag
== SymTagData
&&
83 (sym
->kind
== DataIsGlobal
|| sym
->kind
== DataIsFileStatic
) &&
84 !strcmp(sym
->hash_elt
.name
, name
))
86 TRACE("Changing absolute address for %d.%s: %lx -> %s\n",
87 isym
->SectionNumber
, name
, sym
->u
.var
.offset
,
88 wine_dbgstr_longlong(module
->module
.BaseOfImage
+
89 sect
[isym
->SectionNumber
- 1].VirtualAddress
+ isym
->Value
));
90 sym
->u
.var
.offset
= module
->module
.BaseOfImage
+
91 sect
[isym
->SectionNumber
- 1].VirtualAddress
+ isym
->Value
;
96 naux
= isym
->NumberOfAuxSymbols
+ 1;
101 /******************************************************************
102 * pe_load_coff_symbol_table
104 * Load public symbols out of the COFF symbol table (if any).
106 static BOOL
pe_load_coff_symbol_table(struct module
* module
, IMAGE_NT_HEADERS
* nth
, void* mapping
)
108 const IMAGE_SYMBOL
* isym
;
110 const char* strtable
;
113 const char* lastfilename
= NULL
;
114 struct symt_compiland
* compiland
= NULL
;
115 const IMAGE_SECTION_HEADER
* sect
;
117 numsym
= nth
->FileHeader
.NumberOfSymbols
;
118 if (!nth
->FileHeader
.PointerToSymbolTable
|| !numsym
)
120 isym
= (const IMAGE_SYMBOL
*)((char*)mapping
+ nth
->FileHeader
.PointerToSymbolTable
);
121 /* FIXME: no way to get strtable size */
122 strtable
= (const char*)&isym
[numsym
];
123 sect
= IMAGE_FIRST_SECTION(nth
);
125 for (i
= 0; i
< numsym
; i
+= naux
, isym
+= naux
)
127 if (isym
->StorageClass
== IMAGE_SYM_CLASS_FILE
)
129 lastfilename
= (const char*)(isym
+ 1);
132 if (isym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
&&
133 isym
->SectionNumber
> 0 && isym
->SectionNumber
<= nth
->FileHeader
.NumberOfSections
)
135 if (isym
->N
.Name
.Short
)
137 name
= memcpy(tmp
, isym
->N
.ShortName
, 8);
140 else name
= strtable
+ isym
->N
.Name
.Long
;
141 if (name
[0] == '_') name
++;
143 if (!compiland
&& lastfilename
)
144 compiland
= symt_new_compiland(module
, 0,
145 source_new(module
, NULL
, lastfilename
));
146 symt_new_public(module
, compiland
, name
,
147 module
->module
.BaseOfImage
+ sect
[isym
->SectionNumber
- 1].VirtualAddress
+ isym
->Value
,
150 naux
= isym
->NumberOfAuxSymbols
+ 1;
152 module
->module
.SymType
= SymCoff
;
153 module
->module
.LineNumbers
= FALSE
;
154 module
->module
.GlobalSymbols
= FALSE
;
155 module
->module
.TypeInfo
= FALSE
;
156 module
->module
.SourceIndexed
= FALSE
;
157 module
->module
.Publics
= TRUE
;
162 static inline void* pe_get_sect(IMAGE_NT_HEADERS
* nth
, void* mapping
,
163 IMAGE_SECTION_HEADER
* sect
)
165 return (sect
) ? RtlImageRvaToVa(nth
, mapping
, sect
->VirtualAddress
, NULL
) : NULL
;
168 static inline DWORD
pe_get_sect_size(IMAGE_SECTION_HEADER
* sect
)
170 return (sect
) ? sect
->SizeOfRawData
: 0;
173 /******************************************************************
176 * look for stabs information in PE header (it's how the mingw compiler provides
177 * its debugging information)
179 static BOOL
pe_load_stabs(const struct process
* pcs
, struct module
* module
,
180 void* mapping
, IMAGE_NT_HEADERS
* nth
)
182 IMAGE_SECTION_HEADER
* section
;
183 IMAGE_SECTION_HEADER
* sect_stabs
= NULL
;
184 IMAGE_SECTION_HEADER
* sect_stabstr
= NULL
;
188 section
= (IMAGE_SECTION_HEADER
*)
189 ((char*)&nth
->OptionalHeader
+ nth
->FileHeader
.SizeOfOptionalHeader
);
190 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, section
++)
192 if (!strcasecmp((const char*)section
->Name
, ".stab")) sect_stabs
= section
;
193 else if (!strncasecmp((const char*)section
->Name
, ".stabstr", 8)) sect_stabstr
= section
;
195 if (sect_stabs
&& sect_stabstr
)
197 ret
= stabs_parse(module
,
198 module
->module
.BaseOfImage
- nth
->OptionalHeader
.ImageBase
,
199 pe_get_sect(nth
, mapping
, sect_stabs
), pe_get_sect_size(sect_stabs
),
200 pe_get_sect(nth
, mapping
, sect_stabstr
), pe_get_sect_size(sect_stabstr
),
202 if (ret
) pe_locate_with_coff_symbol_table(module
, nth
, mapping
);
204 TRACE("%s the STABS debug info\n", ret
? "successfully loaded" : "failed to load");
209 /******************************************************************
212 * look for dwarf information in PE header (it's also a way for the mingw compiler
213 * to provide its debugging information)
215 static BOOL
pe_load_dwarf(const struct process
* pcs
, struct module
* module
,
216 void* mapping
, IMAGE_NT_HEADERS
* nth
)
218 IMAGE_SECTION_HEADER
* section
;
219 IMAGE_SECTION_HEADER
* sect_debuginfo
= NULL
;
220 IMAGE_SECTION_HEADER
* sect_debugstr
= NULL
;
221 IMAGE_SECTION_HEADER
* sect_debugabbrev
= NULL
;
222 IMAGE_SECTION_HEADER
* sect_debugline
= NULL
;
223 IMAGE_SECTION_HEADER
* sect_debugloc
= NULL
;
225 const char* strtable
;
226 const char* sectname
;
229 if (nth
->FileHeader
.PointerToSymbolTable
&& nth
->FileHeader
.NumberOfSymbols
)
230 /* FIXME: no way to get strtable size */
231 strtable
= (const char*)mapping
+ nth
->FileHeader
.PointerToSymbolTable
+
232 nth
->FileHeader
.NumberOfSymbols
* sizeof(IMAGE_SYMBOL
);
233 else strtable
= NULL
;
235 section
= (IMAGE_SECTION_HEADER
*)
236 ((char*)&nth
->OptionalHeader
+ nth
->FileHeader
.SizeOfOptionalHeader
);
237 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, section
++)
239 sectname
= (const char*)section
->Name
;
240 /* long section names start with a '/' (at least on MinGW32) */
241 if (*sectname
== '/' && strtable
)
242 sectname
= strtable
+ atoi(sectname
+ 1);
243 if (!strcasecmp(sectname
, ".debug_info")) sect_debuginfo
= section
;
244 else if (!strcasecmp(sectname
, ".debug_str")) sect_debugstr
= section
;
245 else if (!strcasecmp(sectname
, ".debug_abbrev")) sect_debugabbrev
= section
;
246 else if (!strcasecmp(sectname
, ".debug_line")) sect_debugline
= section
;
247 else if (!strcasecmp(sectname
, ".debug_loc")) sect_debugloc
= section
;
251 ret
= dwarf2_parse(module
,
252 module
->module
.BaseOfImage
- nth
->OptionalHeader
.ImageBase
,
253 NULL
, /* FIXME: some thunks to deal with ? */
254 pe_get_sect(nth
, mapping
, sect_debuginfo
), pe_get_sect_size(sect_debuginfo
),
255 pe_get_sect(nth
, mapping
, sect_debugabbrev
), pe_get_sect_size(sect_debugabbrev
),
256 pe_get_sect(nth
, mapping
, sect_debugstr
), pe_get_sect_size(sect_debugstr
),
257 pe_get_sect(nth
, mapping
, sect_debugline
), pe_get_sect_size(sect_debugline
),
258 pe_get_sect(nth
, mapping
, sect_debugloc
), pe_get_sect_size(sect_debugloc
));
260 TRACE("%s the DWARF debug info\n", ret
? "successfully loaded" : "failed to load");
265 /******************************************************************
270 static BOOL
pe_load_dbg_file(const struct process
* pcs
, struct module
* module
,
271 const char* dbg_name
, DWORD timestamp
)
274 HANDLE hFile
= INVALID_HANDLE_VALUE
, hMap
= 0;
275 const BYTE
* dbg_mapping
= NULL
;
278 TRACE("Processing DBG file %s\n", debugstr_a(dbg_name
));
280 if (path_find_symbol_file(pcs
, dbg_name
, NULL
, timestamp
, 0, tmp
, &module
->module
.DbgUnmatched
) &&
281 (hFile
= CreateFileA(tmp
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
282 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
&&
283 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) != 0) &&
284 ((dbg_mapping
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) != NULL
))
286 const IMAGE_SEPARATE_DEBUG_HEADER
* hdr
;
287 const IMAGE_SECTION_HEADER
* sectp
;
288 const IMAGE_DEBUG_DIRECTORY
* dbg
;
290 hdr
= (const IMAGE_SEPARATE_DEBUG_HEADER
*)dbg_mapping
;
291 /* section headers come immediately after debug header */
292 sectp
= (const IMAGE_SECTION_HEADER
*)(hdr
+ 1);
293 /* and after that and the exported names comes the debug directory */
294 dbg
= (const IMAGE_DEBUG_DIRECTORY
*)
295 (dbg_mapping
+ sizeof(*hdr
) +
296 hdr
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
) +
297 hdr
->ExportedNamesSize
);
299 ret
= pe_load_debug_directory(pcs
, module
, dbg_mapping
, sectp
,
300 hdr
->NumberOfSections
, dbg
,
301 hdr
->DebugDirectorySize
/ sizeof(*dbg
));
304 ERR("Couldn't find .DBG file %s (%s)\n", debugstr_a(dbg_name
), debugstr_a(tmp
));
306 if (dbg_mapping
) UnmapViewOfFile(dbg_mapping
);
307 if (hMap
) CloseHandle(hMap
);
308 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
312 /******************************************************************
313 * pe_load_msc_debug_info
315 * Process MSC debug information in PE file.
317 static BOOL
pe_load_msc_debug_info(const struct process
* pcs
,
318 struct module
* module
,
319 void* mapping
, const IMAGE_NT_HEADERS
* nth
)
322 const IMAGE_DATA_DIRECTORY
* dir
;
323 const IMAGE_DEBUG_DIRECTORY
*dbg
= NULL
;
326 /* Read in debug directory */
327 dir
= nth
->OptionalHeader
.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_DEBUG
;
328 nDbg
= dir
->Size
/ sizeof(IMAGE_DEBUG_DIRECTORY
);
329 if (!nDbg
) return FALSE
;
331 dbg
= RtlImageRvaToVa(nth
, mapping
, dir
->VirtualAddress
, NULL
);
333 /* Parse debug directory */
334 if (nth
->FileHeader
.Characteristics
& IMAGE_FILE_DEBUG_STRIPPED
)
336 /* Debug info is stripped to .DBG file */
337 const IMAGE_DEBUG_MISC
* misc
= (const IMAGE_DEBUG_MISC
*)
338 ((const char*)mapping
+ dbg
->PointerToRawData
);
340 if (nDbg
!= 1 || dbg
->Type
!= IMAGE_DEBUG_TYPE_MISC
||
341 misc
->DataType
!= IMAGE_DEBUG_MISC_EXENAME
)
343 WINE_ERR("-Debug info stripped, but no .DBG file in module %s\n",
344 debugstr_w(module
->module
.ModuleName
));
348 ret
= pe_load_dbg_file(pcs
, module
, (const char*)misc
->Data
, nth
->FileHeader
.TimeDateStamp
);
353 const IMAGE_SECTION_HEADER
*sectp
= (const IMAGE_SECTION_HEADER
*)((const char*)&nth
->OptionalHeader
+ nth
->FileHeader
.SizeOfOptionalHeader
);
354 /* Debug info is embedded into PE module */
355 ret
= pe_load_debug_directory(pcs
, module
, mapping
, sectp
,
356 nth
->FileHeader
.NumberOfSections
, dbg
, nDbg
);
362 /***********************************************************************
363 * pe_load_export_debug_info
365 static BOOL
pe_load_export_debug_info(const struct process
* pcs
,
366 struct module
* module
,
367 void* mapping
, const IMAGE_NT_HEADERS
* nth
)
370 const IMAGE_EXPORT_DIRECTORY
* exports
;
371 DWORD base
= module
->module
.BaseOfImage
;
374 if (dbghelp_options
& SYMOPT_NO_PUBLICS
) return TRUE
;
377 /* Add start of DLL (better use the (yet unimplemented) Exe SymTag for this) */
378 /* FIXME: module.ModuleName isn't correctly set yet if it's passed in SymLoadModule */
379 symt_new_public(module
, NULL
, module
->module
.ModuleName
, base
, 1);
382 /* Add entry point */
383 symt_new_public(module
, NULL
, "EntryPoint",
384 base
+ nth
->OptionalHeader
.AddressOfEntryPoint
, 1);
386 /* FIXME: we'd better store addresses linked to sections rather than
388 IMAGE_SECTION_HEADER
* section
;
389 /* Add start of sections */
390 section
= (IMAGE_SECTION_HEADER
*)
391 ((char*)&nth
->OptionalHeader
+ nth
->FileHeader
.SizeOfOptionalHeader
);
392 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, section
++)
394 symt_new_public(module
, NULL
, section
->Name
,
395 RtlImageRvaToVa(nth
, mapping
, section
->VirtualAddress
, NULL
), 1);
399 /* Add exported functions */
400 if ((exports
= RtlImageDirectoryEntryToData(mapping
, FALSE
,
401 IMAGE_DIRECTORY_ENTRY_EXPORT
, &size
)))
403 const WORD
* ordinals
= NULL
;
404 const DWORD_PTR
* functions
= NULL
;
405 const DWORD
* names
= NULL
;
409 functions
= RtlImageRvaToVa(nth
, mapping
, exports
->AddressOfFunctions
, NULL
);
410 ordinals
= RtlImageRvaToVa(nth
, mapping
, exports
->AddressOfNameOrdinals
, NULL
);
411 names
= RtlImageRvaToVa(nth
, mapping
, exports
->AddressOfNames
, NULL
);
413 if (functions
&& ordinals
&& names
)
415 for (i
= 0; i
< exports
->NumberOfNames
; i
++)
417 if (!names
[i
]) continue;
418 symt_new_public(module
, NULL
,
419 RtlImageRvaToVa(nth
, mapping
, names
[i
], NULL
),
420 base
+ functions
[ordinals
[i
]], 1);
423 for (i
= 0; i
< exports
->NumberOfFunctions
; i
++)
425 if (!functions
[i
]) continue;
426 /* Check if we already added it with a name */
427 for (j
= 0; j
< exports
->NumberOfNames
; j
++)
428 if ((ordinals
[j
] == i
) && names
[j
]) break;
429 if (j
< exports
->NumberOfNames
) continue;
430 snprintf(buffer
, sizeof(buffer
), "%d", i
+ exports
->Base
);
431 symt_new_public(module
, NULL
, buffer
, base
+ (DWORD
)functions
[i
], 1);
435 /* no real debug info, only entry points */
436 if (module
->module
.SymType
== SymDeferred
)
437 module
->module
.SymType
= SymExport
;
441 /******************************************************************
445 BOOL
pe_load_debug_info(const struct process
* pcs
, struct module
* module
)
451 IMAGE_NT_HEADERS
* nth
;
453 hFile
= CreateFileW(module
->module
.LoadedImageName
, GENERIC_READ
, FILE_SHARE_READ
,
454 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
455 if (hFile
== INVALID_HANDLE_VALUE
) return ret
;
456 if ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) != 0)
458 if ((mapping
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) != NULL
)
460 nth
= RtlImageNtHeader(mapping
);
462 if (!(dbghelp_options
& SYMOPT_PUBLICS_ONLY
))
464 ret
= pe_load_stabs(pcs
, module
, mapping
, nth
) ||
465 pe_load_dwarf(pcs
, module
, mapping
, nth
) ||
466 pe_load_msc_debug_info(pcs
, module
, mapping
, nth
) ||
467 pe_load_coff_symbol_table(module
, nth
, mapping
);
468 /* if we still have no debug info (we could only get SymExport at this
469 * point), then do the SymExport except if we have an ELF container,
470 * in which case we'll rely on the export's on the ELF side
473 /* FIXME shouldn't we check that? if (!module_get_debug(pcs, module))l */
474 if (pe_load_export_debug_info(pcs
, module
, mapping
, nth
) && !ret
)
476 UnmapViewOfFile(mapping
);
485 /******************************************************************
486 * pe_load_native_module
489 struct module
* pe_load_native_module(struct process
* pcs
, const WCHAR
* name
,
490 HANDLE hFile
, DWORD base
, DWORD size
)
492 struct module
* module
= NULL
;
495 WCHAR loaded_name
[MAX_PATH
];
497 loaded_name
[0] = '\0';
503 if ((hFile
= FindExecutableImageExW(name
, pcs
->search_path
, loaded_name
, NULL
, NULL
)) == NULL
)
507 else if (name
) strcpyW(loaded_name
, name
);
508 else if (dbghelp_options
& SYMOPT_DEFERRED_LOADS
)
509 FIXME("Trouble ahead (no module name passed in deferred mode)\n");
511 if ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) != NULL
)
515 if ((mapping
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) != NULL
)
517 IMAGE_NT_HEADERS
* nth
= RtlImageNtHeader(mapping
);
521 if (!base
) base
= nth
->OptionalHeader
.ImageBase
;
522 if (!size
) size
= nth
->OptionalHeader
.SizeOfImage
;
524 module
= module_new(pcs
, loaded_name
, DMT_PE
, FALSE
, base
, size
,
525 nth
->FileHeader
.TimeDateStamp
,
526 nth
->OptionalHeader
.CheckSum
);
529 if (dbghelp_options
& SYMOPT_DEFERRED_LOADS
)
530 module
->module
.SymType
= SymDeferred
;
532 pe_load_debug_info(pcs
, module
);
535 ERR("could not load the module '%s'\n", debugstr_w(loaded_name
));
537 UnmapViewOfFile(mapping
);
541 if (opened
) CloseHandle(hFile
);
546 /******************************************************************
550 BOOL
pe_load_nt_header(HANDLE hProc
, DWORD64 base
, IMAGE_NT_HEADERS
* nth
)
552 IMAGE_DOS_HEADER dos
;
554 return ReadProcessMemory(hProc
, (char*)(DWORD_PTR
)base
, &dos
, sizeof(dos
), NULL
) &&
555 dos
.e_magic
== IMAGE_DOS_SIGNATURE
&&
556 ReadProcessMemory(hProc
, (char*)(DWORD_PTR
)(base
+ dos
.e_lfanew
),
557 nth
, sizeof(*nth
), NULL
) &&
558 nth
->Signature
== IMAGE_NT_SIGNATURE
;
561 /******************************************************************
562 * pe_load_builtin_module
565 struct module
* pe_load_builtin_module(struct process
* pcs
, const WCHAR
* name
,
566 DWORD64 base
, DWORD64 size
)
568 struct module
* module
= NULL
;
570 if (base
&& pcs
->dbg_hdr_addr
)
572 IMAGE_NT_HEADERS nth
;
574 if (pe_load_nt_header(pcs
->handle
, base
, &nth
))
576 if (!size
) size
= nth
.OptionalHeader
.SizeOfImage
;
577 module
= module_new(pcs
, name
, DMT_PE
, FALSE
, base
, size
,
578 nth
.FileHeader
.TimeDateStamp
,
579 nth
.OptionalHeader
.CheckSum
);
585 /***********************************************************************
586 * ImageDirectoryEntryToDataEx (DBGHELP.@)
588 * Search for specified directory in PE image
592 * base [in] Image base address
593 * image [in] TRUE - image has been loaded by loader, FALSE - raw file image
594 * dir [in] Target directory index
595 * size [out] Receives directory size
596 * section [out] Receives pointer to section header of section containing directory data
599 * Success: pointer to directory data
603 PVOID WINAPI
ImageDirectoryEntryToDataEx( PVOID base
, BOOLEAN image
, USHORT dir
, PULONG size
, PIMAGE_SECTION_HEADER
*section
)
605 const IMAGE_NT_HEADERS
*nt
;
609 if (section
) *section
= NULL
;
611 if (!(nt
= RtlImageNtHeader( base
))) return NULL
;
612 if (dir
>= nt
->OptionalHeader
.NumberOfRvaAndSizes
) return NULL
;
613 if (!(addr
= nt
->OptionalHeader
.DataDirectory
[dir
].VirtualAddress
)) return NULL
;
615 *size
= nt
->OptionalHeader
.DataDirectory
[dir
].Size
;
616 if (image
|| addr
< nt
->OptionalHeader
.SizeOfHeaders
) return (char *)base
+ addr
;
618 return RtlImageRvaToVa( nt
, base
, addr
, section
);
621 /***********************************************************************
622 * ImageDirectoryEntryToData (DBGHELP.@)
625 * See ImageDirectoryEntryToDataEx
627 PVOID WINAPI
ImageDirectoryEntryToData( PVOID base
, BOOLEAN image
, USHORT dir
, PULONG size
)
629 return ImageDirectoryEntryToDataEx( base
, image
, dir
, size
, NULL
);