update GenFw to zero time and debug data when -z option input
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 8 Apr 2009 09:08:54 +0000 (09:08 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 8 Apr 2009 09:08:54 +0000 (09:08 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1546 7335b38e-4728-0410-8992-fb3ffe349368

Source/C/GenFw/GenFw.c

index bfdc409..36015d9 100644 (file)
@@ -244,7 +244,7 @@ Returns:
   fprintf (stdout, "  -s timedate, --stamp timedate\n\\r
                         timedate format is \"yyyy-mm-dd 00:00:00\". if timedata \n\\r
                         is set to NOW, current system time is used. The support\n\\r
-                        date scope is 1970-1-1 0:0:0 ~ 2038-1-19 3:14:07\n\\r
+                        date scope is 1970-1-1 8:0:0 ~ 2038-1-19 3:14:07\n\\r
                         It can't be combined with other action options\n\\r
                         except for -o, -r option. It is a action option.\n\\r
                         If it is combined with other action options, the later\n\\r
@@ -2424,69 +2424,104 @@ Returns:
   UINT32                           Index;\r
   UINT32                           DebugDirectoryEntryRva;\r
   UINT32                           DebugDirectoryEntryFileOffset;\r
+  UINT32                           ExportDirectoryEntryRva;\r
+  UINT32                           ExportDirectoryEntryFileOffset;\r
+  UINT32                           ResourceDirectoryEntryRva;\r
+  UINT32                           ResourceDirectoryEntryFileOffset;\r
   EFI_IMAGE_DOS_HEADER            *DosHdr;\r
   EFI_IMAGE_FILE_HEADER           *FileHdr;\r
   EFI_IMAGE_OPTIONAL_HEADER32     *Optional32Hdr;\r
   EFI_IMAGE_OPTIONAL_HEADER64     *Optional64Hdr;\r
   EFI_IMAGE_SECTION_HEADER        *SectionHeader;\r
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
+  UINT32                          *NewTimeStamp;  \r
 \r
+  //\r
+  // Init variable.\r
+  //\r
+  DebugDirectoryEntryRva    = 0;\r
+  ExportDirectoryEntryRva   = 0;\r
+  ResourceDirectoryEntryRva = 0;\r
   DosHdr   = (EFI_IMAGE_DOS_HEADER *)  FileBuffer;\r
   FileHdr  = (EFI_IMAGE_FILE_HEADER *) (FileBuffer + DosHdr->e_lfanew + sizeof (UINT32));\r
-  DebugDirectoryEntryRva = 0;\r
 \r
   //\r
-  // Get DebugEntryTable RVA address.\r
+  // Get Debug, Export and Resource EntryTable RVA address.\r
+  // Resource Directory entry need to review.\r
   //\r
   if (FileHdr->Machine == EFI_IMAGE_MACHINE_IA32) {\r
     Optional32Hdr = (EFI_IMAGE_OPTIONAL_HEADER32 *) ((UINT8*) FileHdr + sizeof (EFI_IMAGE_FILE_HEADER));\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional32Hdr +  FileHdr->SizeOfOptionalHeader);\r
+    if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXPORT && \\r
+        Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size != 0) {\r
+      ExportDirectoryEntryRva = Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;\r
+    }\r
+    if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE && \\r
+        Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size != 0) {\r
+      ResourceDirectoryEntryRva = Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;\r
+    }\r
     if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG && \\r
         Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size != 0) {\r
       DebugDirectoryEntryRva = Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;\r
-    } else {\r
-      //\r
-      // No Debug Data, nothing to do.\r
-      //\r
-      return EFI_SUCCESS;\r
     }\r
   } else {\r
     Optional64Hdr = (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + sizeof (EFI_IMAGE_FILE_HEADER));\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional64Hdr +  FileHdr->SizeOfOptionalHeader);\r
+    if (Optional64Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXPORT && \\r
+        Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size != 0) {\r
+      ExportDirectoryEntryRva = Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;\r
+    }\r
+    if (Optional64Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE && \\r
+        Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size != 0) {\r
+      ResourceDirectoryEntryRva = Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;\r
+    }\r
     if (Optional64Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG && \\r
         Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size != 0) {\r
       DebugDirectoryEntryRva = Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;\r
-    } else {\r
-      //\r
-      // No Debug Data, nothing to do.\r
-      //\r
-      return EFI_SUCCESS;\r
     }\r
   }\r
 \r
   //\r
-  // Get DebugEntryTable file offset.\r
+  // Get DirectoryEntryTable file offset.\r
   //\r
   for (Index = 0; Index < FileHdr->NumberOfSections; Index ++, SectionHeader ++) {\r
     if (DebugDirectoryEntryRva >= SectionHeader->VirtualAddress &&\r
         DebugDirectoryEntryRva < SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize) {\r
         DebugDirectoryEntryFileOffset =\r
         DebugDirectoryEntryRva - SectionHeader->VirtualAddress + SectionHeader->PointerToRawData;\r
-      break;\r
     }\r
-  }\r
-\r
-  if (Index >= FileHdr->NumberOfSections) {\r
-    Error (NULL, 0, 3000, "Invalid", "PeImage");\r
-    return EFI_ABORTED;\r
+    if (ExportDirectoryEntryRva >= SectionHeader->VirtualAddress &&\r
+        ExportDirectoryEntryRva < SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize) {\r
+        ExportDirectoryEntryFileOffset =\r
+        ExportDirectoryEntryRva - SectionHeader->VirtualAddress + SectionHeader->PointerToRawData;\r
+    }\r
+    if (ResourceDirectoryEntryRva >= SectionHeader->VirtualAddress &&\r
+        ResourceDirectoryEntryRva < SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize) {\r
+        ResourceDirectoryEntryFileOffset =\r
+        ResourceDirectoryEntryRva - SectionHeader->VirtualAddress + SectionHeader->PointerToRawData;\r
+    }\r
   }\r
 \r
   //\r
-  // Zero Debug Data and TimeStamp\r
+  //Zero Debug Data and TimeStamp\r
   //\r
-  DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (FileBuffer + DebugDirectoryEntryFileOffset);\r
-  DebugEntry->TimeDateStamp = 0;\r
-  memset (FileBuffer + DebugEntry->FileOffset, 0, DebugEntry->SizeOfData);\r
+  FileHdr->TimeDateStamp = 0;\r
+\r
+  if (ExportDirectoryEntryRva != 0) {\r
+    NewTimeStamp  = (UINT32 *) (FileBuffer + ExportDirectoryEntryFileOffset + sizeof (UINT32));\r
+    *NewTimeStamp = 0;\r
+  }\r
+\r
+  if (ResourceDirectoryEntryRva != 0) {\r
+    NewTimeStamp  = (UINT32 *) (FileBuffer + ResourceDirectoryEntryFileOffset + sizeof (UINT32));\r
+    *NewTimeStamp = 0;\r
+  }\r
+\r
+  if (DebugDirectoryEntryRva != 0) {\r
+    DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (FileBuffer + DebugDirectoryEntryFileOffset);\r
+    DebugEntry->TimeDateStamp = 0;\r
+    memset (FileBuffer + DebugEntry->FileOffset, 0, DebugEntry->SizeOfData);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -2532,7 +2567,7 @@ Returns:
   EFI_IMAGE_OPTIONAL_HEADER64     *Optional64Hdr;\r
   EFI_IMAGE_SECTION_HEADER        *SectionHeader;\r
   UINT32                          *NewTimeStamp;\r
-\r
+  \r
   //\r
   // Init variable.\r
   //\r