VirtualBox

source: vbox/trunk/include/iprt/ldr.h@ 81025

Last change on this file since 81025 was 79559, checked in by vboxsync, 5 years ago

IPRT/process-creation-posix.cpp: Try to dynamically resolve crypt_r on linux. [adjustments] ticketref:18682

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.6 KB
Line 
1/** @file
2 * IPRT - Loader.
3 */
4
5/*
6 * Copyright (C) 2006-2019 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_ldr_h
27#define IPRT_INCLUDED_ldr_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34
35
36/** @defgroup grp_ldr RTLdr - Loader
37 * @ingroup grp_rt
38 * @{
39 */
40
41
42RT_C_DECLS_BEGIN
43
44/** Loader address (unsigned integer). */
45typedef RTUINTPTR RTLDRADDR;
46/** Pointer to a loader address. */
47typedef RTLDRADDR *PRTLDRADDR;
48/** Pointer to a const loader address. */
49typedef RTLDRADDR const *PCRTLDRADDR;
50/** The max loader address value. */
51#define RTLDRADDR_MAX RTUINTPTR_MAX
52/** NIL loader address value. */
53#define NIL_RTLDRADDR RTLDRADDR_MAX
54
55
56/**
57 * Loader module format.
58 */
59typedef enum RTLDRFMT
60{
61 /** The usual invalid 0 format. */
62 RTLDRFMT_INVALID = 0,
63 /** The native OS loader. */
64 RTLDRFMT_NATIVE,
65 /** The AOUT loader. */
66 RTLDRFMT_AOUT,
67 /** The ELF loader. */
68 RTLDRFMT_ELF,
69 /** The LX loader. */
70 RTLDRFMT_LX,
71 /** The Mach-O loader. */
72 RTLDRFMT_MACHO,
73 /** The PE loader. */
74 RTLDRFMT_PE,
75 /** The end of the valid format values (exclusive). */
76 RTLDRFMT_END,
77 /** Hack to blow the type up to 32-bit. */
78 RTLDRFMT_32BIT_HACK = 0x7fffffff
79} RTLDRFMT;
80
81
82/**
83 * Loader module type.
84 */
85typedef enum RTLDRTYPE
86{
87 /** The usual invalid 0 type. */
88 RTLDRTYPE_INVALID = 0,
89 /** Object file. */
90 RTLDRTYPE_OBJECT,
91 /** Executable module, fixed load address. */
92 RTLDRTYPE_EXECUTABLE_FIXED,
93 /** Executable module, relocatable, non-fixed load address. */
94 RTLDRTYPE_EXECUTABLE_RELOCATABLE,
95 /** Executable module, position independent code, non-fixed load address. */
96 RTLDRTYPE_EXECUTABLE_PIC,
97 /** Shared library, fixed load address.
98 * Typically a system library. */
99 RTLDRTYPE_SHARED_LIBRARY_FIXED,
100 /** Shared library, relocatable, non-fixed load address. */
101 RTLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
102 /** Shared library, position independent code, non-fixed load address. */
103 RTLDRTYPE_SHARED_LIBRARY_PIC,
104 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
105 RTLDRTYPE_FORWARDER_DLL,
106 /** Core or dump. */
107 RTLDRTYPE_CORE,
108 /** Debug module (debug info with empty code & data segments). */
109 RTLDRTYPE_DEBUG_INFO,
110 /** The end of the valid types values (exclusive). */
111 RTLDRTYPE_END,
112 /** Hack to blow the type up to 32-bit. */
113 RTLDRTYPE_32BIT_HACK = 0x7fffffff
114} RTLDRTYPE;
115
116
117/**
118 * Loader endian indicator.
119 */
120typedef enum RTLDRENDIAN
121{
122 /** The usual invalid endian. */
123 RTLDRENDIAN_INVALID,
124 /** Little endian. */
125 RTLDRENDIAN_LITTLE,
126 /** Bit endian. */
127 RTLDRENDIAN_BIG,
128 /** Endianness doesn't have a meaning in the context. */
129 RTLDRENDIAN_NA,
130 /** The end of the valid endian values (exclusive). */
131 RTLDRENDIAN_END,
132 /** Hack to blow the type up to 32-bit. */
133 RTLDRENDIAN_32BIT_HACK = 0x7fffffff
134} RTLDRENDIAN;
135
136
137/** Pointer to a loader reader instance. */
138typedef struct RTLDRREADER *PRTLDRREADER;
139/**
140 * Loader image reader instance.
141 *
142 * @remarks The reader will typically have a larger structure wrapping this one
143 * for storing necessary instance variables.
144 *
145 * The loader ASSUMES the caller serializes all access to the
146 * individual loader module handlers, thus no serialization is required
147 * when implementing this interface.
148 */
149typedef struct RTLDRREADER
150{
151 /** Magic value (RTLDRREADER_MAGIC). */
152 uintptr_t uMagic;
153
154 /**
155 * Reads bytes at a give place in the raw image.
156 *
157 * @returns iprt status code.
158 * @param pReader Pointer to the reader instance.
159 * @param pvBuf Where to store the bits.
160 * @param cb Number of bytes to read.
161 * @param off Where to start reading relative to the start of the raw image.
162 */
163 DECLCALLBACKMEMBER(int, pfnRead)(PRTLDRREADER pReader, void *pvBuf, size_t cb, RTFOFF off);
164
165 /**
166 * Tells end position of last read.
167 *
168 * @returns position relative to start of the raw image.
169 * @param pReader Pointer to the reader instance.
170 */
171 DECLCALLBACKMEMBER(RTFOFF, pfnTell)(PRTLDRREADER pReader);
172
173 /**
174 * Gets the size of the raw image bits.
175 *
176 * @returns size of raw image bits in bytes.
177 * @param pReader Pointer to the reader instance.
178 */
179 DECLCALLBACKMEMBER(uint64_t, pfnSize)(PRTLDRREADER pReader);
180
181 /**
182 * Map the bits into memory.
183 *
184 * The mapping will be freed upon calling pfnDestroy() if not pfnUnmap()
185 * is called before that. The mapping is read only.
186 *
187 * @returns iprt status code.
188 * @param pReader Pointer to the reader instance.
189 * @param ppvBits Where to store the address of the memory mapping on success.
190 * The size of the mapping can be obtained by calling pfnSize().
191 */
192 DECLCALLBACKMEMBER(int, pfnMap)(PRTLDRREADER pReader, const void **ppvBits);
193
194 /**
195 * Unmap bits.
196 *
197 * @returns iprt status code.
198 * @param pReader Pointer to the reader instance.
199 * @param pvBits Memory pointer returned by pfnMap().
200 */
201 DECLCALLBACKMEMBER(int, pfnUnmap)(PRTLDRREADER pReader, const void *pvBits);
202
203 /**
204 * Gets the most appropriate log name.
205 *
206 * @returns Pointer to readonly log name.
207 * @param pReader Pointer to the reader instance.
208 */
209 DECLCALLBACKMEMBER(const char *, pfnLogName)(PRTLDRREADER pReader);
210
211 /**
212 * Releases all resources associated with the reader instance.
213 * The instance is invalid after this call returns.
214 *
215 * @returns iprt status code.
216 * @param pReader Pointer to the reader instance.
217 */
218 DECLCALLBACKMEMBER(int, pfnDestroy)(PRTLDRREADER pReader);
219} RTLDRREADER;
220
221/** Magic value for RTLDRREADER (Gordon Matthew Thomas Sumner / Sting). */
222#define RTLDRREADER_MAGIC UINT32_C(0x19511002)
223
224
225/**
226 * Gets the default file suffix for DLL/SO/DYLIB/whatever.
227 *
228 * @returns The stuff (readonly).
229 */
230RTDECL(const char *) RTLdrGetSuff(void);
231
232/**
233 * Checks if a library is loadable or not.
234 *
235 * This may attempt load and unload the library.
236 *
237 * @returns true/false accordingly.
238 * @param pszFilename Image filename.
239 */
240RTDECL(bool) RTLdrIsLoadable(const char *pszFilename);
241
242/**
243 * Loads a dynamic load library (/shared object) image file using native
244 * OS facilities.
245 *
246 * The filename will be appended the default DLL/SO extension of
247 * the platform if it have been omitted. This means that it's not
248 * possible to load DLLs/SOs with no extension using this interface,
249 * but that's not a bad tradeoff.
250 *
251 * If no path is specified in the filename, the OS will usually search it's library
252 * path to find the image file.
253 *
254 * @returns iprt status code.
255 * @param pszFilename Image filename.
256 * @param phLdrMod Where to store the handle to the loader module.
257 */
258RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
259
260/**
261 * Loads a dynamic load library (/shared object) image file using native
262 * OS facilities.
263 *
264 * The filename will be appended the default DLL/SO extension of
265 * the platform if it have been omitted. This means that it's not
266 * possible to load DLLs/SOs with no extension using this interface,
267 * but that's not a bad tradeoff.
268 *
269 * If no path is specified in the filename, the OS will usually search it's library
270 * path to find the image file.
271 *
272 * @returns iprt status code.
273 * @param pszFilename Image filename.
274 * @param phLdrMod Where to store the handle to the loader module.
275 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
276 * @param pErrInfo Where to return extended error information. Optional.
277 */
278RTDECL(int) RTLdrLoadEx(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
279
280/** @defgroup RTLDRLOAD_FLAGS_XXX Flags for RTLdrLoadEx, RTLdrLoadSystemEx and RTLdrGetSystemSymbolEx
281 * @{ */
282/** Symbols defined in this library are not made available to resolve
283 * references in subsequently loaded libraries (default). */
284#define RTLDRLOAD_FLAGS_LOCAL UINT32_C(0)
285/** Symbols defined in this library will be made available for symbol
286 * resolution of subsequently loaded libraries. */
287#define RTLDRLOAD_FLAGS_GLOBAL RT_BIT_32(0)
288/** Do not unload the library upon RTLdrClose. (For system libs.) */
289#define RTLDRLOAD_FLAGS_NO_UNLOAD RT_BIT_32(1)
290/** Windows/NT: Search the DLL load directory for imported DLLs - W7,
291 * Vista, and W2K8 requires KB2533623 to be installed to support this; not
292 * supported on XP, W2K3 or earlier. Ignored on other platforms. */
293#define RTLDRLOAD_FLAGS_NT_SEARCH_DLL_LOAD_DIR RT_BIT_32(2)
294/** Do not append default suffix. */
295#define RTLDRLOAD_FLAGS_NO_SUFFIX RT_BIT_32(3)
296/** Shift for the first .so.MAJOR version number to try.
297 * Only applicable to RTLdrLoadSystemEx() and RTLdrGetSystemSymbolEx(). */
298#define RTLDRLOAD_FLAGS_SO_VER_BEGIN_SHIFT 12
299/** Mask for the first .so.MAJOR version number to try.
300 * Only applicable to RTLdrLoadSystemEx() and RTLdrGetSystemSymbolEx(). */
301#define RTLDRLOAD_FLAGS_SO_VER_BEGIN_MASK UINT32_C(0x003ff000)
302/** Shift for the end .so.MAJOR version number (exclusive).
303 * Only applicable to RTLdrLoadSystemEx() and RTLdrGetSystemSymbolEx(). */
304#define RTLDRLOAD_FLAGS_SO_VER_END_SHIFT 22
305/** Mask for the end .so.MAJOR version number (exclusive).
306 * Only applicable to RTLdrLoadSystemEx() and RTLdrGetSystemSymbolEx(). */
307#define RTLDRLOAD_FLAGS_SO_VER_END_MASK UINT32_C(0xffc00000)
308/** Specifies the range for the .so.MAJOR version number.
309 * Only applicable to RTLdrLoadSystemEx() and RTLdrGetSystemSymbolEx().
310 * Ignored on systems not using .so.
311 * @param a_uBegin The first version to try.
312 * @param a_uEnd The version number to stop at (exclusive).
313 */
314#define RTLDRLOAD_FLAGS_SO_VER_RANGE(a_uBegin, a_uEnd) \
315 ( ((a_uBegin) << RTLDRLOAD_FLAGS_SO_VER_BEGIN_SHIFT) | ((a_uEnd) << RTLDRLOAD_FLAGS_SO_VER_END_SHIFT) )
316/** The mask of valid flag bits.
317 * The shared object major version range is excluded. */
318#define RTLDRLOAD_FLAGS_VALID_MASK UINT32_C(0x0000000f)
319/** @} */
320
321/**
322 * Loads a dynamic load library (/shared object) image file residing in one of
323 * the default system library locations.
324 *
325 * Only the system library locations are searched. No suffix is required.
326 *
327 * @returns iprt status code.
328 * @param pszFilename Image filename. No path.
329 * @param fNoUnload Do not unload the library when RTLdrClose is called.
330 * @param phLdrMod Where to store the handle to the loaded module.
331 */
332RTDECL(int) RTLdrLoadSystem(const char *pszFilename, bool fNoUnload, PRTLDRMOD phLdrMod);
333
334/**
335 * Loads a dynamic load library (/shared object) image file residing in one of
336 * the default system library locations, extended version.
337 *
338 * Only the system library locations are searched. No suffix is required.
339 *
340 * @returns iprt status code.
341 * @param pszFilename Image filename. No path.
342 * @param fFlags RTLDRLOAD_FLAGS_XXX, including RTLDRLOAD_FLAGS_SO_VER_XXX.
343 * @param phLdrMod Where to store the handle to the loaded module.
344 */
345RTDECL(int) RTLdrLoadSystemEx(const char *pszFilename, uint32_t fFlags, PRTLDRMOD phLdrMod);
346
347/**
348 * Combines RTLdrLoadSystem and RTLdrGetSymbol, with fNoUnload set to true.
349 *
350 * @returns The symbol value, NULL on failure. (If you care for a less boolean
351 * status, go thru the necessary API calls yourself.)
352 * @param pszFilename Image filename. No path.
353 * @param pszSymbol Symbol name.
354 */
355RTDECL(void *) RTLdrGetSystemSymbol(const char *pszFilename, const char *pszSymbol);
356
357/**
358 * Combines RTLdrLoadSystemEx and RTLdrGetSymbol.
359 *
360 * @returns The symbol value, NULL on failure. (If you care for a less boolean
361 * status, go thru the necessary API calls yourself.)
362 * @param pszFilename Image filename. No path.
363 * @param pszSymbol Symbol name.
364 * @param fFlags RTLDRLOAD_FLAGS_XXX, including RTLDRLOAD_FLAGS_SO_VER_XXX.
365 */
366RTDECL(void *) RTLdrGetSystemSymbolEx(const char *pszFilename, const char *pszSymbol, uint32_t fFlags);
367
368/**
369 * Loads a dynamic load library (/shared object) image file residing in the
370 * RTPathAppPrivateArch() directory.
371 *
372 * Suffix is not required.
373 *
374 * @returns iprt status code.
375 * @param pszFilename Image filename. No path.
376 * @param phLdrMod Where to store the handle to the loaded module.
377 */
378RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
379
380/**
381 * Gets the native module handle for a module loaded by RTLdrLoad, RTLdrLoadEx,
382 * RTLdrLoadSystem, or RTLdrLoadAppPriv.
383 *
384 * @returns Native handle on success, ~(uintptr_t)0 on failure.
385 * @param hLdrMod The loader module handle.
386 */
387RTDECL(uintptr_t) RTLdrGetNativeHandle(RTLDRMOD hLdrMod);
388
389
390/**
391 * Image architecuture specifier for RTLdrOpenEx.
392 */
393typedef enum RTLDRARCH
394{
395 RTLDRARCH_INVALID = 0,
396 /** Whatever. */
397 RTLDRARCH_WHATEVER,
398 /** The host architecture. */
399 RTLDRARCH_HOST,
400 /** 16-bit x86. */
401 RTLDRARCH_X86_16,
402 /** 32-bit x86. */
403 RTLDRARCH_X86_32,
404 /** AMD64 (64-bit x86 if you like). */
405 RTLDRARCH_AMD64,
406 /** 32-bit ARM. */
407 RTLDRARCH_ARM32,
408 /** 64-bit ARM. */
409 RTLDRARCH_ARM64,
410 /** End of the valid values. */
411 RTLDRARCH_END,
412 /** Make sure the type is a full 32-bit. */
413 RTLDRARCH_32BIT_HACK = 0x7fffffff
414} RTLDRARCH;
415/** Pointer to a RTLDRARCH. */
416typedef RTLDRARCH *PRTLDRARCH;
417
418/**
419 * Translates a RTLDRARCH value to a string.
420 *
421 * @returns Name corresponding to @a enmArch
422 * @param enmArch The value to name.
423 */
424RTDECL(const char *) RTLdrArchName(RTLDRARCH enmArch);
425
426/**
427 * Returns the host architecture.
428 *
429 * @returns Host architecture or RTLDRARCH_WHATEVER if no match.
430 */
431RTDECL(RTLDRARCH) RTLdrGetHostArch(void);
432
433
434/** @name RTLDR_O_XXX - RTLdrOpen flags.
435 * @{ */
436/** Open for debugging or introspection reasons.
437 * This will skip a few of the stricter validations when loading images. */
438#define RTLDR_O_FOR_DEBUG RT_BIT_32(0)
439/** Open for signature validation. */
440#define RTLDR_O_FOR_VALIDATION RT_BIT_32(1)
441/** The arch specification is just a guideline for FAT binaries. */
442#define RTLDR_O_WHATEVER_ARCH RT_BIT_32(2)
443/** Ignore the architecture specification if there is no code. */
444#define RTLDR_O_IGNORE_ARCH_IF_NO_CODE RT_BIT_32(3)
445/** Mask of valid flags. */
446#define RTLDR_O_VALID_MASK UINT32_C(0x0000000f)
447/** @} */
448
449/**
450 * Open a binary image file.
451 *
452 * @returns iprt status code.
453 * @param pszFilename Image filename.
454 * @param fFlags Valid RTLDR_O_XXX combination.
455 * @param enmArch CPU architecture specifier for the image to be loaded.
456 * @param phLdrMod Where to store the handle to the loader module.
457 */
458RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
459
460/**
461 * Open a binary image file, extended version.
462 *
463 * @returns iprt status code.
464 * @param pszFilename Image filename.
465 * @param fFlags Valid RTLDR_O_XXX combination.
466 * @param enmArch CPU architecture specifier for the image to be loaded.
467 * @param phLdrMod Where to store the handle to the loader module.
468 * @param pErrInfo Where to return extended error information. Optional.
469 */
470RTDECL(int) RTLdrOpenEx(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
471
472/**
473 * Open a binary image file allowing VFS chains in the filename.
474 *
475 * @returns iprt status code.
476 * @param pszFilename Image filename, VFS chain specifiers allowed.
477 * @param fFlags Valid RTLDR_O_XXX combination.
478 * @param enmArch CPU architecture specifier for the image to be loaded.
479 * @param phLdrMod Where to store the handle to the loader module.
480 * @param poffError Where to return the offset into @a pszFilename of an VFS
481 * chain element causing trouble. Optional.
482 * @param pErrInfo Where to return extended error information. Optional.
483 */
484RTDECL(int) RTLdrOpenVfsChain(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch,
485 PRTLDRMOD phLdrMod, uint32_t *poffError, PRTERRINFO pErrInfo);
486
487/**
488 * Open part with reader.
489 *
490 * @returns iprt status code.
491 * @param pReader The loader reader instance which will provide the raw
492 * image bits. The reader instance will be consumed on
493 * success. On failure, the caller has to do the cleaning
494 * up.
495 * @param fFlags Valid RTLDR_O_XXX combination.
496 * @param enmArch Architecture specifier.
497 * @param phMod Where to store the handle.
498 * @param pErrInfo Where to return extended error information. Optional.
499 */
500RTDECL(int) RTLdrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod, PRTERRINFO pErrInfo);
501
502/**
503 * Called to read @a cb bytes at @a off into @a pvBuf.
504 *
505 * @returns IPRT status code
506 * @param pvBuf The output buffer.
507 * @param cb The number of bytes to read.
508 * @param off Where to start reading.
509 * @param pvUser The user parameter.
510 */
511typedef DECLCALLBACK(int) FNRTLDRRDRMEMREAD(void *pvBuf, size_t cb, size_t off, void *pvUser);
512/** Pointer to a RTLdrOpenInMemory reader callback. */
513typedef FNRTLDRRDRMEMREAD *PFNRTLDRRDRMEMREAD;
514
515/**
516 * Called to when the module is unloaded (or done loading) to release resources
517 * associated with it (@a pvUser).
518 *
519 * @returns IPRT status code
520 * @param pvUser The user parameter.
521 * @param cbImage The image size.
522 */
523typedef DECLCALLBACK(void) FNRTLDRRDRMEMDTOR(void *pvUser, size_t cbImage);
524/** Pointer to a RTLdrOpenInMemory destructor callback. */
525typedef FNRTLDRRDRMEMDTOR *PFNRTLDRRDRMEMDTOR;
526
527/**
528 * Open a in-memory image or an image with a custom reader callback.
529 *
530 * @returns IPRT status code.
531 * @param pszName The image name.
532 * @param fFlags Valid RTLDR_O_XXX combination.
533 * @param enmArch CPU architecture specifier for the image to be loaded.
534 * @param cbImage The size of the image (fake file).
535 * @param pfnRead The read function. If NULL is passed in, a default
536 * reader function is provided that assumes @a pvUser
537 * points to the raw image bits, at least @a cbImage of
538 * valid memory.
539 * @param pfnDtor The destructor function. If NULL is passed, a default
540 * destructor will be provided that passes @a pvUser to
541 * RTMemFree.
542 * @param pvUser The user argument or, if any of the callbacks are NULL,
543 * a pointer to a memory block.
544 * @param phLdrMod Where to return the module handle.
545 * @param pErrInfo Pointer to an error info buffer, optional.
546 *
547 * @remarks With the exception of invalid @a pfnDtor and/or @a pvUser
548 * parameters, the pfnDtor methods (or the default one if NULL) will
549 * always be invoked. The destruction of pvUser is entirely in the
550 * hands of this method once it's called.
551 */
552RTDECL(int) RTLdrOpenInMemory(const char *pszName, uint32_t fFlags, RTLDRARCH enmArch, size_t cbImage,
553 PFNRTLDRRDRMEMREAD pfnRead, PFNRTLDRRDRMEMDTOR pfnDtor, void *pvUser,
554 PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
555
556/**
557 * Closes a loader module handle.
558 *
559 * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
560 * and RTLdrOpenInMemory() functions.
561 *
562 * @returns iprt status code.
563 * @param hLdrMod The loader module handle.
564 */
565RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
566
567/**
568 * Gets the address of a named exported symbol.
569 *
570 * @returns iprt status code.
571 * @retval VERR_LDR_FORWARDER forwarder, use pfnQueryForwarderInfo. Buffer size
572 * hint in @a ppvValue.
573 * @param hLdrMod The loader module handle.
574 * @param pszSymbol Symbol name.
575 * @param ppvValue Where to store the symbol value. Note that this is restricted to the
576 * pointer size used on the host!
577 */
578RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
579
580/**
581 * Gets the address of a named exported symbol.
582 *
583 * This function differs from the plain one in that it can deal with
584 * both GC and HC address sizes, and that it can calculate the symbol
585 * value relative to any given base address.
586 *
587 * @returns iprt status code.
588 * @retval VERR_LDR_FORWARDER forwarder, use pfnQueryForwarderInfo. Buffer size
589 * hint in @a pValue.
590 * @param hLdrMod The loader module handle.
591 * @param pvBits Optional pointer to the loaded image.
592 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
593 * Not supported for RTLdrLoad() images.
594 * @param BaseAddress Image load address.
595 * Not supported for RTLdrLoad() images.
596 * @param iOrdinal Symbol ordinal number, pass UINT32_MAX if pszSymbol
597 * should be used instead.
598 * @param pszSymbol Symbol name.
599 * @param pValue Where to store the symbol value.
600 */
601RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTLDRADDR BaseAddress,
602 uint32_t iOrdinal, const char *pszSymbol, PRTLDRADDR pValue);
603
604/**
605 * Gets the address of a named exported function.
606 *
607 * Same as RTLdrGetSymbol, but skips the status code and pointer to return
608 * variable stuff.
609 *
610 * @returns Pointer to the function if found, NULL if not.
611 * @param hLdrMod The loader module handle.
612 * @param pszSymbol Function name.
613 */
614RTDECL(PFNRT) RTLdrGetFunction(RTLDRMOD hLdrMod, const char *pszSymbol);
615
616/**
617 * Information about an imported symbol.
618 */
619typedef struct RTLDRIMPORTINFO
620{
621 /** Symbol table entry number, UINT32_MAX if not available. */
622 uint32_t iSelfOrdinal;
623 /** The ordinal of the imported symbol in szModule, UINT32_MAX if not used. */
624 uint32_t iOrdinal;
625 /** The symbol name, NULL if not used. This points to the char immediately
626 * following szModule when returned by RTLdrQueryForwarderInfo. */
627 const char *pszSymbol;
628 /** The name of the module being imported from. */
629 char szModule[1];
630} RTLDRIMPORTINFO;
631/** Pointer to information about an imported symbol. */
632typedef RTLDRIMPORTINFO *PRTLDRIMPORTINFO;
633/** Pointer to const information about an imported symbol. */
634typedef RTLDRIMPORTINFO const *PCRTLDRIMPORTINFO;
635
636/**
637 * Query information about a forwarded symbol.
638 *
639 * @returns IPRT status code.
640 * @param hLdrMod The loader module handle.
641 * @param pvBits Optional pointer to the loaded image.
642 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
643 * Not supported for RTLdrLoad() images.
644 * @param iOrdinal Symbol ordinal number, pass UINT32_MAX if pszSymbol
645 * should be used instead.
646 * @param pszSymbol Symbol name.
647 * @param pInfo Where to return the forwarder info.
648 * @param cbInfo Size of the buffer @a pInfo points to. For a size
649 * hint, see @a pValue when RTLdrGetSymbolEx returns
650 * VERR_LDR_FORWARDER.
651 */
652RTDECL(int) RTLdrQueryForwarderInfo(RTLDRMOD hLdrMod, const void *pvBits, uint32_t iOrdinal, const char *pszSymbol,
653 PRTLDRIMPORTINFO pInfo, size_t cbInfo);
654
655
656/**
657 * Gets the size of the loaded image.
658 *
659 * This is not necessarily available for images that has been loaded using
660 * RTLdrLoad().
661 *
662 * @returns image size (in bytes).
663 * @returns ~(size_t)0 on if not available.
664 * @param hLdrMod Handle to the loader module.
665 */
666RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
667
668/**
669 * Resolve an external symbol during RTLdrGetBits().
670 *
671 * @returns iprt status code.
672 * @param hLdrMod The loader module handle.
673 * @param pszModule Module name.
674 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
675 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
676 * @param pValue Where to store the symbol value (address).
677 * @param pvUser User argument.
678 */
679typedef DECLCALLBACK(int) FNRTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol,
680 PRTLDRADDR pValue, void *pvUser);
681/** Pointer to a FNRTLDRIMPORT() callback function. */
682typedef FNRTLDRIMPORT *PFNRTLDRIMPORT;
683
684/**
685 * Loads the image into a buffer provided by the user and applies fixups
686 * for the given base address.
687 *
688 * @returns iprt status code.
689 * @param hLdrMod The load module handle.
690 * @param pvBits Where to put the bits.
691 * Must be as large as RTLdrSize() suggests.
692 * @param BaseAddress The base address.
693 * @param pfnGetImport Callback function for resolving imports one by one.
694 * @param pvUser User argument for the callback.
695 * @remark Not supported for RTLdrLoad() images.
696 */
697RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
698
699/**
700 * Relocates bits after getting them.
701 * Useful for code which moves around a bit.
702 *
703 * @returns iprt status code.
704 * @param hLdrMod The loader module handle.
705 * @param pvBits Where the image bits are.
706 * Must have been passed to RTLdrGetBits().
707 * @param NewBaseAddress The new base address.
708 * @param OldBaseAddress The old base address.
709 * @param pfnGetImport Callback function for resolving imports one by one.
710 * @param pvUser User argument for the callback.
711 * @remark Not supported for RTLdrLoad() images.
712 */
713RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress,
714 PFNRTLDRIMPORT pfnGetImport, void *pvUser);
715
716/**
717 * Enumeration callback function used by RTLdrEnumSymbols().
718 *
719 * @returns iprt status code. Failure will stop the enumeration.
720 * @param hLdrMod The loader module handle.
721 * @param pszSymbol Symbol name. NULL if ordinal only.
722 * @param uSymbol Symbol ordinal, ~0 if not used.
723 * @param Value Symbol value.
724 * @param pvUser The user argument specified to RTLdrEnumSymbols().
725 */
726typedef DECLCALLBACK(int) FNRTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTLDRADDR Value, void *pvUser);
727/** Pointer to a FNRTLDRENUMSYMS() callback function. */
728typedef FNRTLDRENUMSYMS *PFNRTLDRENUMSYMS;
729
730/**
731 * Enumerates all symbols in a module.
732 *
733 * @returns iprt status code.
734 * @param hLdrMod The loader module handle.
735 * @param fFlags Flags indicating what to return and such.
736 * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
737 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
738 * @param BaseAddress Image load address.
739 * @param pfnCallback Callback function.
740 * @param pvUser User argument for the callback.
741 * @remark Not supported for RTLdrLoad() images.
742 */
743RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
744
745/** @name RTLdrEnumSymbols flags.
746 * @{ */
747/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
748#define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
749/** Ignore forwarders rather than reporting them with RTLDR_ENUM_SYMBOL_FWD_ADDRESS as value. */
750#define RTLDR_ENUM_SYMBOL_FLAGS_NO_FWD RT_BIT(2)
751/** @} */
752
753/** Special symbol for forwarder symbols, since they cannot be resolved with
754 * the current API. */
755#if (HC_ARCH_BITS == 64 || GC_ARCH_BITS == 64)
756# define RTLDR_ENUM_SYMBOL_FWD_ADDRESS UINT64_C(0xff4242fffd4242fd)
757#else
758# define RTLDR_ENUM_SYMBOL_FWD_ADDRESS UINT32_C(0xff4242fd)
759#endif
760
761
762/**
763 * Debug info type (as far the loader can tell).
764 */
765typedef enum RTLDRDBGINFOTYPE
766{
767 /** The invalid 0 value. */
768 RTLDRDBGINFOTYPE_INVALID = 0,
769 /** Unknown debug info format. */
770 RTLDRDBGINFOTYPE_UNKNOWN,
771 /** Stabs. */
772 RTLDRDBGINFOTYPE_STABS,
773 /** Debug With Arbitrary Record Format (DWARF). */
774 RTLDRDBGINFOTYPE_DWARF,
775 /** Debug With Arbitrary Record Format (DWARF), in external file (DWO). */
776 RTLDRDBGINFOTYPE_DWARF_DWO,
777 /** Microsoft Codeview debug info. */
778 RTLDRDBGINFOTYPE_CODEVIEW,
779 /** Microsoft Codeview debug info, in external v2.0+ program database (PDB). */
780 RTLDRDBGINFOTYPE_CODEVIEW_PDB20,
781 /** Microsoft Codeview debug info, in external v7.0+ program database (PDB). */
782 RTLDRDBGINFOTYPE_CODEVIEW_PDB70,
783 /** Microsoft Codeview debug info, in external file (DBG). */
784 RTLDRDBGINFOTYPE_CODEVIEW_DBG,
785 /** Microsoft COFF debug info. */
786 RTLDRDBGINFOTYPE_COFF,
787 /** Watcom debug info. */
788 RTLDRDBGINFOTYPE_WATCOM,
789 /** IBM High Level Language debug info. */
790 RTLDRDBGINFOTYPE_HLL,
791 /** The end of the valid debug info values (exclusive). */
792 RTLDRDBGINFOTYPE_END,
793 /** Blow the type up to 32-bits. */
794 RTLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
795} RTLDRDBGINFOTYPE;
796
797
798/**
799 * Debug info details for the enumeration callback.
800 */
801typedef struct RTLDRDBGINFO
802{
803 /** The kind of debug info. */
804 RTLDRDBGINFOTYPE enmType;
805 /** The debug info ordinal number / id. */
806 uint32_t iDbgInfo;
807 /** The file offset *if* this type has one specific location in the executable
808 * image file. This is -1 if there isn't any specific file location. */
809 RTFOFF offFile;
810 /** The link address of the debug info if it's loadable. NIL_RTLDRADDR if not
811 * loadable*/
812 RTLDRADDR LinkAddress;
813 /** The size of the debug information. -1 is used if this isn't applicable.*/
814 RTLDRADDR cb;
815 /** This is set if the debug information is found in an external file. NULL
816 * if no external file involved.
817 * @note Putting it outside the union to allow lazy callback implementation. */
818 const char *pszExtFile;
819 /** Type (enmType) specific information. */
820 union
821 {
822 /** RTLDRDBGINFOTYPE_DWARF */
823 struct
824 {
825 /** The section name. */
826 const char *pszSection;
827 } Dwarf;
828
829 /** RTLDRDBGINFOTYPE_DWARF_DWO */
830 struct
831 {
832 /** The CRC32 of the external file. */
833 uint32_t uCrc32;
834 } Dwo;
835
836 /** RTLDRDBGINFOTYPE_CODEVIEW, RTLDRDBGINFOTYPE_COFF */
837 struct
838 {
839 /** The PE image size. */
840 uint32_t cbImage;
841 /** The timestamp. */
842 uint32_t uTimestamp;
843 /** The major version from the entry. */
844 uint32_t uMajorVer;
845 /** The minor version from the entry. */
846 uint32_t uMinorVer;
847 } Cv, Coff;
848
849 /** RTLDRDBGINFOTYPE_CODEVIEW_DBG */
850 struct
851 {
852 /** The PE image size. */
853 uint32_t cbImage;
854 /** The timestamp. */
855 uint32_t uTimestamp;
856 } Dbg;
857
858 /** RTLDRDBGINFOTYPE_CODEVIEW_PDB20*/
859 struct
860 {
861 /** The PE image size. */
862 uint32_t cbImage;
863 /** The timestamp. */
864 uint32_t uTimestamp;
865 /** The PDB age. */
866 uint32_t uAge;
867 } Pdb20;
868
869 /** RTLDRDBGINFOTYPE_CODEVIEW_PDB70 */
870 struct
871 {
872 /** The PE image size. */
873 uint32_t cbImage;
874 /** The PDB age. */
875 uint32_t uAge;
876 /** The UUID. */
877 RTUUID Uuid;
878 } Pdb70;
879 } u;
880} RTLDRDBGINFO;
881/** Pointer to debug info details. */
882typedef RTLDRDBGINFO *PRTLDRDBGINFO;
883/** Pointer to read only debug info details. */
884typedef RTLDRDBGINFO const *PCRTLDRDBGINFO;
885
886
887/**
888 * Debug info enumerator callback.
889 *
890 * @returns VINF_SUCCESS to continue the enumeration. Any other status code
891 * will cause RTLdrEnumDbgInfo to immediately return with that status.
892 *
893 * @param hLdrMod The module handle.
894 * @param pDbgInfo Pointer to a read only structure with the details.
895 * @param pvUser The user parameter specified to RTLdrEnumDbgInfo.
896 */
897typedef DECLCALLBACK(int) FNRTLDRENUMDBG(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser);
898/** Pointer to a debug info enumerator callback. */
899typedef FNRTLDRENUMDBG *PFNRTLDRENUMDBG;
900
901/**
902 * Enumerate the debug info contained in the executable image.
903 *
904 * @returns IPRT status code or whatever pfnCallback returns.
905 *
906 * @param hLdrMod The module handle.
907 * @param pvBits Optional pointer to bits returned by
908 * RTLdrGetBits(). This can be used by some module
909 * interpreters to reduce memory consumption.
910 * @param pfnCallback The callback function.
911 * @param pvUser The user argument.
912 */
913RTDECL(int) RTLdrEnumDbgInfo(RTLDRMOD hLdrMod, const void *pvBits, PFNRTLDRENUMDBG pfnCallback, void *pvUser);
914
915
916/**
917 * Loader segment.
918 */
919typedef struct RTLDRSEG
920{
921 /** The segment name. Always set to something. */
922 const char *pszName;
923 /** The length of the segment name. */
924 uint32_t cchName;
925 /** The flat selector to use for the segment (i.e. data/code).
926 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
927 uint16_t SelFlat;
928 /** The 16-bit selector to use for the segment.
929 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
930 uint16_t Sel16bit;
931 /** Segment flags. */
932 uint32_t fFlags;
933 /** The segment protection (RTMEM_PROT_XXX). */
934 uint32_t fProt;
935 /** The size of the segment. */
936 RTLDRADDR cb;
937 /** The required segment alignment.
938 * The to 0 if the segment isn't supposed to be mapped. */
939 RTLDRADDR Alignment;
940 /** The link address.
941 * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped or if
942 * the image doesn't have link addresses. */
943 RTLDRADDR LinkAddress;
944 /** File offset of the segment.
945 * Set to -1 if no file backing (like BSS). */
946 RTFOFF offFile;
947 /** Size of the file bits of the segment.
948 * Set to -1 if no file backing (like BSS). */
949 RTFOFF cbFile;
950 /** The relative virtual address when mapped.
951 * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped. */
952 RTLDRADDR RVA;
953 /** The size of the segment including the alignment gap up to the next segment when mapped.
954 * This is set to NIL_RTLDRADDR if not implemented. */
955 RTLDRADDR cbMapped;
956} RTLDRSEG;
957/** Pointer to a loader segment. */
958typedef RTLDRSEG *PRTLDRSEG;
959/** Pointer to a read only loader segment. */
960typedef RTLDRSEG const *PCRTLDRSEG;
961
962
963/** @name Segment flags
964 * @{ */
965/** The segment is 16-bit. When not set the default of the target architecture is assumed. */
966#define RTLDRSEG_FLAG_16BIT UINT32_C(1)
967/** The segment requires a 16-bit selector alias. (OS/2) */
968#define RTLDRSEG_FLAG_OS2_ALIAS16 UINT32_C(2)
969/** Conforming segment (x86 weirdness). (OS/2) */
970#define RTLDRSEG_FLAG_OS2_CONFORM UINT32_C(4)
971/** IOPL (ring-2) segment. (OS/2) */
972#define RTLDRSEG_FLAG_OS2_IOPL UINT32_C(8)
973/** @} */
974
975/**
976 * Segment enumerator callback.
977 *
978 * @returns VINF_SUCCESS to continue the enumeration. Any other status code
979 * will cause RTLdrEnumSegments to immediately return with that
980 * status.
981 *
982 * @param hLdrMod The module handle.
983 * @param pSeg The segment information.
984 * @param pvUser The user parameter specified to RTLdrEnumSegments.
985 */
986typedef DECLCALLBACK(int) FNRTLDRENUMSEGS(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser);
987/** Pointer to a segment enumerator callback. */
988typedef FNRTLDRENUMSEGS *PFNRTLDRENUMSEGS;
989
990/**
991 * Enumerate the debug info contained in the executable image.
992 *
993 * @returns IPRT status code or whatever pfnCallback returns.
994 *
995 * @param hLdrMod The module handle.
996 * @param pfnCallback The callback function.
997 * @param pvUser The user argument.
998 */
999RTDECL(int) RTLdrEnumSegments(RTLDRMOD hLdrMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser);
1000
1001/**
1002 * Converts a link address to a segment:offset address.
1003 *
1004 * @returns IPRT status code.
1005 *
1006 * @param hLdrMod The module handle.
1007 * @param LinkAddress The link address to convert.
1008 * @param piSeg Where to return the segment index.
1009 * @param poffSeg Where to return the segment offset.
1010 */
1011RTDECL(int) RTLdrLinkAddressToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, uint32_t *piSeg, PRTLDRADDR poffSeg);
1012
1013/**
1014 * Converts a link address to an image relative virtual address (RVA).
1015 *
1016 * @returns IPRT status code.
1017 *
1018 * @param hLdrMod The module handle.
1019 * @param LinkAddress The link address to convert.
1020 * @param pRva Where to return the RVA.
1021 */
1022RTDECL(int) RTLdrLinkAddressToRva(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva);
1023
1024/**
1025 * Converts an image relative virtual address (RVA) to a segment:offset.
1026 *
1027 * @returns IPRT status code.
1028 *
1029 * @param hLdrMod The module handle.
1030 * @param iSeg The segment index.
1031 * @param offSeg The segment offset.
1032 * @param pRva Where to return the RVA.
1033 */
1034RTDECL(int) RTLdrSegOffsetToRva(RTLDRMOD hLdrMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva);
1035
1036/**
1037 * Converts a segment:offset into an image relative virtual address (RVA).
1038 *
1039 * @returns IPRT status code.
1040 *
1041 * @param hLdrMod The module handle.
1042 * @param Rva The link address to convert.
1043 * @param piSeg Where to return the segment index.
1044 * @param poffSeg Where to return the segment offset.
1045 */
1046RTDECL(int) RTLdrRvaToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg);
1047
1048/**
1049 * Gets the image format.
1050 *
1051 * @returns Valid image format on success. RTLDRFMT_INVALID on invalid handle or
1052 * other errors.
1053 * @param hLdrMod The module handle.
1054 */
1055RTDECL(RTLDRFMT) RTLdrGetFormat(RTLDRMOD hLdrMod);
1056
1057/**
1058 * Gets the image type.
1059 *
1060 * @returns Valid image type value on success. RTLDRTYPE_INVALID on
1061 * invalid handle or other errors.
1062 * @param hLdrMod The module handle.
1063 */
1064RTDECL(RTLDRTYPE) RTLdrGetType(RTLDRMOD hLdrMod);
1065
1066/**
1067 * Gets the image endian-ness.
1068 *
1069 * @returns Valid image endian value on success. RTLDRENDIAN_INVALID on invalid
1070 * handle or other errors.
1071 * @param hLdrMod The module handle.
1072 */
1073RTDECL(RTLDRENDIAN) RTLdrGetEndian(RTLDRMOD hLdrMod);
1074
1075/**
1076 * Gets the image endian-ness.
1077 *
1078 * @returns Valid image architecture value on success.
1079 * RTLDRARCH_INVALID on invalid handle or other errors.
1080 * @param hLdrMod The module handle.
1081 */
1082RTDECL(RTLDRARCH) RTLdrGetArch(RTLDRMOD hLdrMod);
1083
1084/**
1085 * Loader properties that can be queried thru RTLdrQueryProp.
1086 */
1087typedef enum RTLDRPROP
1088{
1089 RTLDRPROP_INVALID = 0,
1090 /** The image UUID (Mach-O).
1091 * Returns a RTUUID in the buffer. */
1092 RTLDRPROP_UUID,
1093 /** The image timestamp in seconds, genrally since unix epoc.
1094 * Returns a 32-bit or 64-bit signed integer value in the buffer. */
1095 RTLDRPROP_TIMESTAMP_SECONDS,
1096 /** Checks if the image is signed.
1097 * Returns a bool. */
1098 RTLDRPROP_IS_SIGNED,
1099 /** Retrives the PKCS \#7 SignedData blob that signs the image.
1100 * Returns variable sized buffer containing the ASN.1 BER encoding.
1101 *
1102 * @remarks This generally starts with a PKCS \#7 Content structure, the
1103 * SignedData bit is found a few levels down into this as per RFC. */
1104 RTLDRPROP_PKCS7_SIGNED_DATA,
1105
1106 /** Query whether code signature checks are enabled. */
1107 RTLDRPROP_SIGNATURE_CHECKS_ENFORCED,
1108
1109 /** Number of import or needed modules. */
1110 RTLDRPROP_IMPORT_COUNT,
1111 /** Import module by index (32-bit) stored in the buffer. */
1112 RTLDRPROP_IMPORT_MODULE,
1113 /** The file offset of the main executable header.
1114 * This is mainly for PE, NE and LX headers, but also Mach-O FAT. */
1115 RTLDRPROP_FILE_OFF_HEADER,
1116 /** The internal module name.
1117 * This is the SONAME for ELF, export table name for PE, and zero'th resident
1118 * name table entry for LX.
1119 * Returns zero terminated string. */
1120 RTLDRPROP_INTERNAL_NAME,
1121 /** The raw unwind table if available.
1122 * For PE this means IMAGE_DIRECTORY_ENTRY_EXCEPTION content, for AMD64 this
1123 * is the lookup table (IMAGE_RUNTIME_FUNCTION_ENTRY).
1124 * Not implemented any others yet. */
1125 RTLDRPROP_UNWIND_TABLE,
1126 /** Read unwind info at given RVA and up to buffer size. The RVA is stored
1127 * as uint32_t in the buffer when making the call.
1128 * This is only implemented for PE. */
1129 RTLDRPROP_UNWIND_INFO,
1130
1131 /** End of valid properties. */
1132 RTLDRPROP_END,
1133 /** Blow the type up to 32 bits. */
1134 RTLDRPROP_32BIT_HACK = 0x7fffffff
1135} RTLDRPROP;
1136
1137/**
1138 * Generic method for querying image properties.
1139 *
1140 * @returns IPRT status code.
1141 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
1142 * or that specific property). The caller must handle this result.
1143 * @retval VERR_NOT_FOUND the property was not found in the module. The caller
1144 * must also normally deal with this.
1145 * @retval VERR_INVALID_FUNCTION if the function value is wrong.
1146 * @retval VERR_INVALID_PARAMETER if the buffer size is wrong.
1147 * @retval VERR_BUFFER_OVERFLOW if the function doesn't have a fixed size
1148 * buffer and the buffer isn't big enough. Use RTLdrQueryPropEx.
1149 * @retval VERR_INVALID_HANDLE if the handle is invalid.
1150 *
1151 * @param hLdrMod The module handle.
1152 * @param enmProp The property to query.
1153 * @param pvBuf Pointer to the input / output buffer. In most cases
1154 * it's only used for returning data.
1155 * @param cbBuf The size of the buffer.
1156 */
1157RTDECL(int) RTLdrQueryProp(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf);
1158
1159/**
1160 * Generic method for querying image properties, extended version.
1161 *
1162 * @returns IPRT status code.
1163 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
1164 * or that specific property). The caller must handle this result.
1165 * @retval VERR_NOT_FOUND the property was not found in the module. The caller
1166 * must also normally deal with this.
1167 * @retval VERR_INVALID_FUNCTION if the function value is wrong.
1168 * @retval VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
1169 * size in @a *pcbRet.
1170 * @retval VERR_BUFFER_OVERFLOW if the function doesn't have a fixed size
1171 * buffer and the buffer isn't big enough. Correct size in @a *pcbRet.
1172 * @retval VERR_INVALID_HANDLE if the handle is invalid.
1173 *
1174 * @param hLdrMod The module handle.
1175 * @param enmProp The property to query.
1176 * @param pvBits Optional pointer to bits returned by
1177 * RTLdrGetBits(). This can be utilized by some module
1178 * interpreters to reduce memory consumption and file
1179 * access.
1180 * @param pvBuf Pointer to the input / output buffer. In most cases
1181 * it's only used for returning data.
1182 * @param cbBuf The size of the buffer.
1183 * @param pcbRet Where to return the amount of data returned. On
1184 * buffer size errors, this is set to the correct size.
1185 * Optional.
1186 */
1187RTDECL(int) RTLdrQueryPropEx(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBits, void *pvBuf, size_t cbBuf, size_t *pcbRet);
1188
1189
1190/**
1191 * Signature type, see FNRTLDRVALIDATESIGNEDDATA.
1192 */
1193typedef enum RTLDRSIGNATURETYPE
1194{
1195 /** Invalid value. */
1196 RTLDRSIGNATURETYPE_INVALID = 0,
1197 /** A RTPKCS7CONTENTINFO structure w/ RTPKCS7SIGNEDDATA inside.
1198 * It's parsed, so the whole binary ASN.1 representation can be found by
1199 * using RTASN1CORE_GET_RAW_ASN1_PTR() and RTASN1CORE_GET_RAW_ASN1_SIZE(). */
1200 RTLDRSIGNATURETYPE_PKCS7_SIGNED_DATA,
1201 /** End of valid values. */
1202 RTLDRSIGNATURETYPE_END,
1203 /** Make sure the size is 32-bit. */
1204 RTLDRSIGNATURETYPE_32BIT_HACK = 0x7fffffff
1205} RTLDRSIGNATURETYPE;
1206
1207/**
1208 * Callback used by RTLdrVerifySignature to verify the signature and associated
1209 * certificates.
1210 *
1211 * @returns IPRT status code.
1212 * @param hLdrMod The module handle.
1213 * @param enmSignature The signature format.
1214 * @param pvSignature The signature data. Format given by @a enmSignature.
1215 * @param cbSignature The size of the buffer @a pvSignature points to.
1216 * @param pvExternalData Pointer to the signed data, if external. NULL if the
1217 * data is internal to the signature structure.
1218 * @param cbExternalData Size of the signed data, if external. 0 if
1219 * internal to the signature structure.
1220 * @param pErrInfo Pointer to an error info buffer, optional.
1221 * @param pvUser User argument.
1222 *
1223 */
1224typedef DECLCALLBACK(int) FNRTLDRVALIDATESIGNEDDATA(RTLDRMOD hLdrMod, RTLDRSIGNATURETYPE enmSignature,
1225 void const *pvSignature, size_t cbSignature,
1226 void const *pvExternalData, size_t cbExternalData,
1227 PRTERRINFO pErrInfo, void *pvUser);
1228/** Pointer to a signature verification callback. */
1229typedef FNRTLDRVALIDATESIGNEDDATA *PFNRTLDRVALIDATESIGNEDDATA;
1230
1231/**
1232 * Verify the image signature.
1233 *
1234 * This may permform additional integrity checks on the image structures that
1235 * was not done when opening the image.
1236 *
1237 * @returns IPRT status code.
1238 * @retval VERR_LDRVI_NOT_SIGNED if not signed.
1239 *
1240 * @param hLdrMod The module handle.
1241 * @param pfnCallback Callback that does the signature and certificate
1242 * verficiation.
1243 * @param pvUser User argument for the callback.
1244 * @param pErrInfo Pointer to an error info buffer. Optional.
1245 */
1246RTDECL(int) RTLdrVerifySignature(RTLDRMOD hLdrMod, PFNRTLDRVALIDATESIGNEDDATA pfnCallback, void *pvUser, PRTERRINFO pErrInfo);
1247
1248/**
1249 * Calculate the image hash according the image signing rules.
1250 *
1251 * @returns IPRT status code.
1252 * @param hLdrMod The module handle.
1253 * @param enmDigest Which kind of digest.
1254 * @param pszDigest Where to store the image digest.
1255 * @param cbDigest Size of the buffer @a pszDigest points at.
1256 */
1257RTDECL(int) RTLdrHashImage(RTLDRMOD hLdrMod, RTDIGESTTYPE enmDigest, char *pszDigest, size_t cbDigest);
1258
1259/**
1260 * Try use unwind information to unwind one frame.
1261 *
1262 * @returns IPRT status code. Last informational status from stack reader callback.
1263 * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
1264 * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
1265 * for the location given by iSeg:off.
1266 *
1267 * @param hLdrMod The module handle.
1268 * @param pvBits Optional pointer to bits returned by
1269 * RTLdrGetBits(). This can be utilized by some module
1270 * interpreters to reduce memory consumption and file
1271 * access.
1272 * @param iSeg The segment number of the program counter. UINT32_MAX if RVA.
1273 * @param off The offset into @a iSeg. Together with @a iSeg
1274 * this corresponds to the RTDBGUNWINDSTATE::uPc
1275 * value pointed to by @a pState.
1276 * @param pState The unwind state to work.
1277 *
1278 * @sa RTDbgModUnwindFrame
1279 */
1280RTDECL(int) RTLdrUnwindFrame(RTLDRMOD hLdrMod, void const *pvBits, uint32_t iSeg, RTLDRADDR off, PRTDBGUNWINDSTATE pState);
1281
1282RT_C_DECLS_END
1283
1284/** @} */
1285
1286#endif /* !IPRT_INCLUDED_ldr_h */
1287
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette