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

Function FormatMessage

pkg/util/ntstatus/status.go:43–64  ·  view source on GitHub ↗

FormatMessage resolved the NT status code to an error message. The cache of resolved messages is kept to speed up status code translation and alleviate the pressure on API call invocations.

(status uint32)

Source from the content-addressed store, hash-verified

41// messages is kept to speed up status code translation and alleviate the pressure on
42// API call invocations.
43func FormatMessage(status uint32) string {
44 if isSuccess(status) {
45 return Success
46 }
47 mux.Lock()
48 defer mux.Unlock()
49 if s, ok := statusCache[status]; ok {
50 return s
51 }
52 var flags uint32 = windows.FORMAT_MESSAGE_FROM_SYSTEM
53 b := make([]uint16, 300)
54 msgID := sys.RtlNtStatusToDosError(status)
55 n, err := windows.FormatMessage(flags, 0, msgID, 0, b, nil)
56 if err != nil {
57 return "Unknown"
58 }
59 // trim terminating \r and \n
60 for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
61 }
62 statusCache[status] = string(utf16.Decode(b[:n-1]))
63 return statusCache[status]
64}

Callers 1

StringMethod · 0.92

Calls 4

RtlNtStatusToDosErrorFunction · 0.92
isSuccessFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected