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(
  IN LPSTR CurrentImageName,  
  IN LPSTR SymbolPath,      
  IN BOOL fReBase,          
  IN BOOL fRebaseSysfileOk,  
  IN BOOL fGoingDown,       
  IN DWORD CheckImageSize,  
  OUT LPDWORD OldImageSize,  
  OUT LPDWORD OldImageBase,  
  OUT LPDWORD NewImageSize,  
  IN OUT LPDWORD NewImageBase,  
  IN DWORD TimeStamp        
);
 

Parameters

CurrentImageName
Pointer to a null-terminated string that specifies filename of the file to be rebased.
SymbolPath
Pointer to a null-terminated string that specifies the path used to find the corresponding symbol file.
fReBase
Specifies whether the image is to be rebased. If this value is TRUE, the image is rebased. Otherwise, the image is not rebased.
fRebaseSysfileOk
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
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
Specifies the maximum size that the image can grow to, or zero if there is no limit.
OldImageSize
Pointer to a variable that receives the original image size.
OldImageBase
Pointer to a variable that receives the original image base.
NewImageSize
Pointer to a variable that receives the new image size after the rebase operation.
NewImageBase
Pointer to a variable that receives the new image base after the rebase operation.
TimeStamp
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, debug 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.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Windows CE: Unsupported.
  Header: Declared in imagehlp.h.
  Import Library: Use imagehlp.lib.

See Also

PE Image Helper (ImageHlp) Overview, ImageHlp Image Modification Functions, DllMain