Skip to content

Commit 0b9f45b

Browse files
matanixmatanpeleg3
andauthored
support parsing file metadata table (#113)
Co-authored-by: Matan Peleg <matan.peleg@crowdstrike.com>
1 parent ff737f3 commit 0b9f45b

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

dotnet.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ func (pe *File) parseCLRHeaderDirectory(rva, size uint32) error {
728728
table.Content, n, err = pe.parseMetadataMethodSpecTable(offset)
729729
case GenericParamConstraint: // 0x2c
730730
table.Content, n, err = pe.parseMetadataGenericParamConstraintTable(offset)
731+
case FileMD: // 0x26
732+
table.Content, n, err = pe.parseMetadataFileTable(offset)
731733
default:
732734
pe.logger.Warnf("unhandled metadata table %d %s offset 0x%x cols %d",
733735
tableIndex, MetadataTableIndexToString(tableIndex), offset, table.CountCols)

dotnet_metadata_tables.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,13 +1201,6 @@ type AssemblyRefOSTableRow struct {
12011201
AssemblyRef uint32 `json:"assembly_ref"` // an index into the AssemblyRef table
12021202
}
12031203

1204-
// File 0x26
1205-
type FileTableRow struct {
1206-
Flags uint32 `json:"flags"` // a 4-byte bitmask of type FileAttributes, §II.23.1.6
1207-
Name uint32 `json:"name"` // an index into the String heap
1208-
HashValue uint32 `json:"hash_value"` // an index into the Blob heap
1209-
}
1210-
12111204
// ExportedType 0x27
12121205
type ExportedTypeTableRow struct {
12131206
Flags uint32 `json:"flags"` // a 4-byte bitmask of type TypeAttributes, §II.23.1.15
@@ -1435,3 +1428,40 @@ func (pe *File) parseMetadataGenericParamConstraintTable(off uint32) ([]GenericP
14351428
}
14361429
return rows, n, nil
14371430
}
1431+
1432+
// File 0x26
1433+
type FileTableRow struct {
1434+
Flags uint32 `json:"flags"` // a 4-byte bitmask of type FileAttributes, §II.23.1.6
1435+
Name uint32 `json:"name"` // an index into the String heap
1436+
HashValue uint32 `json:"hash_value"` // an index into the Blob heap
1437+
}
1438+
1439+
// File 0x26
1440+
func (pe *File) parseMetadataFileTable(off uint32) ([]FileTableRow, uint32, error) {
1441+
var err error
1442+
var indexSize uint32
1443+
var n uint32
1444+
1445+
rowCount := int(pe.CLR.MetadataTables[FileMD].CountCols)
1446+
rows := make([]FileTableRow, rowCount)
1447+
for i := 0; i < rowCount; i++ {
1448+
if rows[i].Flags, err = pe.ReadUint32(off); err != nil {
1449+
return rows, n, err
1450+
}
1451+
off += 4
1452+
n += 4
1453+
1454+
if indexSize, err = pe.readFromMetadataStream(idxString, off, &rows[i].Name); err != nil {
1455+
return rows, n, err
1456+
}
1457+
off += indexSize
1458+
n += indexSize
1459+
1460+
if indexSize, err = pe.readFromMetadataStream(idxBlob, off, &rows[i].HashValue); err != nil {
1461+
return rows, n, err
1462+
}
1463+
off += indexSize
1464+
n += indexSize
1465+
}
1466+
return rows, n, nil
1467+
}

0 commit comments

Comments
 (0)