mirror of
https://github.com/acidanthera/audk.git
synced 2025-09-26 11:08:42 +02:00
ImageTool: Always store the full image segment data, including padding
This commit is contained in:
parent
108c0769ad
commit
4fccfa0359
@ -717,9 +717,14 @@ CreateIntermediate (
|
||||
|
||||
memcpy (Segments[SIndex].Name, Name, strlen (Name));
|
||||
|
||||
Segments[SIndex].DataSize = (uint32_t)Shdr->sh_size;
|
||||
Segments[SIndex].ImageAddress = Shdr->sh_addr - BaseAddress;
|
||||
Segments[SIndex].DataSize = (uint32_t)Shdr->sh_size;
|
||||
Segments[SIndex].ImageSize = ALIGN_VALUE (Segments[SIndex].DataSize, Context->Alignment);
|
||||
Segments[SIndex].Read = true;
|
||||
Segments[SIndex].Write = (Shdr->sh_flags & SHF_WRITE) != 0;
|
||||
Segments[SIndex].Execute = (Shdr->sh_flags & SHF_EXECINSTR) != 0;
|
||||
|
||||
Segments[SIndex].Data = calloc (1, Segments[SIndex].DataSize);
|
||||
Segments[SIndex].Data = calloc (1, Segments[SIndex].ImageSize);
|
||||
if (Segments[SIndex].Data == NULL) {
|
||||
fprintf (stderr, "ImageTool: Could not allocate memory for Segment #%d Data\n", Index);
|
||||
return RETURN_OUT_OF_RESOURCES;
|
||||
@ -729,11 +734,6 @@ CreateIntermediate (
|
||||
memcpy (Segments[SIndex].Data, (const char *)Ehdr + Shdr->sh_offset, (size_t)Shdr->sh_size);
|
||||
}
|
||||
|
||||
Segments[SIndex].ImageAddress = Shdr->sh_addr - BaseAddress;
|
||||
Segments[SIndex].ImageSize = ALIGN_VALUE (Segments[SIndex].DataSize, Context->Alignment);
|
||||
Segments[SIndex].Read = true;
|
||||
Segments[SIndex].Write = (Shdr->sh_flags & SHF_WRITE) != 0;
|
||||
Segments[SIndex].Execute = (Shdr->sh_flags & SHF_EXECINSTR) != 0;
|
||||
++SIndex;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ static
|
||||
bool
|
||||
CheckToolImageSegment (
|
||||
const image_tool_segment_info_t *SegmentInfo,
|
||||
image_tool_segment_t *Segment,
|
||||
const image_tool_segment_t *Segment,
|
||||
uint32_t *PreviousEndAddress
|
||||
)
|
||||
{
|
||||
@ -19,12 +19,7 @@ CheckToolImageSegment (
|
||||
assert (Segment != NULL);
|
||||
assert (PreviousEndAddress != NULL);
|
||||
|
||||
Overflow = BaseOverflowAlignUpU32 (
|
||||
Segment->ImageSize,
|
||||
SegmentInfo->SegmentAlignment,
|
||||
&Segment->ImageSize
|
||||
);
|
||||
if (Overflow) {
|
||||
if (!IS_ALIGNED (Segment->ImageSize, SegmentInfo->SegmentAlignment)) {
|
||||
raise ();
|
||||
return false;
|
||||
}
|
||||
@ -33,11 +28,10 @@ CheckToolImageSegment (
|
||||
raise ();
|
||||
return false;
|
||||
}
|
||||
//
|
||||
// Shrink segment.
|
||||
//
|
||||
|
||||
if (Segment->ImageSize < Segment->DataSize) {
|
||||
Segment->DataSize = Segment->ImageSize;
|
||||
raise ();
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: Expand prior segment
|
||||
@ -82,6 +76,11 @@ CheckToolImageSegmentInfo (
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IS_ALIGNED (SegmentInfo->Segments[0].ImageAddress, SegmentInfo->SegmentAlignment)) {
|
||||
raise ();
|
||||
return false;
|
||||
}
|
||||
|
||||
*ImageSize = (uint32_t)SegmentInfo->Segments[0].ImageAddress;
|
||||
for (Index = 0; Index < SegmentInfo->NumSegments; ++Index) {
|
||||
Result = CheckToolImageSegment (
|
||||
@ -182,7 +181,7 @@ CheckToolImageRelocInfo (
|
||||
static
|
||||
bool
|
||||
CheckToolImageDebugInfo (
|
||||
image_tool_debug_info_t *DebugInfo
|
||||
const image_tool_debug_info_t *DebugInfo
|
||||
)
|
||||
{
|
||||
assert (DebugInfo != NULL);
|
||||
@ -200,7 +199,7 @@ CheckToolImageDebugInfo (
|
||||
|
||||
bool
|
||||
CheckToolImage (
|
||||
image_tool_image_info_t *Image
|
||||
const image_tool_image_info_t *Image
|
||||
)
|
||||
{
|
||||
bool Result;
|
||||
@ -237,7 +236,6 @@ ImageConvertToXip (
|
||||
image_tool_segment_info_t *SegmentInfo;
|
||||
uint64_t Index;
|
||||
image_tool_segment_t *Segment;
|
||||
void *Data;
|
||||
|
||||
assert (Image != NULL);
|
||||
|
||||
@ -247,19 +245,6 @@ ImageConvertToXip (
|
||||
Segment = &SegmentInfo->Segments[Index];
|
||||
|
||||
assert (Segment->DataSize <= Segment->ImageSize);
|
||||
|
||||
Data = realloc (Segment->Data, Segment->ImageSize);
|
||||
if (Data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memset (
|
||||
(char *)Data + Segment->DataSize,
|
||||
0,
|
||||
Segment->ImageSize - Segment->DataSize
|
||||
);
|
||||
|
||||
Segment->Data = Data;
|
||||
Segment->DataSize = Segment->ImageSize;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ ToolContextConstructPe (
|
||||
|
||||
bool
|
||||
CheckToolImage (
|
||||
image_tool_image_info_t *Image
|
||||
const image_tool_image_info_t *Image
|
||||
);
|
||||
|
||||
void *
|
||||
|
@ -182,7 +182,6 @@ ScanPeGetSegmentInfo (
|
||||
image_tool_segment_t *ImageSegment;
|
||||
const char *ImageBuffer;
|
||||
uint32_t Index;
|
||||
UINT32 Size;
|
||||
|
||||
assert (SegmentInfo != NULL);
|
||||
assert (HiiInfo != NULL);
|
||||
@ -221,9 +220,14 @@ ScanPeGetSegmentInfo (
|
||||
|
||||
memmove (ImageSegment->Name, Section->Name, sizeof (Section->Name));
|
||||
|
||||
Size = ALIGN_VALUE (Section->VirtualSize, SegmentInfo->SegmentAlignment);
|
||||
ImageSegment->ImageAddress = Section->VirtualAddress;
|
||||
ImageSegment->DataSize = MIN (Section->SizeOfRawData, Section->VirtualSize);
|
||||
ImageSegment->ImageSize = ALIGN_VALUE (Section->VirtualSize, SegmentInfo->SegmentAlignment);
|
||||
ImageSegment->Read = (Section->Characteristics & EFI_IMAGE_SCN_MEM_READ) != 0;
|
||||
ImageSegment->Write = (Section->Characteristics & EFI_IMAGE_SCN_MEM_WRITE) != 0;
|
||||
ImageSegment->Execute = (Section->Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) != 0;
|
||||
|
||||
ImageSegment->Data = calloc (1, Size);
|
||||
ImageSegment->Data = malloc (ImageSegment->ImageSize);
|
||||
if (ImageSegment->Data == NULL) {
|
||||
fprintf (stderr, "ImageTool: Could not allocate memory for Segment Data\n");
|
||||
free (ImageSegment->Name);
|
||||
@ -233,23 +237,16 @@ ScanPeGetSegmentInfo (
|
||||
memmove (
|
||||
ImageSegment->Data,
|
||||
ImageBuffer + Section->VirtualAddress,
|
||||
Section->VirtualSize
|
||||
ImageSegment->ImageSize
|
||||
);
|
||||
|
||||
ImageSegment->DataSize = Size;
|
||||
ImageSegment->ImageAddress = Section->VirtualAddress;
|
||||
ImageSegment->ImageSize = Size;
|
||||
|
||||
ImageSegment->Read = (Section->Characteristics & EFI_IMAGE_SCN_MEM_READ) != 0;
|
||||
ImageSegment->Write = (Section->Characteristics & EFI_IMAGE_SCN_MEM_WRITE) != 0;
|
||||
ImageSegment->Execute = (Section->Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) != 0;
|
||||
|
||||
++SegmentInfo->NumSegments;
|
||||
++ImageSegment;
|
||||
} else if (memcmp (Section->Name, PE_COFF_SECT_NAME_RESRC, sizeof (Section->Name)) == 0) {
|
||||
Size = ALIGN_VALUE (Section->VirtualSize, SegmentInfo->SegmentAlignment);
|
||||
// FIXME: Store only the HII data and construct the RESRC dir in PeEmit.c
|
||||
HiiInfo->DataSize = MIN (Section->SizeOfRawData, Section->VirtualSize);
|
||||
|
||||
HiiInfo->Data = calloc (1, Size);
|
||||
HiiInfo->Data = malloc (HiiInfo->DataSize);
|
||||
if (HiiInfo->Data == NULL) {
|
||||
fprintf (stderr, "ImageTool: Could not allocate memory for Hii Data\n");
|
||||
return false;
|
||||
@ -258,10 +255,8 @@ ScanPeGetSegmentInfo (
|
||||
memmove (
|
||||
HiiInfo->Data,
|
||||
ImageBuffer + Section->VirtualAddress,
|
||||
Section->VirtualSize
|
||||
HiiInfo->DataSize
|
||||
);
|
||||
|
||||
HiiInfo->DataSize = Size;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user