1 //===-- WindowsResourceDumper.cpp - Windows Resource printer --------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Windows resource (.res) dumper for llvm-readobj.
11 //===----------------------------------------------------------------------===//
13 #include "WindowsResourceDumper.h"
15 #include "llvm/Object/WindowsResource.h"
16 #include "llvm/Support/ConvertUTF.h"
17 #include "llvm/Support/ScopedPrinter.h"
21 namespace WindowsRes
{
23 std::string
stripUTF16(const ArrayRef
<UTF16
> &UTF16Str
) {
25 Result
.reserve(UTF16Str
.size());
27 for (UTF16 Ch
: UTF16Str
) {
28 // UTF16Str will have swapped byte order in case of big-endian machines.
29 // Swap it back in such a case.
30 uint16_t ChValue
= support::endian::byte_swap(Ch
, support::little
);
39 Error
Dumper::printData() {
40 auto EntryPtrOrErr
= WinRes
->getHeadEntry();
42 return EntryPtrOrErr
.takeError();
43 auto EntryPtr
= *EntryPtrOrErr
;
49 if (auto Err
= EntryPtr
.moveNext(IsEnd
))
52 return Error::success();
55 void Dumper::printEntry(const ResourceEntryRef
&Ref
) {
56 if (Ref
.checkTypeString()) {
57 auto NarrowStr
= stripUTF16(Ref
.getTypeString());
58 SW
.printString("Resource type (string)", NarrowStr
);
60 SW
.printNumber("Resource type (int)", Ref
.getTypeID());
62 if (Ref
.checkNameString()) {
63 auto NarrowStr
= stripUTF16(Ref
.getNameString());
64 SW
.printString("Resource name (string)", NarrowStr
);
66 SW
.printNumber("Resource name (int)", Ref
.getNameID());
68 SW
.printNumber("Data version", Ref
.getDataVersion());
69 SW
.printHex("Memory flags", Ref
.getMemoryFlags());
70 SW
.printNumber("Language ID", Ref
.getLanguage());
71 SW
.printNumber("Version (major)", Ref
.getMajorVersion());
72 SW
.printNumber("Version (minor)", Ref
.getMinorVersion());
73 SW
.printNumber("Characteristics", Ref
.getCharacteristics());
74 SW
.printNumber("Data size", (uint64_t)Ref
.getData().size());
75 SW
.printBinary("Data:", Ref
.getData());
76 SW
.startLine() << "\n";
79 } // namespace WindowsRes