Skip to content

Commit 6957a63

Browse files
committed
chore(kcap): Persist process flags in capture
The process state marshaller stores the new IsWow64, IsPackaged, and IsProtected fields into the binary blob.
1 parent 015e7f0 commit 6957a63

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

pkg/kcap/version/version_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
ProcessSecV2
3636
// ProcessSecV3 is the v3 of the process section
3737
ProcessSecV3
38+
// ProcessSecV4 is the v4 of the process section
39+
ProcessSecV4
3840
)
3941

4042
const (

pkg/kevent/marshaller_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ func (e *Kevent) MarshalRaw() []byte {
175175
// write process state
176176
if e.PS != nil && (e.IsCreateProcess() || e.IsProcessRundown()) {
177177
buf := e.PS.Marshal()
178-
sec := section.New(section.Process, kcapver.ProcessSecV3, 0, uint32(len(buf)))
178+
sec := section.New(section.Process, kcapver.ProcessSecV4, 0, uint32(len(buf)))
179179
b = append(b, sec[:]...)
180180
b = append(b, buf...)
181181
} else {
182-
sec := section.New(section.Process, kcapver.ProcessSecV3, 0, 0)
182+
sec := section.New(section.Process, kcapver.ProcessSecV4, 0, 0)
183183
b = append(b, sec[:]...)
184184
}
185185

pkg/ps/types/marshaller_windows.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
kcapver "github.com/rabbitstack/fibratus/pkg/kcap/version"
2626
"github.com/rabbitstack/fibratus/pkg/pe"
2727
"github.com/rabbitstack/fibratus/pkg/util/bytes"
28+
"github.com/rabbitstack/fibratus/pkg/util/convert"
2829
"time"
2930
"unsafe"
3031
)
@@ -109,6 +110,11 @@ func (ps *PS) Marshal() []byte {
109110
b = append(b, bytes.WriteUint16(uint16(len(ps.Domain)))...)
110111
b = append(b, ps.Domain...)
111112

113+
// write process flags
114+
b = append(b, convert.Btoi(ps.IsWOW64))
115+
b = append(b, convert.Btoi(ps.IsPackaged))
116+
b = append(b, convert.Btoi(ps.IsProtected))
117+
112118
return b
113119
}
114120

@@ -249,8 +255,19 @@ readpe:
249255
// read domain
250256
l = bytes.ReadUint16(b[idx+offset:])
251257
buf = b[:]
258+
idx += 2
259+
offset += uint32(l)
252260
ps.Domain = string((*[1<<30 - 1]byte)(unsafe.Pointer(&buf[0]))[:l:l])
253261
}
262+
if psec.Version() >= kcapver.ProcessSecV4 {
263+
// process flags
264+
ps.IsWOW64 = convert.Itob(b[idx+offset])
265+
idx++
266+
ps.IsPackaged = convert.Itob(b[idx+offset])
267+
idx++
268+
ps.IsProtected = convert.Itob(b[idx+offset])
269+
}
270+
254271
return nil
255272
}
256273

@@ -285,8 +302,18 @@ readpe:
285302
// read domain
286303
l = bytes.ReadUint16(b[idx+offset:])
287304
buf = b[:]
305+
idx += 2
306+
offset += uint32(l)
288307
ps.Domain = string((*[1<<30 - 1]byte)(unsafe.Pointer(&buf[0]))[:l:l])
289308
}
309+
if psec.Version() >= kcapver.ProcessSecV4 {
310+
// process flags
311+
ps.IsWOW64 = convert.Itob(b[idx+offset])
312+
idx++
313+
ps.IsPackaged = convert.Itob(b[idx+offset])
314+
idx++
315+
ps.IsProtected = convert.Itob(b[idx+offset])
316+
}
290317

291318
return nil
292319
}

pkg/ps/types/marshaller_windows_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ func TestPSMarshaler(t *testing.T) {
7777
Object: 357488883434455544,
7878
},
7979
},
80+
IsProtected: true,
81+
IsWOW64: true,
82+
IsPackaged: false,
8083
}
8184

8285
b := ps.Marshal()
83-
sec := section.New(section.Process, kcapver.ProcessSecV3, 0, 0)
86+
sec := section.New(section.Process, kcapver.ProcessSecV4, 0, 0)
8487
clone, err := NewFromKcap(b, sec)
8588
require.NoError(t, err)
8689

@@ -96,6 +99,9 @@ func TestPSMarshaler(t *testing.T) {
9699
assert.Equal(t, []string{"-contentproc", `--channel="6304.3.1055809391\1014207667`, "-childID", "1", "-isForBrowser", "-prefsHandle", "2584", "-prefMapHandle", "2580", "-prefsLen", "70", "-prefMapSize", "216993", "-parentBuildID"}, clone.Args)
97100
assert.Equal(t, uint32(4), clone.SessionID)
98101
assert.Equal(t, map[string]string{"ProgramData": "C:\\ProgramData", "COMPUTRENAME": "archrabbit"}, clone.Envs)
102+
assert.True(t, clone.IsProtected)
103+
assert.True(t, clone.IsWOW64)
104+
assert.False(t, clone.IsPackaged)
99105

100106
require.Len(t, clone.Handles, 3)
101107

0 commit comments

Comments
 (0)