[COFF] Add a ResourceSectionRef method for getting the data entry, print it in llvm-readobj

Differential Revision: https://reviews.llvm.org/D66819

llvm-svn: 370311
This commit is contained in:
Martin Storsjo 2019-08-29 09:00:14 +00:00
parent edb6ab9ba6
commit 7ba81d95d5
6 changed files with 197 additions and 0 deletions

View File

@ -1208,6 +1208,8 @@ public:
getEntryNameString(const coff_resource_dir_entry &Entry);
Expected<const coff_resource_dir_table &>
getEntrySubDir(const coff_resource_dir_entry &Entry);
Expected<const coff_resource_data_entry &>
getEntryData(const coff_resource_dir_entry &Entry);
Expected<const coff_resource_dir_table &> getBaseTable();
Expected<const coff_resource_dir_entry &>
getTableEntry(const coff_resource_dir_table &Table, uint32_t Index);
@ -1218,6 +1220,8 @@ private:
Expected<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
Expected<const coff_resource_dir_entry &>
getTableEntryAtOffset(uint32_t Offset);
Expected<const coff_resource_data_entry &>
getDataEntryAtOffset(uint32_t Offset);
Expected<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
};

View File

@ -1707,11 +1707,29 @@ ResourceSectionRef::getTableEntryAtOffset(uint32_t Offset) {
return *Entry;
}
Expected<const coff_resource_data_entry &>
ResourceSectionRef::getDataEntryAtOffset(uint32_t Offset) {
const coff_resource_data_entry *Entry = nullptr;
BinaryStreamReader Reader(BBS);
Reader.setOffset(Offset);
RETURN_IF_ERROR(Reader.readObject(Entry));
assert(Entry != nullptr);
return *Entry;
}
Expected<const coff_resource_dir_table &>
ResourceSectionRef::getEntrySubDir(const coff_resource_dir_entry &Entry) {
assert(Entry.Offset.isSubDir());
return getTableAtOffset(Entry.Offset.value());
}
Expected<const coff_resource_data_entry &>
ResourceSectionRef::getEntryData(const coff_resource_dir_entry &Entry) {
assert(!Entry.Offset.isSubDir());
return getDataEntryAtOffset(Entry.Offset.value());
}
Expected<const coff_resource_dir_table &> ResourceSectionRef::getBaseTable() {
return getTableAtOffset(0);
}

View File

@ -29,6 +29,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 57
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -46,6 +52,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 808
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: OKAY [
@ -58,6 +70,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 808
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -75,6 +93,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 48
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: (ID 14432) [
@ -87,6 +111,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 46
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -104,6 +134,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 108
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -121,6 +157,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 24
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Language: (ID 2052) [
CHECK-NEXT: Entry Offset: 0x248
@ -128,6 +170,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 24
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: (ID 12) [
@ -140,6 +188,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 24
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -157,6 +211,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 54
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Language: (ID 2052) [
CHECK-NEXT: Entry Offset: 0x278
@ -164,6 +224,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 67
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Language: (ID 4103) [
CHECK-NEXT: Entry Offset: 0x288
@ -171,6 +237,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 66
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]

View File

@ -28,6 +28,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 57
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -45,6 +51,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 808
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: OKAY [
@ -57,6 +69,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 808
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -74,6 +92,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 48
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: (ID 14432) [
@ -86,6 +110,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 46
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -103,6 +133,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 108
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
@ -120,6 +156,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 24
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: Name: (ID 12) [
@ -132,6 +174,12 @@ CHECK-NEXT: Time/Date Stamp: 1970-01-01 00:00:00 (0x0)
CHECK-NEXT: Major Version: 0
CHECK-NEXT: Minor Version: 0
CHECK-NEXT: Characteristics: 0
CHECK-NEXT: Data [
CHECK-NEXT: DataRVA: 0x0
CHECK-NEXT: DataSize: 24
CHECK-NEXT: Codepage: 0
CHECK-NEXT: Reserved: 0
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]
CHECK-NEXT: ]

View File

@ -28,6 +28,12 @@ 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: Data [
ZERO-NEXT: DataRVA: 0x0
ZERO-NEXT: DataSize: 42
ZERO-NEXT: Codepage: 0
ZERO-NEXT: Reserved: 0
ZERO-NEXT: ]
ZERO-NEXT: ]
ZERO-NEXT: ]
ZERO-NEXT: ]
@ -51,6 +57,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 808
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: Name: OKAY [
@ -63,6 +75,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 808
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
@ -80,6 +98,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 48
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: Name: (ID 14432) [
@ -92,6 +116,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 46
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
@ -109,6 +139,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 108
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
@ -126,6 +162,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 24
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: Name: (ID 12) [
@ -138,6 +180,12 @@ 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: Data [
TEST_RES-NEXT: DataRVA: 0x0
TEST_RES-NEXT: DataSize: 24
TEST_RES-NEXT: Codepage: 0
TEST_RES-NEXT: Reserved: 0
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]
TEST_RES-NEXT: ]

View File

@ -1864,6 +1864,13 @@ void COFFDumper::printResourceDirectoryTable(
W.printNumber("Major Version", Table.MajorVersion);
W.printNumber("Minor Version", Table.MinorVersion);
W.printNumber("Characteristics", Table.Characteristics);
ListScope DataScope(W, "Data");
auto &DataEntry =
unwrapOrError(Obj->getFileName(), RSF.getEntryData(Entry));
W.printHex("DataRVA", DataEntry.DataRVA);
W.printNumber("DataSize", DataEntry.DataSize);
W.printNumber("Codepage", DataEntry.Codepage);
W.printNumber("Reserved", DataEntry.Reserved);
}
}
}