}\r
}\r
\r
-void\r
-ZeroXdataSection (\r
- IN CHAR8 *ImageName,\r
- IN OUT UINT8 *FileBuffer,\r
- IN EFI_IMAGE_SECTION_HEADER *SectionHeader,\r
- IN UINT32 SectionTotalNumber\r
- )\r
-{\r
- FILE *fpMapFile;\r
- CHAR8 MapFileName[_MAX_PATH];\r
- CHAR8 Line [MAX_LINE_LEN];\r
- CHAR8 KeyWord [MAX_LINE_LEN];\r
- CHAR8 SectionName [MAX_LINE_LEN];\r
- UINT32 FunctionType = 0;\r
- unsigned SectionOffset = 0;\r
- unsigned SectionLength = 0;\r
- unsigned SectionNumber = 0;\r
- CHAR8 *PdbPointer;\r
- INT32 Index;\r
- UINT32 Index2;\r
-\r
- for (Index2 = 0; Index2 < SectionTotalNumber; Index2++) {\r
- if (stricmp ((char *)SectionHeader[Index2].Name, ".zdata") == 0) {\r
- //\r
- // try to zero the customized .zdata section, which is mapped to .xdata\r
- //\r
- memset (FileBuffer + SectionHeader[Index2].PointerToRawData, 0, SectionHeader[Index2].SizeOfRawData);\r
- DebugMsg (NULL, 0, 9, NULL, "Zero the .xdata section for PE image at Offset 0x%x and Length 0x%x", (unsigned) SectionHeader[Index2].PointerToRawData, (unsigned) SectionHeader[Index2].SizeOfRawData);\r
- return;\r
- }\r
- }\r
- //\r
- // Try to get PDB file name\r
- //\r
- PdbPointer = (CHAR8 *) PeCoffLoaderGetPdbPointer (FileBuffer);\r
- if (PdbPointer != NULL) {\r
- strcpy (MapFileName, PdbPointer);\r
- } else {\r
- strcpy (MapFileName, ImageName);\r
- }\r
-\r
- //\r
- // Construct map file name\r
- //\r
- Index = strlen (MapFileName) - 1;\r
- while (Index >= 0 && MapFileName[Index] != '.') {\r
- Index --;\r
- }\r
- if (Index < 0) {\r
- //\r
- // don't know how to costruct map file\r
- //\r
- return;\r
- }\r
-\r
- //\r
- // fill map file postfix\r
- //\r
- MapFileName[Index + 1] = 'm';\r
- MapFileName[Index + 2] = 'a';\r
- MapFileName[Index + 3] = 'p';\r
- MapFileName[Index + 4] = '\0';\r
-\r
- //\r
- // try opening Map File\r
- //\r
- fpMapFile = fopen (MapFileName, "r");\r
- if (fpMapFile == NULL) {\r
- //\r
- // Can't open Map file. Maybe it doesn't exist.\r
- //\r
- return;\r
- }\r
-\r
- //\r
- // Output Functions information into Fv Map file\r
- //\r
- while (fgets (Line, MAX_LINE_LEN, fpMapFile) != NULL) {\r
- //\r
- // Skip blank line\r
- //\r
- if (Line[0] == 0x0a) {\r
- if (FunctionType != 0) {\r
- //\r
- // read all section table data\r
- //\r
- FunctionType = 0;\r
- break;\r
- }\r
- FunctionType = 0;\r
- continue;\r
- }\r
-\r
- //\r
- // By Start keyword\r
- //\r
- if (FunctionType == 0) {\r
- sscanf (Line, "%s", KeyWord);\r
- if (stricmp (KeyWord, "Start") == 0) {\r
- //\r
- // function list\r
- //\r
- FunctionType = 1;\r
- }\r
- continue;\r
- }\r
- //\r
- // Printf Function Information\r
- //\r
- if (FunctionType == 1) {\r
- sscanf (Line, "%x:%x %xH %s", &SectionNumber, &SectionOffset, &SectionLength, SectionName);\r
- if (stricmp (SectionName, ".xdata") == 0) {\r
- FunctionType = 2;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if (FunctionType != 2) {\r
- //\r
- // no .xdata section is found\r
- //\r
- fclose (fpMapFile);\r
- return;\r
- }\r
-\r
- //\r
- // Zero .xdata Section data\r
- //\r
- memset (FileBuffer + SectionHeader[SectionNumber-1].PointerToRawData + SectionOffset, 0, SectionLength);\r
- DebugMsg (NULL, 0, 9, NULL, "Zero the .xdata section for PE image at Offset 0x%x and Length 0x%x", (unsigned) SectionHeader[SectionNumber-1].PointerToRawData + SectionOffset, SectionLength);\r
- fclose (fpMapFile);\r
- return;\r
-}\r
-\r
int\r
main (\r
int argc,\r
for (Index1 = 0; Index1 < Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size / sizeof (RUNTIME_FUNCTION); Index1++, RuntimeFunction++) {\r
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) &(PeHdr->Pe32.OptionalHeader) + PeHdr->Pe32.FileHeader.SizeOfOptionalHeader);\r
for (Index2 = 0; Index2 < PeHdr->Pe32.FileHeader.NumberOfSections; Index2++, SectionHeader++) {\r
- if (RuntimeFunction->UnwindInfoAddress > SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) {\r
+ if (RuntimeFunction->UnwindInfoAddress >= SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) {\r
UnwindInfo = (UNWIND_INFO *)(FileBuffer + SectionHeader->PointerToRawData + (RuntimeFunction->UnwindInfoAddress - SectionHeader->VirtualAddress));\r
if (UnwindInfo->Version == 1) {\r
memset (UnwindInfo + 1, 0, UnwindInfo->CountOfUnwindCodes * sizeof (UINT16));\r
memset (UnwindInfo, 0, sizeof (UNWIND_INFO));\r
}\r
+ break;\r
}\r
}\r
memset (RuntimeFunction, 0, sizeof (RUNTIME_FUNCTION));\r
//\r
if (!KeepExceptionTableFlag) {\r
SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) &(PeHdr->Pe32.OptionalHeader) + PeHdr->Pe32.FileHeader.SizeOfOptionalHeader);\r
- ZeroXdataSection(mInImageName, FileBuffer, SectionHeader, PeHdr->Pe32.FileHeader.NumberOfSections);\r
+ for (Index = 0; Index < PeHdr->Pe32.FileHeader.NumberOfSections; Index++) {\r
+ if (stricmp ((char *)SectionHeader[Index].Name, ".xdata") == 0) {\r
+ //\r
+ // zero .xdata section\r
+ //\r
+ memset (FileBuffer + SectionHeader[Index].PointerToRawData, 0, SectionHeader[Index].SizeOfRawData);\r
+ DebugMsg (NULL, 0, 9, NULL, "Zero the .xdata section for PE image at Offset 0x%x and Length 0x%x", (unsigned) SectionHeader[Index].PointerToRawData, (unsigned) SectionHeader[Index].SizeOfRawData);\r
+ break;\r
+ }\r
+ }\r
}\r
\r
//\r