Platform SDK: Debugging and Error Handling

ReBaseImage

The ReBaseImage function is used to change the load address for the specified image, which reduces the required load time for a DLL.

Alternatively, you can use the Rebase tool.

BOOL ReBaseImage(
  PSTR CurrentImageName,  
  PSTR SymbolPath,      
  BOOL fReBase,          
  BOOL fRebaseSysfileOk,  
  BOOL fGoingDown,       
  ULONG CheckImageSize,  
  ULONG *OldImageSize,  
  ULONG_PTR *OldImageBase,  
  ULONG *NewImageSize,  
  ULONG_PTR *NewImageBase,  
  ULONG TimeStamp        
);

Parameters

CurrentImageName
[in] Pointer to a null-terminated string that specifies file name of the file to be rebased.
SymbolPath
[in] Pointer to a null-terminated string that specifies the path used to find the corresponding symbol file.
fReBase
[in] Specifies whether the image is to be rebased. If this value is TRUE, the image is rebased. Otherwise, the image is not rebased.
fRebaseSysfileOk
[in] Specifies whether a system image is to be rebased. If this value is TRUE, the system image is rebased. Otherwise, the system image is not rebased.
fGoingDown
[in] Specifies whether the image should be rebased below the given base. If this value is TRUE, the image can be rebased below the given base; otherwise, it cannot.
CheckImageSize
[in] Specifies the maximum size that the image can grow to, or zero if there is no limit.
OldImageSize
[out] Pointer to a variable that receives the original image size.
OldImageBase
[out] Pointer to a variable that receives the original image base.
NewImageSize
[out] Pointer to a variable that receives the new image size after the rebase operation.
NewImageBase
[in/out] Pointer to a variable that receives the new image base after the rebase operation.
TimeStamp
[in] Specifies the new time stamp for the image. The value must be represented in the number of seconds elapsed since midnight (00:00:00), January 1, 1970, Universal Coordinated Time, according to the system clock.

Return Values

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.

Remarks

The ReBaseImage function changes the desired load address for the specified image. This operation involves reading the entire image and updating all fixups, debugging information, checksum, and time stamp values. You can rebase an image to reduce the required load time for its DLLs. If an application can rely on a DLL being loaded at the desired load address, then the system loader does not have to relocate the image. The image is simply loaded into the application's virtual address space and the DllMain function is called, if one is present.

A well-behaved application has its DLLs rebased so they each fall within a unique range of the virtual address space. The system DLLs are currently based in memory from 0x70000000 to 0x78000000 (0x68000000 to 0x78000000 on MIPS). Therefore, you should base your DLLs from 0x60000000 to 0x68000000. One possible scheme is to choose a base address based on the first letter of the DLL name, as shown in the following table.

First Letter Base Address
A - C 0x60000000
D - F 0x61000000
G - I 0x62000000
J - L 0x63000000
M - O 0x64000000
P - R 0x65000000
S - U 0x66000000
V - X 0x67000000
Y - Z 0x68000000

By using these suggestions with the ReBaseImage function, each DLL in an application can be assigned a unique base address. This process can be part of the build process or part of the final release procedure for the application.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in Imagehlp.h.
  Library: Use Imagehlp.lib.

See Also

Image Help Library Overview, ImageHlp Functions, DllMain