Index: llvm/trunk/include/llvm/Object/Binary.h =================================================================== --- llvm/trunk/include/llvm/Object/Binary.h +++ llvm/trunk/include/llvm/Object/Binary.h @@ -44,6 +44,8 @@ ID_COFFImportFile, ID_IR, // LLVM IR + ID_WinRes, // Windows resource (.res) file. + // Object and children. ID_StartObjects, ID_COFF, @@ -58,8 +60,6 @@ ID_MachO64L, // MachO 64-bit, little endian ID_MachO64B, // MachO 64-bit, big endian - ID_WinRes, // Windows resource (.res) file. - ID_Wasm, ID_EndObjects Index: llvm/trunk/include/llvm/Object/WindowsResource.h =================================================================== --- llvm/trunk/include/llvm/Object/WindowsResource.h +++ llvm/trunk/include/llvm/Object/WindowsResource.h @@ -100,7 +100,9 @@ bool checkNameString() const { return IsStringName; } ArrayRef getNameString() const { return Name; } uint16_t getNameID() const { return NameID; } + uint16_t getDataVersion() const { return Suffix->DataVersion; } uint16_t getLanguage() const { return Suffix->Language; } + uint16_t getMemoryFlags() const { return Suffix->MemoryFlags; } uint16_t getMajorVersion() const { return Suffix->Version >> 16; } uint16_t getMinorVersion() const { return Suffix->Version; } uint32_t getCharacteristics() const { return Suffix->Characteristics; } Index: llvm/trunk/include/llvm/WindowsResource/ResourceProcessor.h =================================================================== --- llvm/trunk/include/llvm/WindowsResource/ResourceProcessor.h +++ llvm/trunk/include/llvm/WindowsResource/ResourceProcessor.h @@ -0,0 +1,51 @@ +//===-- ResourceProcessor.h -------------------------------------*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// + +#ifndef LLVM_INCLUDE_LLVM_SUPPORT_WINDOWS_RESOURCE_PROCESSOR_H +#define LLVM_INCLUDE_LLVM_SUPPORT_WINDOWS_RESOURCE_PROCESSOR_H + +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/raw_ostream.h" + +#include +#include + + +namespace llvm { + +class WindowsResourceProcessor { +public: + using PathType = SmallVector; + + WindowsResourceProcessor() {} + + void addDefine(StringRef Key, StringRef Value = StringRef()) { + PreprocessorDefines.emplace_back(Key, Value); + } + void addInclude(const PathType &IncludePath) { + IncludeList.push_back(IncludePath); + } + void setVerbose(bool Verbose) { IsVerbose = Verbose; } + void setNullAtEnd(bool NullAtEnd) { AppendNull = NullAtEnd; } + + Error process(StringRef InputData, + std::unique_ptr OutputStream); + +private: + StringRef InputData; + std::vector IncludeList; + std::vector> PreprocessorDefines; + bool IsVerbose, AppendNull; +}; + +} + +#endif Index: llvm/trunk/include/llvm/WindowsResource/ResourceScriptToken.h =================================================================== --- llvm/trunk/include/llvm/WindowsResource/ResourceScriptToken.h +++ llvm/trunk/include/llvm/WindowsResource/ResourceScriptToken.h @@ -0,0 +1,59 @@ +//===-- ResourceScriptToken.h -----------------------------------*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// +// +// This declares the .rc script tokens. +// The list of available tokens is located at ResourceScriptTokenList.h. +// +// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx +// +//===---------------------------------------------------------------------===// + +#ifndef LLVM_INCLUDE_LLVM_SUPPORT_WINDOWS_RESOURCE_SCRIPTTOKEN_H +#define LLVM_INCLUDE_LLVM_SUPPORT_WINDOWS_RESOURCE_SCRIPTTOKEN_H + +#include "llvm/ADT/StringRef.h" + +namespace llvm { + +// A definition of a single resource script token. Each token has its kind +// (declared in ResourceScriptTokenList) and holds a value - a reference +// representation of the token. +// RCToken does not claim ownership on its value. A memory buffer containing +// the token value should be stored in a safe place and cannot be freed +// nor reallocated. +class RCToken { +public: + enum class Kind { +#define TOKEN(Name) Name, +#define SHORT_TOKEN(Name, Ch) Name, +#include "ResourceScriptTokenList.h" +#undef TOKEN +#undef SHORT_TOKEN + }; + + RCToken(RCToken::Kind RCTokenKind, StringRef Value); + + // Get an integer value of the integer token. + uint32_t intValue() const; + bool isLongInt() const; + + StringRef value() const; + Kind kind() const; + + // Check if a token describes a binary operator. + bool isBinaryOp() const; + +private: + Kind TokenKind; + StringRef TokenValue; +}; + +} // namespace llvm + +#endif Index: llvm/trunk/include/llvm/WindowsResource/ResourceScriptTokenList.h =================================================================== --- llvm/trunk/include/llvm/WindowsResource/ResourceScriptTokenList.h +++ llvm/trunk/include/llvm/WindowsResource/ResourceScriptTokenList.h @@ -0,0 +1,35 @@ +//===-- ResourceScriptTokenList.h -------------------------------*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// +// +// This is a part of llvm-rc tokens header. It lists all the possible tokens +// that might occur in a correct .rc script. +// +//===---------------------------------------------------------------------===// + + +// Long tokens. They might consist of more than one character. +TOKEN(Invalid) // Invalid token. Should not occur in a valid script. +TOKEN(Int) // Integer (decimal, octal or hexadecimal). +TOKEN(String) // String value. +TOKEN(Identifier) // Script identifier (resource name or type). + +// Short tokens. They usually consist of exactly one character. +// The definitions are of the form SHORT_TOKEN(TokenName, TokenChar). +// TokenChar is the one-character token representation occuring in the correct +// .rc scripts. +SHORT_TOKEN(BlockBegin, '{') // Start of the script block; can also be BEGIN. +SHORT_TOKEN(BlockEnd, '}') // End of the block; can also be END. +SHORT_TOKEN(Comma, ',') // Comma - resource arguments separator. +SHORT_TOKEN(Plus, '+') // Addition operator. +SHORT_TOKEN(Minus, '-') // Subtraction operator. +SHORT_TOKEN(Pipe, '|') // Bitwise-OR operator. +SHORT_TOKEN(Amp, '&') // Bitwise-AND operator. +SHORT_TOKEN(Tilde, '~') // Bitwise-NOT operator. +SHORT_TOKEN(LeftParen, '(') // Left parenthesis in the script expressions. +SHORT_TOKEN(RightParen, ')') // Right parenthesis. Index: llvm/trunk/test/tools/llvm-readobj/coff-resources.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/coff-resources.test +++ llvm/trunk/test/tools/llvm-readobj/coff-resources.test @@ -0,0 +1,143 @@ +// Check dumping of the .rsrc section(s) +// The input was generated with the following commands, using the original Windows +// rc.exe and cvtres.exe: +// > rc /fo test_resource.res /nologo test_resource.rc +// > cvtres /machine:X86 /readonly /nologo /out:test_resource.o test_resource.res + +RUN: llvm-readobj -coff-resources -section-data %p/Inputs/zero-string-table.obj.coff-i386 \ +RUN: | FileCheck %s -check-prefix ZERO +RUN: llvm-readobj -coff-resources %p/Inputs/resources/test_resource.obj.coff \ +RUN: | FileCheck %s -check-prefix TEST_RES + +ZERO: Resources [ +ZERO-NEXT: Total Number of Resources: 1 +ZERO-NEXT: Base Table Address: 0x188 +ZERO-DAG: Number of String Entries: 0 +ZERO-NEXT: Number of ID Entries: 1 +ZERO-NEXT: Type: kRT_STRING (ID 6) [ +ZERO-NEXT: Table Offset: 0x18 +ZERO-NEXT: Number of String Entries: 0 +ZERO-NEXT: Number of ID Entries: 1 +ZERO-NEXT: Name: (ID 1) [ +ZERO-NEXT: Table Offset: 0x30 +ZERO-NEXT: Number of String Entries: 0 +ZERO-NEXT: Number of ID Entries: 1 +ZERO-NEXT: Language: (ID 1033) [ +ZERO-NEXT: Entry Offset: 0x48 +ZERO-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +ZERO-NEXT: Major Version: 0 +ZERO-NEXT: Minor Version: 0 +ZERO-NEXT: Characteristics: 0 +ZERO-NEXT: ] +ZERO-NEXT: ] +ZERO-NEXT: ] + +TEST_RES: Resources [ +TEST_RES-NEXT: Total Number of Resources: 7 +TEST_RES-NEXT: Base Table Address: 0x1C0 +TEST_RES-DAG: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 4 +TEST_RES-NEXT: Type: kRT_BITMAP (ID 2) [ +TEST_RES-NEXT: Table Offset: 0x30 +TEST_RES-NEXT: Number of String Entries: 2 +TEST_RES-NEXT: Number of ID Entries: 0 +TEST_RES-NEXT: Name: CURSOR [ +TEST_RES-NEXT: Table Offset: 0xA8 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 1033) [ +TEST_RES-NEXT: Entry Offset: 0x150 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Name: OKAY [ +TEST_RES-NEXT: Table Offset: 0xC0 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 1033) [ +TEST_RES-NEXT: Entry Offset: 0x160 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Type: kRT_MENU (ID 4) [ +TEST_RES-NEXT: Table Offset: 0x50 +TEST_RES-NEXT: Number of String Entries: 1 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Name: "EAT" [ +TEST_RES-NEXT: Table Offset: 0xD8 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 3081) [ +TEST_RES-NEXT: Entry Offset: 0x170 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Name: (ID 14432) [ +TEST_RES-NEXT: Table Offset: 0xF0 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 2052) [ +TEST_RES-NEXT: Entry Offset: 0x180 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Type: kRT_DIALOG (ID 5) [ +TEST_RES-NEXT: Table Offset: 0x70 +TEST_RES-NEXT: Number of String Entries: 1 +TEST_RES-NEXT: Number of ID Entries: 0 +TEST_RES-NEXT: Name: TESTDIALOG [ +TEST_RES-NEXT: Table Offset: 0x108 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 1033) [ +TEST_RES-NEXT: Entry Offset: 0x190 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Type: kRT_ACCELERATOR (ID 9) [ +TEST_RES-NEXT: Table Offset: 0x88 +TEST_RES-NEXT: Number of String Entries: 1 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Name: MYACCELERATORS [ +TEST_RES-NEXT: Table Offset: 0x120 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 1033) [ +TEST_RES-NEXT: Entry Offset: 0x1A0 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: Name: (ID 12) [ +TEST_RES-NEXT: Table Offset: 0x138 +TEST_RES-NEXT: Number of String Entries: 0 +TEST_RES-NEXT: Number of ID Entries: 1 +TEST_RES-NEXT: Language: (ID 1033) [ +TEST_RES-NEXT: Entry Offset: 0x1B0 +TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) +TEST_RES-NEXT: Major Version: 0 +TEST_RES-NEXT: Minor Version: 0 +TEST_RES-NEXT: Characteristics: 0 +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] +TEST_RES-NEXT: ] Index: llvm/trunk/test/tools/llvm-readobj/res-resources.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/res-resources.test +++ llvm/trunk/test/tools/llvm-readobj/res-resources.test @@ -0,0 +1,163 @@ +// Check dumping of the resources stored in .res files. +// The input was generated with the following commands, using the original Windows +// rc.exe: +// > rc /fo test_resource.res /nologo test_resource.rc + +// RUN: llvm-readobj %p/Inputs/resources/test_resource.res | FileCheck %s + +// CHECK: Resource type (int): 9 +// CHECK-NEXT: Resource name (string): MYACCELERATORS +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x30 +// CHECK-NEXT: Language ID: 1033 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 24 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 11000300 E7030000 0D004400 4C040000 |..........D.L...| +// CHECK-NEXT: 0010: 82001200 BC010000 |........| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 2 +// CHECK-NEXT: Resource name (string): CURSOR +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x30 +// CHECK-NEXT: Language ID: 1033 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 808 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 28000000 10000000 10000000 01001800 |(...............| +// CHECK-NEXT: 0010: 00000000 00030000 C40E0000 C40E0000 |................| +// CHECK-NEXT: 0020: 00000000 00000000 FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0030: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0040: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0050: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0060: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0070: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0080: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0090: FFFFFFFF FFFFFFFF FFFFFFFF FF7F7F7F |................| +// CHECK-NEXT: 00A0: 7C7C7C78 78787575 75FFFFFF FFFFFFFF ||||xxxuuu.......| +// CHECK-NEXT: 00B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 00C0: FFFFFFFF 979797FF FFFFFFFF FF838383 |................| +// CHECK-NEXT: 00D0: AAAAAADB DBDB7979 79757575 FFFFFFFF |......yyyuuu....| +// CHECK-NEXT: 00E0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 00F0: FFFFFFFF 9C9C9C98 9898FFFF FF888888 |................| +// CHECK-NEXT: 0100: DBDBDBB7 B7B77D7D 7DFFFFFF FFFFFFFF |......}}}.......| +// CHECK-NEXT: 0110: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0120: FFFFFFFF A0A0A09C 9C9C9393 93ADADAD |................| +// CHECK-NEXT: 0130: F2F2F284 84848181 81FFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0140: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0150: FFFFFFFF A4A4A4D7 D7D79D9D 9DD0D0D0 |................| +// CHECK-NEXT: 0160: EEEEEE91 91918D8D 8DFFFFFF FFFFFF81 |................| +// CHECK-NEXT: 0170: 81817E7E 7EFFFFFF FFFFFFFF FFFFFFFF |..~~~...........| +// CHECK-NEXT: 0180: FFFFFFFF A9A9A9F2 F2F2E5E5 E5E2E2E2 |................| +// CHECK-NEXT: 0190: 95959591 91918D8D 8D898989 868686FF |................| +// CHECK-NEXT: 01A0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 01B0: FFFFFFFF ADADADF2 F2F2E1E1 E1DFDFDF |................| +// CHECK-NEXT: 01C0: E7E7E7E4 E4E4BBBB BB8E8E8E FFFFFFFF |................| +// CHECK-NEXT: 01D0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 01E0: FFFFFFFF B5B5B5F2 F2F2E8E8 E8E7E7E7 |................| +// CHECK-NEXT: 01F0: EAEAEAC6 C6C69E9E 9EFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0200: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0210: FFFFFFFF B9B9B9F4 F4F4ECEC ECEDEDED |................| +// CHECK-NEXT: 0220: CBCBCBA7 A7A7FFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0230: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0240: FFFFFFFF BDBDBDF7 F7F7EFEF EFD0D0D0 |................| +// CHECK-NEXT: 0250: AFAFAFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0260: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0270: FFFFFFFF C1C1C1F7 F7F7D5D5 D5B6B6B6 |................| +// CHECK-NEXT: 0280: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0290: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 02A0: FFFFFFFF C4C4C4D9 D9D9BEBE BEFFFFFF |................| +// CHECK-NEXT: 02B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 02C0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 02D0: FFFFFFFF C8C8C8C5 C5C5FFFF FFFFFFFF |................| +// CHECK-NEXT: 02E0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 02F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0300: FFFFFFFF CBCBCBFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0310: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0320: FFFFFFFF FFFFFFFF |........| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 2 +// CHECK-NEXT: Resource name (string): OKAY +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x30 +// CHECK-NEXT: Language ID: 1033 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 808 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 28000000 10000000 10000000 01001800 |(...............| +// CHECK-NEXT: 0010: 00000000 00030000 C40E0000 C40E0000 |................| +// (...) +// CHECK-DAG: 0310: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |................| +// CHECK-NEXT: 0320: FFFFFFFF FFFFFFFF |........| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 4 +// CHECK-NEXT: Resource name (int): 14432 +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x1030 +// CHECK-NEXT: Language ID: 2052 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 46 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 00000000 00006400 79007500 00000000 |......d.y.u.....| +// CHECK-NEXT: 0010: 65007300 68006100 6C006100 00008000 |e.s.h.a.l.a.....| +// CHECK-NEXT: 0020: 66006B00 61006F00 79006100 0000 |f.k.a.o.y.a...| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 5 +// CHECK-NEXT: Resource name (string): TESTDIALOG +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x1030 +// CHECK-NEXT: Language ID: 1033 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 108 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 0000C080 00000000 02000A00 0A00C800 |................| +// CHECK-NEXT: 0010: 2C010000 00005400 65007300 74000000 |,.....T.e.s.t...| +// CHECK-NEXT: 0020: 01000250 00000000 0A000A00 E6000E00 |...P............| +// CHECK-NEXT: 0030: 0100FFFF 82004300 6F006E00 74006900 |......C.o.n.t.i.| +// CHECK-NEXT: 0040: 6E007500 65003A00 00000000 00000150 |n.u.e.:........P| +// CHECK-NEXT: 0050: 00000000 42008600 A1000D00 0200FFFF |....B...........| +// CHECK-NEXT: 0060: 80002600 4F004B00 00000000 |..&.O.K.....| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 9 +// CHECK-NEXT: Resource name (int): 12 +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x30 +// CHECK-NEXT: Language ID: 1033 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 24 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 11005800 A4000000 0D004800 2E160000 |..X.......H.....| +// CHECK-NEXT: 0010: 82001200 BC010000 |........| +// CHECK-NEXT: ) + +// CHECK-DAG: Resource type (int): 4 +// CHECK-NEXT: Resource name (string): "EAT" +// CHECK-NEXT: Data version: 0 +// CHECK-NEXT: Memory flags: 0x1030 +// CHECK-NEXT: Language ID: 3081 +// CHECK-NEXT: Version (major): 0 +// CHECK-NEXT: Version (minor): 0 +// CHECK-NEXT: Characteristics: 0 +// CHECK-NEXT: Data size: 48 +// CHECK-NEXT: Data: ( +// CHECK-NEXT: 0000: 00000000 00006400 66006900 73006800 |......d.f.i.s.h.| +// CHECK-NEXT: 0010: 00000000 65007300 61006C00 61006400 |....e.s.a.l.a.d.| +// CHECK-NEXT: 0020: 00008000 66006400 75006300 6B000000 |....f.d.u.c.k...| +// CHECK-NEXT: ) Index: llvm/trunk/test/tools/llvm-readobj/resources.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/resources.test +++ llvm/trunk/test/tools/llvm-readobj/resources.test @@ -1,143 +0,0 @@ -// Check dumping of the .rsrc section(s) -// The input was generated with the following commands, using the original Windows -// rc.exe and cvtres.exe: -// > rc /fo test_resource.res /nologo test_resource.rc -// > cvtres /machine:X86 /readonly /nologo /out:test_resource.o test_resource.res - -RUN: llvm-readobj -coff-resources -section-data %p/Inputs/zero-string-table.obj.coff-i386 \ -RUN: | FileCheck %s -check-prefix ZERO -RUN: llvm-readobj -coff-resources %p/Inputs/resources/test_resource.obj.coff \ -RUN: | FileCheck %s -check-prefix TEST_RES - -ZERO: Resources [ -ZERO-NEXT: Total Number of Resources: 1 -ZERO-NEXT: Base Table Address: 0x188 -ZERO-DAG: Number of String Entries: 0 -ZERO-NEXT: Number of ID Entries: 1 -ZERO-NEXT: Type: kRT_STRING (ID 6) [ -ZERO-NEXT: Table Offset: 0x18 -ZERO-NEXT: Number of String Entries: 0 -ZERO-NEXT: Number of ID Entries: 1 -ZERO-NEXT: Name: (ID 1) [ -ZERO-NEXT: Table Offset: 0x30 -ZERO-NEXT: Number of String Entries: 0 -ZERO-NEXT: Number of ID Entries: 1 -ZERO-NEXT: Language: (ID 1033) [ -ZERO-NEXT: Entry Offset: 0x48 -ZERO-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -ZERO-NEXT: Major Version: 0 -ZERO-NEXT: Minor Version: 0 -ZERO-NEXT: Characteristics: 0 -ZERO-NEXT: ] -ZERO-NEXT: ] -ZERO-NEXT: ] - -TEST_RES: Resources [ -TEST_RES-NEXT: Total Number of Resources: 7 -TEST_RES-NEXT: Base Table Address: 0x1C0 -TEST_RES-DAG: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 4 -TEST_RES-NEXT: Type: kRT_BITMAP (ID 2) [ -TEST_RES-NEXT: Table Offset: 0x30 -TEST_RES-NEXT: Number of String Entries: 2 -TEST_RES-NEXT: Number of ID Entries: 0 -TEST_RES-NEXT: Name: CURSOR [ -TEST_RES-NEXT: Table Offset: 0xA8 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 1033) [ -TEST_RES-NEXT: Entry Offset: 0x150 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Name: OKAY [ -TEST_RES-NEXT: Table Offset: 0xC0 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 1033) [ -TEST_RES-NEXT: Entry Offset: 0x160 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Type: kRT_MENU (ID 4) [ -TEST_RES-NEXT: Table Offset: 0x50 -TEST_RES-NEXT: Number of String Entries: 1 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Name: "EAT" [ -TEST_RES-NEXT: Table Offset: 0xD8 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 3081) [ -TEST_RES-NEXT: Entry Offset: 0x170 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Name: (ID 14432) [ -TEST_RES-NEXT: Table Offset: 0xF0 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 2052) [ -TEST_RES-NEXT: Entry Offset: 0x180 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Type: kRT_DIALOG (ID 5) [ -TEST_RES-NEXT: Table Offset: 0x70 -TEST_RES-NEXT: Number of String Entries: 1 -TEST_RES-NEXT: Number of ID Entries: 0 -TEST_RES-NEXT: Name: TESTDIALOG [ -TEST_RES-NEXT: Table Offset: 0x108 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 1033) [ -TEST_RES-NEXT: Entry Offset: 0x190 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Type: kRT_ACCELERATOR (ID 9) [ -TEST_RES-NEXT: Table Offset: 0x88 -TEST_RES-NEXT: Number of String Entries: 1 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Name: MYACCELERATORS [ -TEST_RES-NEXT: Table Offset: 0x120 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 1033) [ -TEST_RES-NEXT: Entry Offset: 0x1A0 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: Name: (ID 12) [ -TEST_RES-NEXT: Table Offset: 0x138 -TEST_RES-NEXT: Number of String Entries: 0 -TEST_RES-NEXT: Number of ID Entries: 1 -TEST_RES-NEXT: Language: (ID 1033) [ -TEST_RES-NEXT: Entry Offset: 0x1B0 -TEST_RES-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0) -TEST_RES-NEXT: Major Version: 0 -TEST_RES-NEXT: Minor Version: 0 -TEST_RES-NEXT: Characteristics: 0 -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] -TEST_RES-NEXT: ] Index: llvm/trunk/tools/llvm-readobj/CMakeLists.txt =================================================================== --- llvm/trunk/tools/llvm-readobj/CMakeLists.txt +++ llvm/trunk/tools/llvm-readobj/CMakeLists.txt @@ -19,6 +19,7 @@ ObjDumper.cpp WasmDumper.cpp Win64EHDumper.cpp + WindowsResourceDumper.cpp ) add_llvm_tool_symlink(llvm-readelf llvm-readobj) Index: llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.h =================================================================== --- llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.h +++ llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.h @@ -0,0 +1,37 @@ +//===- WindowsResourceDumper.h - Windows Resource printer -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_READOBJ_WINDOWSRESOURCEDUMPER_H +#define LLVM_TOOLS_LLVM_READOBJ_WINDOWSRESOURCEDUMPER_H + +#include "llvm/Object/WindowsResource.h" +#include "llvm/Support/ScopedPrinter.h" + +namespace llvm { +namespace object { +namespace WindowsRes { + +class Dumper { +public: + Dumper(WindowsResource *Res, ScopedPrinter &SW) : SW(SW), WinRes(Res) {} + + Error printData(); + +private: + ScopedPrinter &SW; + WindowsResource *WinRes; + + void printEntry(const ResourceEntryRef &Ref); +}; + +} // namespace WindowsRes +} // namespace object +} // namespace llvm + +#endif Index: llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.cpp +++ llvm/trunk/tools/llvm-readobj/WindowsResourceDumper.cpp @@ -0,0 +1,79 @@ +//===-- WindowsResourceDumper.cpp - Windows Resource printer --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the Windows resource (.res) dumper for llvm-readobj. +// +//===----------------------------------------------------------------------===// + +#include "WindowsResourceDumper.h" +#include "Error.h" +#include "llvm-readobj.h" +#include "llvm/Object/WindowsResource.h" +#include "llvm/Support/ScopedPrinter.h" + +namespace llvm { +namespace object { +namespace WindowsRes { + +std::string stripUTF16(const ArrayRef &UTF16Str) { + std::string Result; + Result.reserve(UTF16Str.size()); + + for (UTF16 Ch : UTF16Str) { + if (Ch <= 0xFF) + Result += Ch; + 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); + } else + SW.printNumber("Resource type (int)", Ref.getTypeID()); + + 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()); + SW.printNumber("Data size", Ref.getData().size()); + SW.printBinary("Data:", Ref.getData()); + SW.startLine() << "\n"; +} + +} // namespace WindowsRes +} // namespace object +} // namespace llvm Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp @@ -22,12 +22,14 @@ #include "llvm-readobj.h" #include "Error.h" #include "ObjDumper.h" +#include "WindowsResourceDumper.h" #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFFImportFile.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Object/WindowsResource.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DataTypes.h" @@ -522,6 +524,15 @@ } } +/// @brief Dumps \a WinRes, Windows Resource (.res) file; +static void dumpWindowsResourceFile(WindowsResource *WinRes) { + ScopedPrinter Printer{outs()}; + WindowsRes::Dumper Dumper(WinRes, Printer); + if (auto Err = Dumper.printData()) + reportError(WinRes->getFileName(), std::move(Err)); +} + + /// @brief Opens \a File and dumps it. static void dumpInput(StringRef File) { @@ -540,6 +551,8 @@ dumpObject(Obj); else if (COFFImportFile *Import = dyn_cast(&Binary)) dumpCOFFImportFile(Import); + else if (WindowsResource *WinRes = dyn_cast(&Binary)) + dumpWindowsResourceFile(WinRes); else reportError(File, readobj_error::unrecognized_file_format); }