#include "llvm/Object/WindowsResource.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/ScopedPrinter.h"
#include <ctime>
#include <queue>
usingnamespacellvm;
usingnamespaceobject;
namespace llvm {
namespace object {
#define RETURN_IF_ERROR(X) …
#define UNWRAP_REF_OR_RETURN(Name, Expr) …
#define UNWRAP_OR_RETURN(Name, Expr) …
const uint32_t MIN_HEADER_SIZE = …;
const uint32_t SECTION_ALIGNMENT = …;
WindowsResource::WindowsResource(MemoryBufferRef Source)
: … { … }
Expected<std::unique_ptr<WindowsResource>>
WindowsResource::createWindowsResource(MemoryBufferRef Source) { … }
Expected<ResourceEntryRef> WindowsResource::getHeadEntry() { … }
ResourceEntryRef::ResourceEntryRef(BinaryStreamRef Ref,
const WindowsResource *Owner)
: … { … }
Expected<ResourceEntryRef>
ResourceEntryRef::create(BinaryStreamRef BSR, const WindowsResource *Owner) { … }
Error ResourceEntryRef::moveNext(bool &End) { … }
static Error readStringOrId(BinaryStreamReader &Reader, uint16_t &ID,
ArrayRef<UTF16> &Str, bool &IsString) { … }
Error ResourceEntryRef::loadNext() { … }
WindowsResourceParser::WindowsResourceParser(bool MinGW)
: … { … }
void printResourceTypeName(uint16_t TypeID, raw_ostream &OS) { … }
static bool convertUTF16LEToUTF8String(ArrayRef<UTF16> Src, std::string &Out) { … }
static std::string makeDuplicateResourceError(
const ResourceEntryRef &Entry, StringRef File1, StringRef File2) { … }
static void printStringOrID(const WindowsResourceParser::StringOrID &S,
raw_string_ostream &OS, bool IsType, bool IsID) { … }
static std::string makeDuplicateResourceError(
const std::vector<WindowsResourceParser::StringOrID> &Context,
StringRef File1, StringRef File2) { … }
void WindowsResourceParser::cleanUpManifests(
std::vector<std::string> &Duplicates) { … }
bool WindowsResourceParser::shouldIgnoreDuplicate(
const ResourceEntryRef &Entry) const { … }
bool WindowsResourceParser::shouldIgnoreDuplicate(
const std::vector<StringOrID> &Context) const { … }
Error WindowsResourceParser::parse(WindowsResource *WR,
std::vector<std::string> &Duplicates) { … }
Error WindowsResourceParser::parse(ResourceSectionRef &RSR, StringRef Filename,
std::vector<std::string> &Duplicates) { … }
void WindowsResourceParser::printTree(raw_ostream &OS) const { … }
bool WindowsResourceParser::TreeNode::addEntry(
const ResourceEntryRef &Entry, uint32_t Origin,
std::vector<std::vector<uint8_t>> &Data,
std::vector<std::vector<UTF16>> &StringTable, TreeNode *&Result) { … }
Error WindowsResourceParser::addChildren(TreeNode &Node,
ResourceSectionRef &RSR,
const coff_resource_dir_table &Table,
uint32_t Origin,
std::vector<StringOrID> &Context,
std::vector<std::string> &Duplicates) { … }
WindowsResourceParser::TreeNode::TreeNode(uint32_t StringIndex)
: … { … }
WindowsResourceParser::TreeNode::TreeNode(uint16_t MajorVersion,
uint16_t MinorVersion,
uint32_t Characteristics,
uint32_t Origin, uint32_t DataIndex)
: … { … }
std::unique_ptr<WindowsResourceParser::TreeNode>
WindowsResourceParser::TreeNode::createStringNode(uint32_t Index) { … }
std::unique_ptr<WindowsResourceParser::TreeNode>
WindowsResourceParser::TreeNode::createIDNode() { … }
std::unique_ptr<WindowsResourceParser::TreeNode>
WindowsResourceParser::TreeNode::createDataNode(uint16_t MajorVersion,
uint16_t MinorVersion,
uint32_t Characteristics,
uint32_t Origin,
uint32_t DataIndex) { … }
WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addTypeNode(
const ResourceEntryRef &Entry,
std::vector<std::vector<UTF16>> &StringTable) { … }
WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addNameNode(
const ResourceEntryRef &Entry,
std::vector<std::vector<UTF16>> &StringTable) { … }
bool WindowsResourceParser::TreeNode::addLanguageNode(
const ResourceEntryRef &Entry, uint32_t Origin,
std::vector<std::vector<uint8_t>> &Data, TreeNode *&Result) { … }
bool WindowsResourceParser::TreeNode::addDataChild(
uint32_t ID, uint16_t MajorVersion, uint16_t MinorVersion,
uint32_t Characteristics, uint32_t Origin, uint32_t DataIndex,
TreeNode *&Result) { … }
WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addIDChild(
uint32_t ID) { … }
WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addNameChild(
ArrayRef<UTF16> NameRef, std::vector<std::vector<UTF16>> &StringTable) { … }
void WindowsResourceParser::TreeNode::print(ScopedPrinter &Writer,
StringRef Name) const { … }
uint32_t WindowsResourceParser::TreeNode::getTreeSize() const { … }
void WindowsResourceParser::TreeNode::shiftDataIndexDown(uint32_t Index) { … }
class WindowsResourceCOFFWriter { … };
WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(
COFF::MachineTypes MachineType, const WindowsResourceParser &Parser,
Error &E)
: … { … }
void WindowsResourceCOFFWriter::performFileLayout() { … }
void WindowsResourceCOFFWriter::performSectionOneLayout() { … }
void WindowsResourceCOFFWriter::performSectionTwoLayout() { … }
std::unique_ptr<MemoryBuffer>
WindowsResourceCOFFWriter::write(uint32_t TimeDateStamp) { … }
static void coffnamecpy(char (&Dest)[COFF::NameSize], StringRef Src) { … }
void WindowsResourceCOFFWriter::writeCOFFHeader(uint32_t TimeDateStamp) { … }
void WindowsResourceCOFFWriter::writeFirstSectionHeader() { … }
void WindowsResourceCOFFWriter::writeSecondSectionHeader() { … }
void WindowsResourceCOFFWriter::writeFirstSection() { … }
void WindowsResourceCOFFWriter::writeSecondSection() { … }
void WindowsResourceCOFFWriter::writeSymbolTable() { … }
void WindowsResourceCOFFWriter::writeStringTable() { … }
void WindowsResourceCOFFWriter::writeDirectoryTree() { … }
void WindowsResourceCOFFWriter::writeDirectoryStringTable() { … }
void WindowsResourceCOFFWriter::writeFirstSectionRelocations() { … }
Expected<std::unique_ptr<MemoryBuffer>>
writeWindowsResourceCOFF(COFF::MachineTypes MachineType,
const WindowsResourceParser &Parser,
uint32_t TimeDateStamp) { … }
}
}