Skip to content

Commit a83dd8b

Browse files
committed
feat(filter): Add start address symbol and module fields
Incorporate the new thread.start_address.symbol and thread.start_address.module fields to extract the symbol corresponding to the thread start address and its module respectively.
1 parent efeeafa commit a83dd8b

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

pkg/filter/accessor_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,16 @@ func (t *threadAccessor) Get(f Field, kevt *kevent.Kevent) (kparams.Value, error
596596
return kevt.Callstack.ContainsUnbacked(), nil
597597
case fields.ThreadCallstack:
598598
return kevt.Callstack, nil
599+
case fields.ThreadStartAddressSymbol:
600+
if kevt.Type != ktypes.CreateThread {
601+
return nil, nil
602+
}
603+
return kevt.GetParamAsString(kparams.StartAddressSymbol), nil
604+
case fields.ThreadStartAddressModule:
605+
if kevt.Type != ktypes.CreateThread {
606+
return nil, nil
607+
}
608+
return kevt.GetParamAsString(kparams.StartAddressModule), nil
599609
}
600610

601611
return nil, nil

pkg/filter/fields/fields_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ const (
212212
ThreadCallstackCallsiteTrailingAssembly Field = "thread.callstack.callsite_trailing_assembly"
213213
// ThreadCallstackIsUnbacked represents the field that indicates if there is an unbacked stack frame
214214
ThreadCallstackIsUnbacked Field = "thread.callstack.is_unbacked"
215+
// ThreadStartAddressSymbol represents the symbol corresponding to the thread start address
216+
ThreadStartAddressSymbol Field = "thread.start_address.symbol"
217+
// ThreadStartAddressModule represents the module corresponding to the thread start address
218+
ThreadStartAddressModule Field = "thread.start_address.module"
215219

216220
// PeNumSections represents the number of sections
217221
PeNumSections Field = "pe.nsections"
@@ -797,6 +801,8 @@ var fields = map[Field]FieldInfo{
797801
ThreadCallstackCallsiteLeadingAssembly: {ThreadCallstackCallsiteLeadingAssembly, "callsite leading assembly instructions", kparams.Slice, []string{"thread.callstack.callsite_leading_assembly in ('mov r10,rcx', 'syscall')"}, nil, nil},
798802
ThreadCallstackCallsiteTrailingAssembly: {ThreadCallstackCallsiteTrailingAssembly, "callsite trailing assembly instructions", kparams.Slice, []string{"thread.callstack.callsite_trailing_assembly in ('add esp, 0xab')"}, nil, nil},
799803
ThreadCallstackIsUnbacked: {ThreadCallstackIsUnbacked, "indicates if the callstack contains unbacked regions", kparams.Bool, []string{"thread.callstack.is_unbacked"}, nil, nil},
804+
ThreadStartAddressSymbol: {ThreadStartAddressSymbol, "thread start address symbol", kparams.UnicodeString, []string{"thread.start_address.symbol = 'LoadImage'"}, nil, nil},
805+
ThreadStartAddressModule: {ThreadStartAddressModule, "thread start address module", kparams.UnicodeString, []string{"thread.start_address.module endswith 'kernel32.dll'"}, nil, nil},
800806

801807
ImagePath: {ImagePath, "full image path", kparams.UnicodeString, []string{"image.patj = 'C:\\Windows\\System32\\advapi32.dll'"}, nil, nil},
802808
ImageName: {ImageName, "image name", kparams.UnicodeString, []string{"image.name = 'advapi32.dll'"}, nil, nil},

pkg/filter/filter_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,19 @@ func TestProcFilter(t *testing.T) {
327327

328328
func TestThreadFilter(t *testing.T) {
329329
kpars := kevent.Kparams{
330-
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: uint32(os.Getpid())},
331-
kparams.ThreadID: {Name: kparams.ThreadID, Type: kparams.TID, Value: uint32(3453)},
332-
kparams.BasePrio: {Name: kparams.BasePrio, Type: kparams.Uint8, Value: uint8(13)},
333-
kparams.StartAddress: {Name: kparams.StartAddress, Type: kparams.Address, Value: uint64(140729524944768)},
334-
kparams.TEB: {Name: kparams.TEB, Type: kparams.Address, Value: uint64(614994620416)},
335-
kparams.IOPrio: {Name: kparams.IOPrio, Type: kparams.Uint8, Value: uint8(2)},
336-
kparams.KstackBase: {Name: kparams.KstackBase, Type: kparams.Address, Value: uint64(18446677035730165760)},
337-
kparams.KstackLimit: {Name: kparams.KstackLimit, Type: kparams.Address, Value: uint64(18446677035730137088)},
338-
kparams.PagePrio: {Name: kparams.PagePrio, Type: kparams.Uint8, Value: uint8(5)},
339-
kparams.UstackBase: {Name: kparams.UstackBase, Type: kparams.Address, Value: uint64(86376448)},
340-
kparams.UstackLimit: {Name: kparams.UstackLimit, Type: kparams.Address, Value: uint64(86372352)},
330+
kparams.ProcessID: {Name: kparams.ProcessID, Type: kparams.PID, Value: uint32(os.Getpid())},
331+
kparams.ThreadID: {Name: kparams.ThreadID, Type: kparams.TID, Value: uint32(3453)},
332+
kparams.BasePrio: {Name: kparams.BasePrio, Type: kparams.Uint8, Value: uint8(13)},
333+
kparams.StartAddress: {Name: kparams.StartAddress, Type: kparams.Address, Value: uint64(140729524944768)},
334+
kparams.TEB: {Name: kparams.TEB, Type: kparams.Address, Value: uint64(614994620416)},
335+
kparams.IOPrio: {Name: kparams.IOPrio, Type: kparams.Uint8, Value: uint8(2)},
336+
kparams.KstackBase: {Name: kparams.KstackBase, Type: kparams.Address, Value: uint64(18446677035730165760)},
337+
kparams.KstackLimit: {Name: kparams.KstackLimit, Type: kparams.Address, Value: uint64(18446677035730137088)},
338+
kparams.PagePrio: {Name: kparams.PagePrio, Type: kparams.Uint8, Value: uint8(5)},
339+
kparams.UstackBase: {Name: kparams.UstackBase, Type: kparams.Address, Value: uint64(86376448)},
340+
kparams.UstackLimit: {Name: kparams.UstackLimit, Type: kparams.Address, Value: uint64(86372352)},
341+
kparams.StartAddressSymbol: {Name: kparams.StartAddressSymbol, Type: kparams.UnicodeString, Value: "LoadImage"},
342+
kparams.StartAddressModule: {Name: kparams.StartAddressModule, Type: kparams.UnicodeString, Value: "C:\\Windows\\System32\\kernel32.dll"},
341343
}
342344
kevt := &kevent.Kevent{
343345
Type: ktypes.CreateThread,
@@ -396,6 +398,8 @@ func TestThreadFilter(t *testing.T) {
396398
{`length(thread.callstack.callsite_leading_assembly) > 0`, true},
397399
{`thread.callstack.callsite_trailing_assembly matches ('*mov r10, rcx|mov eax, 0x*|syscall*')`, true},
398400
{`thread.callstack.is_unbacked`, true},
401+
{`thread.start_address.symbol = 'LoadImage'`, true},
402+
{`thread.start_address.module = 'C:\\Windows\\System32\\kernel32.dll'`, true},
399403

400404
{`foreach(thread._callstack, $frame, $frame.address = '2638e59e0a5' or $frame.address = '7ffb5c1d0396')`, true},
401405
{`foreach(thread._callstack, $frame, $frame.address = 'fffff8072ebc1f6f' or $frame.address = 'fffff8072eb8961b')`, true},

0 commit comments

Comments
 (0)