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

Function TestRemoveModule

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

Source from the content-addressed store, hash-verified

575}
576
577func TestRemoveModule(t *testing.T) {
578 hsnap := new(handle.SnapshotterMock)
579 hsnap.On("FindHandles", mock.Anything).Return([]htypes.Handle{}, nil)
580 psnap := NewSnapshotter(hsnap, &config.Config{})
581 defer psnap.Close()
582
583 pevt := &event.Event{
584 Type: event.CreateProcess,
585 Params: event.Params{
586 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid())},
587 params.ProcessParentID: {Name: params.ProcessParentID, Type: params.PID, Value: uint32(os.Getppid())},
588 params.ProcessName: {Name: params.ProcessName, Type: params.UnicodeString, Value: "spotify.exe"},
589 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`},
590 params.Exe: {Name: params.Exe, Type: params.UnicodeString, Value: `C:\Users\admin\AppData\Roaming\Spotify\Spotify.exe --parent`},
591 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}},
592 params.StartTime: {Name: params.StartTime, Type: params.Time, Value: time.Now()},
593 params.SessionID: {Name: params.SessionID, Type: params.Uint32, Value: uint32(1)},
594 params.ProcessFlags: {Name: params.ProcessFlags, Type: params.Flags, Value: uint32(0x00000010)},
595 },
596 }
597 require.NoError(t, psnap.Write(pevt))
598
599 mevt := &event.Event{
600 Type: event.LoadModule,
601 Params: event.Params{
602 params.ProcessID: {Name: params.ProcessID, Type: params.PID, Value: uint32(os.Getpid())},
603 params.ModulePath: {Name: params.ModulePath, Type: params.UnicodeString, Value: "C:\\Windows\\System32\\notepad.exe"},
604 params.ModuleBase: {Name: params.ModuleBase, Type: params.Address, Value: uint64(0xffff7656)},
605 },
606 }
607
608 require.NoError(t, psnap.AddModule(mevt))
609
610 ok, ps := psnap.Find(uint32(os.Getpid()))
611 require.True(t, ok)
612 require.NotNil(t, ps)
613 require.Len(t, ps.Modules, 1)
614 require.NoError(t, psnap.RemoveModule(uint32(os.Getpid()), va.Address(0xffff7656)))
615 require.Len(t, ps.Modules, 0)
616}
617
618func TestOverrideProcExecutable(t *testing.T) {
619 hsnap := new(handle.SnapshotterMock)

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
WriteMethod · 0.95
AddModuleMethod · 0.95
FindMethod · 0.95
RemoveModuleMethod · 0.95
AddressTypeAlias · 0.92
NewSnapshotterFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected