Skip to content

Commit 4b5f79f

Browse files
committed
refactor(filter): Rename pe. fields
To better convey the PE fields are responsible for extracting values from the PE of the current process, i.e., the one generating the event, the fields are renamed accordingly.
1 parent 0aada01 commit 4b5f79f

File tree

5 files changed

+208
-108
lines changed

5 files changed

+208
-108
lines changed

pkg/filter/accessor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ func (f *filter) narrowAccessors() {
171171
switch {
172172
case field.Name.IsKevtField(), field.Name.IsEvtField():
173173
removeEvtAccessor = false
174+
case field.Name.IsPeField():
175+
removePEAccessor = false
174176
case field.Name.IsPsField():
175177
removePsAccessor = false
176178
case field.Name.IsThreadField():
@@ -185,8 +187,6 @@ func (f *filter) narrowAccessors() {
185187
removeNetworkAccessor = false
186188
case field.Name.IsHandleField():
187189
removeHandleAccessor = false
188-
case field.Name.IsPeField():
189-
removePEAccessor = false
190190
case field.Name.IsMemField():
191191
removeMemAccessor = false
192192
case field.Name.IsDNSField():

pkg/filter/accessor_windows.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ func (pa *peAccessor) Get(f Field, e *event.Event) (params.Value, error) {
10741074
if err != nil {
10751075
return nil, err
10761076
}
1077+
e.PS.PE = p
10771078
}
10781079

10791080
// here we determine if the PE was tampered. This check
@@ -1115,54 +1116,52 @@ func (pa *peAccessor) Get(f Field, e *event.Event) (params.Value, error) {
11151116
p.VerifySignature()
11161117
}
11171118

1118-
e.PS.PE = p
1119-
11201119
switch f.Name {
1121-
case fields.PeEntrypoint:
1120+
case fields.PeEntrypoint, fields.PsPeEntrypoint:
11221121
return p.EntryPoint, nil
1123-
case fields.PeBaseAddress:
1122+
case fields.PeBaseAddress, fields.PsPeBaseAddress:
11241123
return p.ImageBase, nil
1125-
case fields.PeNumSections:
1124+
case fields.PeNumSections, fields.PsPeNumSections:
11261125
return p.NumberOfSections, nil
1127-
case fields.PeNumSymbols:
1126+
case fields.PeNumSymbols, fields.PsPeNumSymbols:
11281127
return p.NumberOfSymbols, nil
1129-
case fields.PeSymbols:
1128+
case fields.PeSymbols, fields.PsPeSymbols:
11301129
return p.Symbols, nil
1131-
case fields.PeImports:
1130+
case fields.PeImports, fields.PsPeImports:
11321131
return p.Imports, nil
1133-
case fields.PeImphash:
1132+
case fields.PeImphash, fields.PsPeImphash:
11341133
return p.Imphash, nil
1135-
case fields.PeIsDotnet:
1134+
case fields.PeIsDotnet, fields.PsPeIsDotnet:
11361135
return p.IsDotnet, nil
1137-
case fields.PeAnomalies:
1136+
case fields.PeAnomalies, fields.PsPeAnomalies:
11381137
return p.Anomalies, nil
1139-
case fields.PeIsSigned:
1138+
case fields.PeIsSigned, fields.PsSignatureExists:
11401139
return p.IsSigned, nil
1141-
case fields.PeIsTrusted:
1140+
case fields.PeIsTrusted, fields.PsSignatureIsTrusted:
11421141
return p.IsTrusted, nil
11431142
case fields.PeIsModified:
11441143
return p.IsModified, nil
1145-
case fields.PeCertIssuer:
1144+
case fields.PeCertIssuer, fields.PsSignatureIssuer:
11461145
if p.Cert == nil {
11471146
return nil, ErrPeNilCertificate
11481147
}
11491148
return p.Cert.Issuer, nil
1150-
case fields.PeCertSubject:
1149+
case fields.PeCertSubject, fields.PsSignatureSubject:
11511150
if p.Cert == nil {
11521151
return nil, ErrPeNilCertificate
11531152
}
11541153
return p.Cert.Subject, nil
1155-
case fields.PeCertSerial:
1154+
case fields.PeCertSerial, fields.PsSignatureSerial:
11561155
if p.Cert == nil {
11571156
return nil, ErrPeNilCertificate
11581157
}
11591158
return p.Cert.SerialNumber, nil
1160-
case fields.PeCertAfter:
1159+
case fields.PeCertAfter, fields.PsSignatureAfter:
11611160
if p.Cert == nil {
11621161
return nil, ErrPeNilCertificate
11631162
}
11641163
return p.Cert.NotAfter, nil
1165-
case fields.PeCertBefore:
1164+
case fields.PeCertBefore, fields.PsSignatureBefore:
11661165
if p.Cert == nil {
11671166
return nil, ErrPeNilCertificate
11681167
}
@@ -1173,23 +1172,23 @@ func (pa *peAccessor) Get(f Field, e *event.Event) (params.Value, error) {
11731172
return e.Params.GetBool(params.FileIsDriver)
11741173
case fields.PeIsExecutable:
11751174
return e.Params.GetBool(params.FileIsExecutable)
1176-
case fields.PeCompany:
1175+
case fields.PeCompany, fields.PsPeCompany:
11771176
return p.VersionResources[pe.Company], nil
1178-
case fields.PeCopyright:
1177+
case fields.PeCopyright, fields.PsPeCopyright:
11791178
return p.VersionResources[pe.LegalCopyright], nil
1180-
case fields.PeDescription:
1179+
case fields.PeDescription, fields.PsPeDescription:
11811180
return p.VersionResources[pe.FileDescription], nil
1182-
case fields.PeFileName:
1181+
case fields.PeFileName, fields.PsPeFileName:
11831182
return p.VersionResources[pe.OriginalFilename], nil
1184-
case fields.PeFileVersion:
1183+
case fields.PeFileVersion, fields.PsPeFileVersion:
11851184
return p.VersionResources[pe.FileVersion], nil
1186-
case fields.PeProduct:
1185+
case fields.PeProduct, fields.PsPeProduct:
11871186
return p.VersionResources[pe.ProductName], nil
1188-
case fields.PeProductVersion:
1187+
case fields.PeProductVersion, fields.PsPeProductVersion:
11891188
return p.VersionResources[pe.ProductVersion], nil
1190-
case fields.PeSections:
1189+
case fields.PeSections, fields.PsPeSections:
11911190
return p.Sections, nil
1192-
case fields.PeResources:
1191+
case fields.PeResources, fields.PsPeResources:
11931192
// return a single version resource indicated by the arg.
11941193
// For example, pe.resources[FileDescription] returns the
11951194
// original file description present in the resource directory

pkg/filter/accessor_windows_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
package filter
2020

2121
import (
22+
"reflect"
23+
"testing"
24+
2225
"github.com/rabbitstack/fibratus/pkg/callstack"
2326
"github.com/rabbitstack/fibratus/pkg/event"
2427
ptypes "github.com/rabbitstack/fibratus/pkg/ps/types"
2528
"github.com/stretchr/testify/assert"
2629
"github.com/stretchr/testify/require"
27-
"reflect"
28-
"testing"
2930
)
3031

3132
func TestNarrowAccessors(t *testing.T) {
@@ -42,7 +43,7 @@ func TestNarrowAccessors(t *testing.T) {
4243
1,
4344
},
4445
{
45-
New(`handle.type = 'Section' and pe.nsections > 1 and evt.name = 'CreateHandle'`, cfg),
46+
New(`handle.type = 'Section' and ps.pe.nsections > 1 and evt.name = 'CreateHandle'`, cfg),
4647
3,
4748
},
4849
{

0 commit comments

Comments
 (0)