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

Function TestParseMem

pkg/pe/parser_test.go:105–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func TestParseMem(t *testing.T) {
106 var tests = []struct {
107 executable string
108 expectedSections int
109 }{
110 {filepath.Join(os.Getenv("windir"), "regedit.exe"), 8},
111 }
112
113 for _, tt := range tests {
114 var si windows.StartupInfo
115 var pi windows.ProcessInformation
116 argv := windows.StringToUTF16Ptr(tt.executable)
117 err := windows.CreateProcess(
118 nil,
119 argv,
120 nil,
121 nil,
122 true,
123 0,
124 nil,
125 nil,
126 &si,
127 &pi)
128 require.NoError(t, err)
129 time.Sleep(time.Millisecond * 300)
130 defer func() {
131 _ = windows.TerminateProcess(pi.Process, 0)
132 }()
133 addr, err := getModuleBaseAddress(pi.ProcessId)
134 if err != nil {
135 t.Fatalf("%s: unable to get the base address: %v", tt.executable, err)
136 }
137
138 pe, err := ParseMem(pi.ProcessId, addr, false, WithSections())
139 if err != nil {
140 t.Fatalf("%s: %v", tt.executable, err)
141 }
142 if pe == nil {
143 t.Fatalf("%s: PE metadata is nil", tt.executable)
144 }
145 if len(pe.Sections) != tt.expectedSections {
146 t.Errorf("%s: expected: %d, got %d sections", tt.executable, tt.expectedSections, len(pe.Sections))
147 }
148 }
149}
150
151func getModuleBaseAddress(pid uint32) (uintptr, error) {
152 var moduleHandles [1024]windows.Handle

Callers

nothing calls this directly

Calls 3

ParseMemFunction · 0.85
WithSectionsFunction · 0.85
getModuleBaseAddressFunction · 0.70

Tested by

no test coverage detected