MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / RebaseImage

Function RebaseImage

BaseTools/Source/C/VolInfo/VolInfo.c:1474–1595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1472}
1473
1474EFI_STATUS
1475RebaseImage (
1476 IN CHAR8 *FileName,
1477 IN OUT UINT8 *FileBuffer,
1478 IN UINT64 NewPe32BaseAddress
1479 )
1480/*++
1481
1482Routine Description:
1483
1484 Set new base address into PeImage, and fix up PeImage based on new address.
1485
1486Arguments:
1487
1488 FileName - Name of file
1489 FileBuffer - Pointer to PeImage.
1490 NewPe32BaseAddress - New Base Address for PE image.
1491
1492Returns:
1493
1494 EFI_INVALID_PARAMETER - BaseAddress is not valid.
1495 EFI_SUCCESS - Update PeImage is correctly.
1496
1497--*/
1498{
1499 EFI_STATUS Status;
1500 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
1501 UINTN Index;
1502 EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
1503 UINT8 *MemoryImagePointer;
1504 EFI_IMAGE_SECTION_HEADER *SectionHeader;
1505
1506 //
1507 // Initialize context
1508 //
1509 memset (&ImageContext, 0, sizeof (ImageContext));
1510 ImageContext.Handle = (VOID *) FileBuffer;
1511 ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) RebaseImageRead;
1512 Status = PeCoffLoaderGetImageInfo (&ImageContext);
1513 if (EFI_ERROR (Status)) {
1514 Error (NULL, 0, 3000, "Invalid", "The input PeImage %s is not valid", FileName);
1515 return Status;
1516 }
1517
1518 if (ImageContext.RelocationsStripped) {
1519 Error (NULL, 0, 3000, "Invalid", "The input PeImage %s has no relocation to be fixed up", FileName);
1520 return Status;
1521 }
1522
1523 //
1524 // Get PeHeader pointer
1525 //
1526 ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(FileBuffer + ImageContext.PeCoffHeaderOffset);
1527
1528 //
1529 // Load and Relocate Image Data
1530 //
1531 MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);

Callers 2

GenFw.cFile · 0.85
ParseSectionFunction · 0.85

Calls 9

memsetFunction · 0.50
PeCoffLoaderGetImageInfoFunction · 0.50
ErrorFunction · 0.50
mallocFunction · 0.50
PeCoffLoaderLoadImageFunction · 0.50
freeFunction · 0.50
CopyMemFunction · 0.50

Tested by

no test coverage detected