From: mdkinney Date: Wed, 4 Oct 2006 23:02:50 +0000 (+0000) Subject: Update FwImage to zero .xdata information if the image type is X64 and all debug... X-Git-Tag: edk2-stable201903~24215 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=307fd19702192700da7713ee536af3c42bf465f3 Update FwImage to zero .xdata information if the image type is X64 and all debug information has been stripped. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1659 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Source/TianoTools/FwImage/fwimage.c b/Tools/Source/TianoTools/FwImage/fwimage.c index 0097a94550..5dd1634b99 100644 --- a/Tools/Source/TianoTools/FwImage/fwimage.c +++ b/Tools/Source/TianoTools/FwImage/fwimage.c @@ -164,12 +164,16 @@ Returns: EFI_IMAGE_DOS_HEADER BackupDosHdr; ULONG Index; ULONG Index1; + ULONG Index2; + ULONG Index3; BOOLEAN TimeStampPresent; UINTN AllignedRelocSize; UINTN Delta; EFI_IMAGE_SECTION_HEADER *SectionHeader; UINT8 *FileBuffer; UINTN FileLength; + RUNTIME_FUNCTION *RuntimeFunction; + UNWIND_INFO *UnwindInfo; SetUtilityName (UTILITY_NAME); // @@ -373,26 +377,6 @@ Returns: Optional32->SizeOfHeapReserve = 0; Optional32->SizeOfHeapCommit = 0; - // - // Zero the .pdata section if the machine type is X64 and the Debug Directoty entry is empty - // - if (PeHdr->FileHeader.Machine == 0x8664) { // X64 - if (Optional32->NumberOfRvaAndSizes >= 4) { - if (Optional32->NumberOfRvaAndSizes < 7 || (Optional32->NumberOfRvaAndSizes >= 7 && Optional32->DataDirectory[6].Size == 0)) { - SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader); - for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) { - if (SectionHeader->VirtualAddress == Optional32->DataDirectory[3].VirtualAddress) { - for (Index1 = 0; Index1 < Optional32->DataDirectory[3].Size; Index1++) { - FileBuffer[SectionHeader->PointerToRawData + Index1] = 0; - } - } - } - Optional32->DataDirectory[3].Size = 0; - Optional32->DataDirectory[3].VirtualAddress = 0; - } - } - } - // // Strip zero padding at the end of the .reloc section // @@ -454,8 +438,19 @@ Returns: SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader); for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) { if (SectionHeader->VirtualAddress == Optional64->DataDirectory[3].VirtualAddress) { - for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size; Index1++) { - FileBuffer[SectionHeader->PointerToRawData + Index1] = 0; + RuntimeFunction = (RUNTIME_FUNCTION *)(FileBuffer + SectionHeader->PointerToRawData); + for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size / sizeof (RUNTIME_FUNCTION); Index1++, RuntimeFunction++) { + SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader); + for (Index2 = 0; Index2 < PeHdr->FileHeader.NumberOfSections; Index2++, SectionHeader++) { + if (RuntimeFunction->UnwindInfoAddress > SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) { + UnwindInfo = (UNWIND_INFO *)(FileBuffer + SectionHeader->PointerToRawData + (RuntimeFunction->UnwindInfoAddress - SectionHeader->VirtualAddress)); + if (UnwindInfo->Version == 1) { + memset (UnwindInfo + 1, 0, UnwindInfo->CountOfUnwindCodes * sizeof (UINT16)); + memset (UnwindInfo, 0, sizeof (UNWIND_INFO)); + } + } + } + memset (RuntimeFunction, 0, sizeof (RUNTIME_FUNCTION)); } } }