MCPcopy Create free account
hub / github.com/beefytech/Beef / HDCheckHandles

Function HDCheckHandles

IDEHelper/HandleDbg.cpp:135–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135void HDCheckHandles(const std::string& traceStr)
136{
137 AutoCrit autoCrit(gHDCritSect);
138
139 CheckInit();
140
141 /*if (!(processHandle = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid)))
142 {
143 printf("Could not open PID %d! (Don't try to open a system process.)\n", pid);
144 return 1;
145 }*/
146
147 PSYSTEM_HANDLE_INFORMATION handleInfo;
148 ULONG handleInfoSize = 0x100000;
149 handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc(handleInfoSize);
150 NTSTATUS status;
151
152 /* NtQuerySystemInformation won't give us the correct buffer size,
153 so we guess by doubling the buffer size. */
154 while ((status = gNtQuerySystemInformation(
155 SystemHandleInformation,
156 handleInfo,
157 handleInfoSize,
158 NULL
159 )) == STATUS_INFO_LENGTH_MISMATCH)
160 handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2);
161
162 /* NtQuerySystemInformation stopped giving us STATUS_INFO_LENGTH_MISMATCH. */
163 if (!NT_SUCCESS(status))
164 {
165 //printf("NtQuerySystemInformation failed!\n");
166 return;
167 }
168
169 HandleMap oldHandleMap = gHDHandleMap;
170 gHDHandleMap.clear();
171
172 for (int i = 0; i < (int)handleInfo->HandleCount; i++)
173 {
174 SYSTEM_HANDLE& handle = handleInfo->Handles[i];
175 /*HANDLE dupHandle = NULL;
176 POBJECT_TYPE_INFORMATION objectTypeInfo;
177 PVOID objectNameInfo;
178 UNICODE_STRING objectName;
179 ULONG returnLength;*/
180
181 /* Check if this handle belongs to the PID the user specified. */
182 if (handle.ProcessId != GetCurrentProcessId())
183 continue;
184
185 auto itr = oldHandleMap.find(handle.Handle);
186 if (itr != oldHandleMap.end())
187 gHDHandleMap.insert(*itr);
188 else
189 {
190 HandleEntry handleEntry;
191 handleEntry.mTraceStr = traceStr;
192 handleEntry.mHandle = handle;

Callers 1

HDStartFunction · 0.85

Calls 7

CheckInitFunction · 0.85
findMethod · 0.80
mallocFunction · 0.50
reallocFunction · 0.50
freeFunction · 0.50
clearMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected