@@ -467,6 +467,72 @@ func TestRemoveModule(t *testing.T) {
467467 require .Len (t , ps .Modules , 0 )
468468}
469469
470+ func TestOverrideProcExecutable (t * testing.T ) {
471+ hsnap := new (handle.SnapshotterMock )
472+ hsnap .On ("FindHandles" , mock .Anything ).Return ([]htypes.Handle {}, nil )
473+ psnap := NewSnapshotter (hsnap , & config.Config {})
474+ defer psnap .Close ()
475+
476+ evt := & kevent.Kevent {
477+ Type : ktypes .CreateProcess ,
478+ Kparams : kevent.Kparams {
479+ kparams .ProcessID : {Name : kparams .ProcessID , Type : kparams .PID , Value : uint32 (os .Getpid ())},
480+ kparams .ProcessParentID : {Name : kparams .ProcessParentID , Type : kparams .PID , Value : uint32 (os .Getppid ())},
481+ kparams .ProcessName : {Name : kparams .ProcessName , Type : kparams .UnicodeString , Value : "spotify.exe" },
482+ kparams .Cmdline : {Name : kparams .Cmdline , Type : kparams .UnicodeString , Value : `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` },
483+ kparams .Exe : {Name : kparams .Exe , Type : kparams .UnicodeString , Value : `Spotify.exe` },
484+ kparams .UserSID : {Name : kparams .UserSID , Type : kparams .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 }},
485+ kparams .StartTime : {Name : kparams .StartTime , Type : kparams .Time , Value : time .Now ()},
486+ kparams .SessionID : {Name : kparams .SessionID , Type : kparams .Uint32 , Value : uint32 (1 )},
487+ kparams .ProcessFlags : {Name : kparams .ProcessFlags , Type : kparams .Flags , Value : uint32 (0x00000010 )},
488+ },
489+ }
490+ require .NoError (t , psnap .Write (evt ))
491+
492+ var tests = []struct {
493+ expectedExe string
494+ evt * kevent.Kevent
495+ }{
496+ {`Spotify.exe` ,
497+ & kevent.Kevent {
498+ Type : ktypes .LoadImage ,
499+ Kparams : kevent.Kparams {
500+ kparams .ProcessID : {Name : kparams .ProcessID , Type : kparams .PID , Value : uint32 (os .Getpid ())},
501+ kparams .ImagePath : {Name : kparams .ImagePath , Type : kparams .UnicodeString , Value : "C:\\ Windows\\ assembly\\ NativeImages_v4.0.30319_32\\ Microsoft.Dee252aac#\\ 707569faabe821b47fa4f59ecd9eb6ea\\ Microsoft.Developer.IdentityService.ni.exe" },
502+ },
503+ },
504+ },
505+ {`Spotify.exe` ,
506+ & kevent.Kevent {
507+ Type : ktypes .LoadImage ,
508+ Kparams : kevent.Kparams {
509+ kparams .ProcessID : {Name : kparams .ProcessID , Type : kparams .PID , Value : uint32 (os .Getpid ())},
510+ kparams .ImagePath : {Name : kparams .ImagePath , Type : kparams .UnicodeString , Value : "C:\\ Windows\\ System32\\ notepad.exe" },
511+ },
512+ },
513+ },
514+ {`C:\Users\admin\AppData\Roaming\Spotify\Spotify.exe` ,
515+ & kevent.Kevent {
516+ Type : ktypes .LoadImage ,
517+ Kparams : kevent.Kparams {
518+ kparams .ProcessID : {Name : kparams .ProcessID , Type : kparams .PID , Value : uint32 (os .Getpid ())},
519+ kparams .ImagePath : {Name : kparams .ImagePath , Type : kparams .UnicodeString , Value : "C:\\ Users\\ admin\\ AppData\\ Roaming\\ Spotify\\ Spotify.exe" },
520+ },
521+ },
522+ },
523+ }
524+
525+ for _ , tt := range tests {
526+ t .Run (tt .expectedExe , func (t * testing.T ) {
527+ evt := tt .evt
528+ require .NoError (t , psnap .AddModule (evt ))
529+ ok , ps := psnap .Find (uint32 (os .Getpid ()))
530+ require .True (t , ok )
531+ assert .Equal (t , tt .expectedExe , ps .Exe )
532+ })
533+ }
534+ }
535+
470536func init () {
471537 reapPeriod = time .Millisecond * 45
472538}
0 commit comments