2017-09-20 20:33:35 +02:00
|
|
|
//===-- WindowsResourceDumper.cpp - Windows Resource printer --------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-20 20:33:35 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Windows resource (.res) dumper for llvm-readobj.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "WindowsResourceDumper.h"
|
|
|
|
#include "llvm/Object/WindowsResource.h"
|
2017-09-21 01:26:05 +02:00
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
2017-09-20 20:33:35 +02:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace object {
|
|
|
|
namespace WindowsRes {
|
|
|
|
|
|
|
|
std::string stripUTF16(const ArrayRef<UTF16> &UTF16Str) {
|
|
|
|
std::string Result;
|
|
|
|
Result.reserve(UTF16Str.size());
|
|
|
|
|
|
|
|
for (UTF16 Ch : UTF16Str) {
|
2017-09-21 01:07:39 +02:00
|
|
|
// UTF16Str will have swapped byte order in case of big-endian machines.
|
|
|
|
// Swap it back in such a case.
|
2017-09-21 22:36:38 +02:00
|
|
|
uint16_t ChValue = support::endian::byte_swap(Ch, support::little);
|
2017-09-21 01:07:39 +02:00
|
|
|
if (ChValue <= 0xFF)
|
|
|
|
Result += ChValue;
|
2017-09-20 20:33:35 +02:00
|
|
|
else
|
|
|
|
Result += '?';
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error Dumper::printData() {
|
|
|
|
auto EntryPtrOrErr = WinRes->getHeadEntry();
|
|
|
|
if (!EntryPtrOrErr)
|
|
|
|
return EntryPtrOrErr.takeError();
|
|
|
|
auto EntryPtr = *EntryPtrOrErr;
|
|
|
|
|
|
|
|
bool IsEnd = false;
|
|
|
|
while (!IsEnd) {
|
|
|
|
printEntry(EntryPtr);
|
|
|
|
|
|
|
|
if (auto Err = EntryPtr.moveNext(IsEnd))
|
|
|
|
return Err;
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dumper::printEntry(const ResourceEntryRef &Ref) {
|
|
|
|
if (Ref.checkTypeString()) {
|
|
|
|
auto NarrowStr = stripUTF16(Ref.getTypeString());
|
|
|
|
SW.printString("Resource type (string)", NarrowStr);
|
2019-08-29 10:59:31 +02:00
|
|
|
} else {
|
|
|
|
SmallString<20> IDStr;
|
|
|
|
raw_svector_ostream OS(IDStr);
|
|
|
|
printResourceTypeName(Ref.getTypeID(), OS);
|
|
|
|
SW.printString("Resource type (int)", IDStr);
|
|
|
|
}
|
2017-09-20 20:33:35 +02:00
|
|
|
|
|
|
|
if (Ref.checkNameString()) {
|
|
|
|
auto NarrowStr = stripUTF16(Ref.getNameString());
|
|
|
|
SW.printString("Resource name (string)", NarrowStr);
|
|
|
|
} else
|
|
|
|
SW.printNumber("Resource name (int)", Ref.getNameID());
|
|
|
|
|
|
|
|
SW.printNumber("Data version", Ref.getDataVersion());
|
|
|
|
SW.printHex("Memory flags", Ref.getMemoryFlags());
|
|
|
|
SW.printNumber("Language ID", Ref.getLanguage());
|
|
|
|
SW.printNumber("Version (major)", Ref.getMajorVersion());
|
|
|
|
SW.printNumber("Version (minor)", Ref.getMinorVersion());
|
|
|
|
SW.printNumber("Characteristics", Ref.getCharacteristics());
|
2017-09-20 23:03:37 +02:00
|
|
|
SW.printNumber("Data size", (uint64_t)Ref.getData().size());
|
2017-09-20 20:33:35 +02:00
|
|
|
SW.printBinary("Data:", Ref.getData());
|
|
|
|
SW.startLine() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace WindowsRes
|
|
|
|
} // namespace object
|
|
|
|
} // namespace llvm
|