Skip to content

Commit 7a6d0c1

Browse files
committed
fix(event): Correct registry string value parsing
1 parent b5de703 commit 7a6d0c1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pkg/event/param_windows.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"time"
3030
"unsafe"
3131

32+
"github.com/rabbitstack/fibratus/pkg/util/utf16"
33+
3234
"github.com/rabbitstack/fibratus/pkg/event/params"
3335
"github.com/rabbitstack/fibratus/pkg/fs"
3436
htypes "github.com/rabbitstack/fibratus/pkg/handle/types"
@@ -531,10 +533,10 @@ func (e *Event) produceParams(evt *etw.EventRecord) {
531533
e.AppendParam(params.RegPath, params.Key, filepath.Join(keyName, valueName))
532534
e.AppendEnum(params.RegValueType, valueType, key.RegistryValueTypes)
533535

534-
if len(capturedData) > 0 {
536+
if len(b) > 0 {
535537
switch valueType {
536538
case registry.SZ, registry.MULTI_SZ, registry.EXPAND_SZ:
537-
e.AppendParam(params.RegData, params.UnicodeString, string(capturedData))
539+
e.AppendParam(params.RegData, params.UnicodeString, utf16.BytesToString(b, binary.LittleEndian))
538540
case registry.BINARY:
539541
e.AppendParam(params.RegData, params.Binary, b)
540542
case registry.DWORD:

pkg/util/utf16/utf16.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package utf16
2323

2424
import (
25+
"encoding/binary"
2526
"unicode/utf8"
2627
)
2728

@@ -58,3 +59,16 @@ func Decode(p []uint16) string {
5859
}
5960
return string(s)
6061
}
62+
63+
// BytesToString converts the UTF16-encoded byte buffer to string.
64+
func BytesToString(b []byte, o binary.ByteOrder) string {
65+
utf := make([]uint16, 0, len(b)/2)
66+
for i := 0; i+1 < len(b); i += 2 {
67+
u := o.Uint16(b[i:])
68+
if u == 0 {
69+
break // stop at null terminator
70+
}
71+
utf = append(utf, u)
72+
}
73+
return Decode(utf)
74+
}

0 commit comments

Comments
 (0)