Lines Matching +full:os +full:- +full:manifest +full:- +full:offset

1 //===-- WindowsResource.cpp -------------------------------------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
47 // 8-byte because it makes everyone happy.
106 Reader.getOffset() - in readStringOrId()
107 sizeof(uint16_t)); // Re-read the bytes which we used to check the flag. in readStringOrId()
119 if (Prefix->HeaderSize < MIN_HEADER_SIZE) in loadNext()
120 return make_error<GenericBinaryError>(Owner->getFileName() + in loadNext()
132 RETURN_IF_ERROR(Reader.readArray(Data, Prefix->DataSize)); in loadNext()
142 void printResourceTypeName(uint16_t TypeID, raw_ostream &OS) { in printResourceTypeName() argument
144 case 1: OS << "CURSOR (ID 1)"; break; in printResourceTypeName()
145 case 2: OS << "BITMAP (ID 2)"; break; in printResourceTypeName()
146 case 3: OS << "ICON (ID 3)"; break; in printResourceTypeName()
147 case 4: OS << "MENU (ID 4)"; break; in printResourceTypeName()
148 case 5: OS << "DIALOG (ID 5)"; break; in printResourceTypeName()
149 case 6: OS << "STRINGTABLE (ID 6)"; break; in printResourceTypeName()
150 case 7: OS << "FONTDIR (ID 7)"; break; in printResourceTypeName()
151 case 8: OS << "FONT (ID 8)"; break; in printResourceTypeName()
152 case 9: OS << "ACCELERATOR (ID 9)"; break; in printResourceTypeName()
153 case 10: OS << "RCDATA (ID 10)"; break; in printResourceTypeName()
154 case 11: OS << "MESSAGETABLE (ID 11)"; break; in printResourceTypeName()
155 case 12: OS << "GROUP_CURSOR (ID 12)"; break; in printResourceTypeName()
156 case 14: OS << "GROUP_ICON (ID 14)"; break; in printResourceTypeName()
157 case 16: OS << "VERSIONINFO (ID 16)"; break; in printResourceTypeName()
158 case 17: OS << "DLGINCLUDE (ID 17)"; break; in printResourceTypeName()
159 case 19: OS << "PLUGPLAY (ID 19)"; break; in printResourceTypeName()
160 case 20: OS << "VXD (ID 20)"; break; in printResourceTypeName()
161 case 21: OS << "ANICURSOR (ID 21)"; break; in printResourceTypeName()
162 case 22: OS << "ANIICON (ID 22)"; break; in printResourceTypeName()
163 case 23: OS << "HTML (ID 23)"; break; in printResourceTypeName()
164 case 24: OS << "MANIFEST (ID 24)"; break; in printResourceTypeName()
165 default: OS << "ID " << TypeID; break; in printResourceTypeName()
183 raw_string_ostream OS(Ret); in makeDuplicateResourceError() local
185 OS << "duplicate resource:"; in makeDuplicateResourceError()
187 OS << " type "; in makeDuplicateResourceError()
192 OS << '\"' << UTF8 << '\"'; in makeDuplicateResourceError()
194 printResourceTypeName(Entry.getTypeID(), OS); in makeDuplicateResourceError()
196 OS << "/name "; in makeDuplicateResourceError()
201 OS << '\"' << UTF8 << '\"'; in makeDuplicateResourceError()
203 OS << "ID " << Entry.getNameID(); in makeDuplicateResourceError()
206 OS << "/language " << Entry.getLanguage() << ", in " << File1 << " and in " in makeDuplicateResourceError()
209 return OS.str(); in makeDuplicateResourceError()
213 raw_string_ostream &OS, bool IsType, bool IsID) { in printStringOrID() argument
218 OS << '\"' << UTF8 << '\"'; in printStringOrID()
220 printResourceTypeName(S.ID, OS); in printStringOrID()
222 OS << "ID " << S.ID; in printStringOrID()
224 OS << S.ID; in printStringOrID()
231 raw_string_ostream OS(Ret); in makeDuplicateResourceError() local
233 OS << "duplicate resource:"; in makeDuplicateResourceError()
236 OS << " type "; in makeDuplicateResourceError()
237 printStringOrID(Context[0], OS, /* IsType */ true, /* IsID */ true); in makeDuplicateResourceError()
241 OS << "/name "; in makeDuplicateResourceError()
242 printStringOrID(Context[1], OS, /* IsType */ false, /* IsID */ true); in makeDuplicateResourceError()
246 OS << "/language "; in makeDuplicateResourceError()
247 printStringOrID(Context[2], OS, /* IsType */ false, /* IsID */ false); in makeDuplicateResourceError()
249 OS << ", in " << File1 << " and in " << File2; in makeDuplicateResourceError()
251 return OS.str(); in makeDuplicateResourceError()
256 // manifest with a non-zero language code.
257 // GCC has the concept of a default manifest resource object, which gets
258 // linked in implicitly if present. This default manifest has got language
259 // id zero, and should be dropped silently if there's another manifest present.
260 // If the user resources surprisignly had a manifest with language id zero,
261 // we should also ignore the duplicate default manifest.
268 TreeNode *TypeNode = TypeIt->second.get(); in cleanUpManifests()
270 TypeNode->IDChildren.find(/* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 1); in cleanUpManifests()
271 if (NameIt == TypeNode->IDChildren.end()) in cleanUpManifests()
274 TreeNode *NameNode = NameIt->second.get(); in cleanUpManifests()
275 if (NameNode->IDChildren.size() <= 1) in cleanUpManifests()
276 return; // None or one manifest present, all good. in cleanUpManifests()
278 // If we have more than one manifest, drop the language zero one if present, in cleanUpManifests()
280 auto LangZeroIt = NameNode->IDChildren.find(0); in cleanUpManifests()
281 if (LangZeroIt != NameNode->IDChildren.end() && in cleanUpManifests()
282 LangZeroIt->second->IsDataNode) { in cleanUpManifests()
283 uint32_t RemovedIndex = LangZeroIt->second->DataIndex; in cleanUpManifests()
284 NameNode->IDChildren.erase(LangZeroIt); in cleanUpManifests()
288 // If we're now down to one manifest, all is good. in cleanUpManifests()
289 if (NameNode->IDChildren.size() <= 1) in cleanUpManifests()
293 // More than one non-language-zero manifest in cleanUpManifests()
294 auto FirstIt = NameNode->IDChildren.begin(); in cleanUpManifests()
295 uint32_t FirstLang = FirstIt->first; in cleanUpManifests()
296 TreeNode *FirstNode = FirstIt->second.get(); in cleanUpManifests()
297 auto LastIt = NameNode->IDChildren.rbegin(); in cleanUpManifests()
298 uint32_t LastLang = LastIt->first; in cleanUpManifests()
299 TreeNode *LastNode = LastIt->second.get(); in cleanUpManifests()
301 ("duplicate non-default manifests with languages " + Twine(FirstLang) + in cleanUpManifests()
302 " in " + InputFilenames[FirstNode->Origin] + " and " + Twine(LastLang) + in cleanUpManifests()
303 " in " + InputFilenames[LastNode->Origin]) in cleanUpManifests()
307 // Ignore duplicates of manifests with language zero (the default manifest),
308 // in case the user has provided a manifest with that language id. See
330 auto EntryOrErr = WR->getHeadEntry(); in parse()
348 InputFilenames.push_back(std::string(WR->getFileName())); in parse()
357 Entry, InputFilenames[Node->Origin], WR->getFileName())); in parse()
375 void WindowsResourceParser::printTree(raw_ostream &OS) const { in printTree()
376 ScopedPrinter Writer(OS); in printTree()
401 if (Entry.Offset.isSubDir()) { in addChildren()
442 Context, InputFilenames[Child->Origin], InputFilenames.back())); in addChildren()
518 Result = ElementInserted.first->second.get(); in addDataChild()
531 return *(Child->second); in addIDChild()
547 return *(Child->second); in addNameChild()
554 Child.second->print(Writer, Child.first); in print()
557 Child.second->print(Writer, to_string(Child.first)); in print()
579 Size += Child.second->getTreeSize(); in getTreeSize()
582 Size += Child.second->getTreeSize(); in getTreeSize()
591 DataIndex--; in shiftDataIndexDown()
594 Child.second->shiftDataIndexDown(Index); in shiftDataIndexDown()
596 Child.second->shiftDataIndexDown(Index); in shiftDataIndexDown()
692 // add size of .rsrc$2 section, which contains all resource data on 8-byte in performSectionTwoLayout()
706 BufferStart = OutputBuffer->getBufferStart(); in write()
732 Header->Machine = MachineType; in writeCOFFHeader()
733 Header->NumberOfSections = 2; in writeCOFFHeader()
734 Header->TimeDateStamp = TimeDateStamp; in writeCOFFHeader()
735 Header->PointerToSymbolTable = SymbolTableOffset; in writeCOFFHeader()
737 Header->NumberOfSymbols = Data.size() + 5; in writeCOFFHeader()
738 Header->SizeOfOptionalHeader = 0; in writeCOFFHeader()
739 // cvtres.exe sets 32BIT_MACHINE even for 64-bit machine types. Match it. in writeCOFFHeader()
740 Header->Characteristics = COFF::IMAGE_FILE_32BIT_MACHINE; in writeCOFFHeader()
748 coffnamecpy(SectionOneHeader->Name, ".rsrc$01"); in writeFirstSectionHeader()
749 SectionOneHeader->VirtualSize = 0; in writeFirstSectionHeader()
750 SectionOneHeader->VirtualAddress = 0; in writeFirstSectionHeader()
751 SectionOneHeader->SizeOfRawData = SectionOneSize; in writeFirstSectionHeader()
752 SectionOneHeader->PointerToRawData = SectionOneOffset; in writeFirstSectionHeader()
753 SectionOneHeader->PointerToRelocations = SectionOneRelocations; in writeFirstSectionHeader()
754 SectionOneHeader->PointerToLinenumbers = 0; in writeFirstSectionHeader()
755 SectionOneHeader->NumberOfRelocations = Data.size(); in writeFirstSectionHeader()
756 SectionOneHeader->NumberOfLinenumbers = 0; in writeFirstSectionHeader()
757 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; in writeFirstSectionHeader()
758 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ; in writeFirstSectionHeader()
766 coffnamecpy(SectionTwoHeader->Name, ".rsrc$02"); in writeSecondSectionHeader()
767 SectionTwoHeader->VirtualSize = 0; in writeSecondSectionHeader()
768 SectionTwoHeader->VirtualAddress = 0; in writeSecondSectionHeader()
769 SectionTwoHeader->SizeOfRawData = SectionTwoSize; in writeSecondSectionHeader()
770 SectionTwoHeader->PointerToRawData = SectionTwoOffset; in writeSecondSectionHeader()
771 SectionTwoHeader->PointerToRelocations = 0; in writeSecondSectionHeader()
772 SectionTwoHeader->PointerToLinenumbers = 0; in writeSecondSectionHeader()
773 SectionTwoHeader->NumberOfRelocations = 0; in writeSecondSectionHeader()
774 SectionTwoHeader->NumberOfLinenumbers = 0; in writeSecondSectionHeader()
775 SectionTwoHeader->Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; in writeSecondSectionHeader()
776 SectionTwoHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ; in writeSecondSectionHeader()
804 coffnamecpy(Symbol->Name.ShortName, "@feat.00"); in writeSymbolTable()
805 Symbol->Value = 0x11; in writeSymbolTable()
806 Symbol->SectionNumber = 0xffff; in writeSymbolTable()
807 Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL; in writeSymbolTable()
808 Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; in writeSymbolTable()
809 Symbol->NumberOfAuxSymbols = 0; in writeSymbolTable()
814 coffnamecpy(Symbol->Name.ShortName, ".rsrc$01"); in writeSymbolTable()
815 Symbol->Value = 0; in writeSymbolTable()
816 Symbol->SectionNumber = 1; in writeSymbolTable()
817 Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL; in writeSymbolTable()
818 Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; in writeSymbolTable()
819 Symbol->NumberOfAuxSymbols = 1; in writeSymbolTable()
823 Aux->Length = SectionOneSize; in writeSymbolTable()
824 Aux->NumberOfRelocations = Data.size(); in writeSymbolTable()
825 Aux->NumberOfLinenumbers = 0; in writeSymbolTable()
826 Aux->CheckSum = 0; in writeSymbolTable()
827 Aux->NumberLowPart = 0; in writeSymbolTable()
828 Aux->Selection = 0; in writeSymbolTable()
833 coffnamecpy(Symbol->Name.ShortName, ".rsrc$02"); in writeSymbolTable()
834 Symbol->Value = 0; in writeSymbolTable()
835 Symbol->SectionNumber = 2; in writeSymbolTable()
836 Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL; in writeSymbolTable()
837 Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; in writeSymbolTable()
838 Symbol->NumberOfAuxSymbols = 1; in writeSymbolTable()
842 Aux->Length = SectionTwoSize; in writeSymbolTable()
843 Aux->NumberOfRelocations = 0; in writeSymbolTable()
844 Aux->NumberOfLinenumbers = 0; in writeSymbolTable()
845 Aux->CheckSum = 0; in writeSymbolTable()
846 Aux->NumberLowPart = 0; in writeSymbolTable()
847 Aux->Selection = 0; in writeSymbolTable()
852 auto RelocationName = formatv("$R{0:X-6}", i & 0xffffff).sstr<COFF::NameSize>(); in writeSymbolTable()
854 coffnamecpy(Symbol->Name.ShortName, RelocationName); in writeSymbolTable()
855 Symbol->Value = DataOffsets[i]; in writeSymbolTable()
856 Symbol->SectionNumber = 2; in writeSymbolTable()
857 Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL; in writeSymbolTable()
858 Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC; in writeSymbolTable()
859 Symbol->NumberOfAuxSymbols = 0; in writeSymbolTable()
871 // Traverse parsed resource tree breadth-first and write the corresponding in writeDirectoryTree()
887 Table->Characteristics = CurrentNode->getCharacteristics(); in writeDirectoryTree()
888 Table->TimeDateStamp = 0; in writeDirectoryTree()
889 Table->MajorVersion = CurrentNode->getMajorVersion(); in writeDirectoryTree()
890 Table->MinorVersion = CurrentNode->getMinorVersion(); in writeDirectoryTree()
891 auto &IDChildren = CurrentNode->getIDChildren(); in writeDirectoryTree()
892 auto &StringChildren = CurrentNode->getStringChildren(); in writeDirectoryTree()
893 Table->NumberOfNameEntries = StringChildren.size(); in writeDirectoryTree()
894 Table->NumberOfIDEntries = IDChildren.size(); in writeDirectoryTree()
902 Entry->Identifier.setNameOffset( in writeDirectoryTree()
903 StringTableOffsets[Child.second->getStringIndex()]); in writeDirectoryTree()
904 if (Child.second->checkIsDataNode()) { in writeDirectoryTree()
905 Entry->Offset.DataEntryOffset = NextLevelOffset; in writeDirectoryTree()
909 Entry->Offset.SubdirOffset = NextLevelOffset + (1 << 31); in writeDirectoryTree()
911 (Child.second->getStringChildren().size() + in writeDirectoryTree()
912 Child.second->getIDChildren().size()) * in writeDirectoryTree()
922 Entry->Identifier.ID = Child.first; in writeDirectoryTree()
923 if (Child.second->checkIsDataNode()) { in writeDirectoryTree()
924 Entry->Offset.DataEntryOffset = NextLevelOffset; in writeDirectoryTree()
928 Entry->Offset.SubdirOffset = NextLevelOffset + (1 << 31); in writeDirectoryTree()
930 (Child.second->getStringChildren().size() + in writeDirectoryTree()
931 Child.second->getIDChildren().size()) * in writeDirectoryTree()
945 RelocationAddresses[DataNodes->getDataIndex()] = CurrentRelativeOffset; in writeDirectoryTree()
946 Entry->DataRVA = 0; // Set to zero because it is a relocation. in writeDirectoryTree()
947 Entry->DataSize = Data[DataNodes->getDataIndex()].size(); in writeDirectoryTree()
948 Entry->Codepage = 0; in writeDirectoryTree()
949 Entry->Reserved = 0; in writeDirectoryTree()
968 alignTo(TotalStringTableSize, sizeof(uint32_t)) - TotalStringTableSize; in writeDirectoryStringTable()
980 Reloc->VirtualAddress = RelocationAddresses[i]; in writeFirstSectionRelocations()
981 Reloc->SymbolTableIndex = NextSymbolIndex++; in writeFirstSectionRelocations()
984 Reloc->Type = COFF::IMAGE_REL_ARM_ADDR32NB; in writeFirstSectionRelocations()
987 Reloc->Type = COFF::IMAGE_REL_AMD64_ADDR32NB; in writeFirstSectionRelocations()
990 Reloc->Type = COFF::IMAGE_REL_I386_DIR32NB; in writeFirstSectionRelocations()
993 Reloc->Type = COFF::IMAGE_REL_ARM64_ADDR32NB; in writeFirstSectionRelocations()