MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / TestAddModule

Function TestAddModule

pkg/ps/snapshotter_windows_test.go:512–575  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

510}
511
512func TestAddModule(t *testing.T) {
513 hsnap := new(handle.SnapshotterMock)
514 hsnap.On("FindHandles", mock.Anything).Return([]htypes.Handle{}, nil)
515 psnap := NewSnapshotter(hsnap, &config.Config{})
516 defer psnap.Close()
517
518 evt := &event.Event{
519 Type: event.CreateProcess,
520 Params: event.Params{
521 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid())},
522 params.ProcessParentID: {Name: params.ProcessParentID, Type: params.PID, Value: uint32(os.Getppid())},
523 params.ProcessName: {Name: params.ProcessName, Type: params.UnicodeString, Value: "spotify.exe"},
524 params.Cmdline: {Name: params.Cmdline, Type: params.UnicodeString, Value: `C:\Users\admin\AppData\Roaming\Spotify\Spotify.exe --type=crashpad-handler /prefetch:7 --max-uploads=5 --max-db-size=20 --max-db-age=5 --monitor-self-annotation=ptype=crashpad-handler "--metrics-dir=C:\Users\admin\AppData\Local\Spotify\User Data" --url=https://crashdump.spotify.com:443/ --annotation=platform=win32 --annotation=product=spotify --annotation=version=1.1.4.197 --initial-client-data=0x5a4,0x5a0,0x5a8,0x59c,0x5ac,0x6edcbf60,0x6edcbf70,0x6edcbf7c`},
525 params.Exe: {Name: params.Exe, Type: params.UnicodeString, Value: `Spotify.exe`},
526 params.UserSID: {Name: params.UserSID, Type: params.WbemSID, Value: []byte{224, 8, 226, 31, 15, 167, 255, 255, 0, 0, 0, 0, 15, 167, 255, 255, 1, 1, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0}},
527 params.StartTime: {Name: params.StartTime, Type: params.Time, Value: time.Now()},
528 params.SessionID: {Name: params.SessionID, Type: params.Uint32, Value: uint32(1)},
529 params.ProcessFlags: {Name: params.ProcessFlags, Type: params.Flags, Value: uint32(0x00000010)},
530 },
531 }
532 require.NoError(t, psnap.Write(evt))
533
534 var tests = []struct {
535 name string
536 evt *event.Event
537 want bool
538 }{
539 {"add module to existing process",
540 &event.Event{
541 Type: event.LoadModule,
542 Params: event.Params{
543 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid())},
544 params.ModulePath: {Name: params.ModulePath, Type: params.UnicodeString, Value: "C:\\Users\\admin\\AppData\\Roaming\\Spotify\\Spotify.exe"},
545 },
546 },
547 true,
548 },
549 {"add module to absent process",
550 &event.Event{
551 Type: event.LoadModule,
552 Params: event.Params{
553 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid() + 1)},
554 params.ModulePath: {Name: params.ModulePath, Type: params.UnicodeString, Value: "C:\\Windows\\System32\\notepad.exe"},
555 },
556 },
557 false,
558 },
559 }
560
561 for _, tt := range tests {
562 t.Run(tt.name, func(t *testing.T) {
563 evt := tt.evt
564 exists := tt.want
565
566 require.NoError(t, psnap.AddModule(evt))
567 ok, proc := psnap.Find(evt.Params.MustGetPid())
568 require.Equal(t, exists, ok)
569 if ok {

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
WriteMethod · 0.95
AddModuleMethod · 0.95
FindMethod · 0.95
GetParamAsStringMethod · 0.95
MustGetPidMethod · 0.80
EqualMethod · 0.80
NewSnapshotterFunction · 0.70
RunMethod · 0.65
FindModuleMethod · 0.65

Tested by

no test coverage detected