1 //===-- WindowsResourceDumper.cpp - Windows Resource printer --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Windows resource (.res) dumper for llvm-readobj.
12 //===----------------------------------------------------------------------===//
14 #include "WindowsResourceDumper.h"
16 #include "llvm/Object/WindowsResource.h"
17 #include "llvm/Support/ConvertUTF.h"
18 #include "llvm/Support/ScopedPrinter.h"
22 namespace WindowsRes
{
24 std::string
stripUTF16(const ArrayRef
<UTF16
> &UTF16Str
) {
26 Result
.reserve(UTF16Str
.size());
28 for (UTF16 Ch
: UTF16Str
) {
29 // UTF16Str will have swapped byte order in case of big-endian machines.
30 // Swap it back in such a case.
31 uint16_t ChValue
= support::endian::byte_swap(Ch
, support::little
);
40 Error
Dumper::printData() {
41 auto EntryPtrOrErr
= WinRes
->getHeadEntry();
43 return EntryPtrOrErr
.takeError();
44 auto EntryPtr
= *EntryPtrOrErr
;
50 if (auto Err
= EntryPtr
.moveNext(IsEnd
))
53 return Error::success();
56 void Dumper::printEntry(const ResourceEntryRef
&Ref
) {
57 if (Ref
.checkTypeString()) {
58 auto NarrowStr
= stripUTF16(Ref
.getTypeString());
59 SW
.printString("Resource type (string)", NarrowStr
);
61 SW
.printNumber("Resource type (int)", Ref
.getTypeID());
63 if (Ref
.checkNameString()) {
64 auto NarrowStr
= stripUTF16(Ref
.getNameString());
65 SW
.printString("Resource name (string)", NarrowStr
);
67 SW
.printNumber("Resource name (int)", Ref
.getNameID());
69 SW
.printNumber("Data version", Ref
.getDataVersion());
70 SW
.printHex("Memory flags", Ref
.getMemoryFlags());
71 SW
.printNumber("Language ID", Ref
.getLanguage());
72 SW
.printNumber("Version (major)", Ref
.getMajorVersion());
73 SW
.printNumber("Version (minor)", Ref
.getMinorVersion());
74 SW
.printNumber("Characteristics", Ref
.getCharacteristics());
75 SW
.printNumber("Data size", (uint64_t)Ref
.getData().size());
76 SW
.printBinary("Data:", Ref
.getData());
77 SW
.startLine() << "\n";
80 } // namespace WindowsRes