MCPcopy Index your code
hub / github.com/rabbitstack/fibratus / QueryName

Function QueryName

pkg/handle/object.go:83–136  ·  view source on GitHub ↗

QueryName gets the name of the underlying handle reference and extra metadata if it is available.

(handle windows.Handle, typ string, withTimeout bool)

Source from the content-addressed store, hash-verified

81
82// QueryName gets the name of the underlying handle reference and extra metadata if it is available.
83func QueryName(handle windows.Handle, typ string, withTimeout bool) (string, htypes.Meta, error) {
84 switch typ {
85 case File:
86 if !withTimeout {
87 return "", nil, nil
88 }
89 // delegate the name resolution to the deadlock aware handle timeout
90 name, err := GetHandleWithTimeout(handle, 500)
91 if err != nil {
92 return "", nil, err
93 }
94 name = devMapper.Convert(name)
95 fileInfo := &htypes.FileInfo{IsDirectory: sys.PathIsDirectory(name)}
96 return name, fileInfo, nil
97 case ALPCPort:
98 port, err := GetAlpcPort(handle)
99 if err != nil {
100 return "", nil, nil
101 }
102 return "", port, nil
103 case Process:
104 var size uint32 = windows.MAX_PATH
105 n := make([]uint16, size)
106 err := windows.QueryFullProcessImageName(handle, 0, &n[0], &size)
107 if err != nil {
108 return "", nil, err
109 }
110 return windows.UTF16ToString(n), nil, nil
111 case Mutant:
112 mutant, err := GetMutant(handle)
113 if err != nil {
114 return "", nil, nil
115 }
116 return "", mutant, nil
117 default:
118 name, err := QueryObjectName(handle)
119 if err != nil {
120 return "", nil, err
121 }
122 switch typ {
123 case Key:
124 rootKey, subkey := key.Format(name)
125 if rootKey == key.Invalid {
126 return name, nil, nil
127 }
128 if subkey != "" {
129 return rootKey.String() + "\\" + subkey, nil, nil
130 }
131 return rootKey.String(), nil, nil
132 default:
133 return name, nil, nil
134 }
135 }
136}

Callers 3

getHandleMethod · 0.85
TestQueryNameFileHandleFunction · 0.85
TestQueryNamedPipeFunction · 0.85

Calls 8

PathIsDirectoryFunction · 0.92
FormatFunction · 0.92
GetHandleWithTimeoutFunction · 0.85
GetAlpcPortFunction · 0.85
GetMutantFunction · 0.85
QueryObjectNameFunction · 0.85
ConvertMethod · 0.65
StringMethod · 0.65

Tested by 2

TestQueryNameFileHandleFunction · 0.68
TestQueryNamedPipeFunction · 0.68