Skip to content

Commit 69c334f

Browse files
authored
Merge pull request #29 from NextronSystems/feat/process-sections
feat: process sections
2 parents b8c5cc4 + f7c2558 commit 69c334f

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

thorlog/v3/process.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,48 @@ type ProcessInfo struct {
4646

4747
ProcessConnections `textlog:",expand"`
4848

49-
Memory *SparseData `json:"memory,omitempty" textlog:"memory,expand,omitempty"`
49+
Sections Sections `json:"sections,omitempty" textlog:"-"`
50+
}
51+
52+
type Sections []Section
53+
54+
// Section describes a memory range in a process's virtual memory.
55+
// This typically corresponds to a section in an executable file or library, such as .text, .data, etc.,
56+
// or a stack, heap, or similar.
57+
// In Linux terms: it corresponds to a line in /proc/<pid>/maps.
58+
type Section struct {
59+
// Name of the section. For sections from loaded libraries, this is the library's file path.
60+
// For other memory ranges, this is OS specific and may be empty.
61+
Name string `json:"name"`
62+
// Address is the start address of the section in the process's virtual memory.
63+
Address uint64 `json:"address"`
64+
// Size is the size of the section in bytes.
65+
Size uint64 `json:"size" textlog:"size"`
66+
// Offset is the offset within the mapped file or library, if this section
67+
// corresponds to a file section. If this section does not correspond to a file,
68+
// this is empty.
69+
Offset uint64 `json:"offset,omitempty"`
70+
// SparseData contains a sparse representation of the section's data.
71+
// Only the interesting parts of the section are included, typically those that have been matched.
72+
SparseData *SparseData `json:"sparse_data,omitempty"`
73+
// Permissions of the section.
74+
Permissions RwxPermissions `json:"permissions"`
75+
}
76+
77+
// RelativeTextPointer implements the jsonlog.TextReferenceResolver interface for Sections.
78+
// It resolves a reference to a Section's SparseData field to a human-readable string.
79+
func (s *Sections) RelativeTextPointer(pointee any) (string, bool) {
80+
for i := range *s {
81+
section := &(*s)[i]
82+
if pointee == &section.SparseData {
83+
if section.Name != "" {
84+
return section.Name, true
85+
} else {
86+
return fmt.Sprintf("0x%x", section.Address), true
87+
}
88+
}
89+
}
90+
return "", false
5091
}
5192

5293
type ProcessConnections struct {

thorlog/v3/sparsedata.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@ import (
99
"github.com/NextronSystems/jsonlog"
1010
)
1111

12+
// SparseData is a log object that represents a sparse data structure.
13+
// SparseData represents a selection of data from a large data block (e.g.: a file's content)
14+
// that is not fully contained in the log.
15+
//
16+
// Not all parts of the full data structure are necessarily contained in the sparse data,
17+
// typically based on how much data is relevant for the analysis.
1218
type SparseData struct {
1319
jsonlog.ObjectHeader
20+
// Elements is a list of sparse data elements that contain the actual data.
21+
// Each element has an offset within the block and the data that is present at that offset.
22+
// Elements are ordered by their offset, and are guaranteed to be non-overlapping.
1423
Elements []SparseDataElement `json:"elements" jsonschema:"nullable"`
15-
Length int64 `json:"length"`
24+
// Length is the length of the block where the sparse elements reside in.
25+
// In other words, all Elements are within an address range of [0, Length).
26+
Length int64 `json:"length"`
1627
}
1728

1829
const truncateSequence = "[...]"

0 commit comments

Comments
 (0)