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

Function BfAllocHook

IDEHelper/DebugManager.cpp:231–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229static bool gInsideAlloc = false;
230static int gLastReqId = 0;
231static int BfAllocHook(int nAllocType, void *pvData,
232 size_t nSize, int nBlockUse, long lRequest,
233 const unsigned char * szFileName, int nLine)
234{
235#ifdef CAPTURE_ALLOC_SOURCES
236 if (gInsideAlloc)
237 return TRUE;
238
239 gInsideAlloc = true;
240
241 intptr stackTrace[20];
242 int traceCount = (int)RtlCaptureStackBackTrace(1, 20, (void**)&stackTrace, 0);
243
244 /*intptr ebpVal;
245 __asm
246 {
247 mov ebpVal, ebp
248 }*/
249
250 //intptr ebp = ebpVal;
251 //intptr eip = 0;
252
253 static HANDLE hProcess = 0;
254 if (hProcess == NULL)
255 {
256 hProcess = GetCurrentProcess();
257 BOOL worked = SymInitialize(hProcess, NULL, TRUE);
258 }
259
260 if (nAllocType == _HOOK_ALLOC)
261 {
262 for (int i = 0; i < traceCount; i++)
263 {
264 /*__try
265 {
266 ebp = *((intptr*)ebp + 0);
267 if (ebp < 0x100000)
268 break;
269 eip = *((intptr*)ebp + 1);
270 }
271 __except (EXCEPTION_EXECUTE_HANDLER)
272 {
273 break;
274 }*/
275
276 intptr curAddr = stackTrace[i];
277
278 const char* name = "?";
279
280 int hashVal = (curAddr & 0x7FFFFFFF) % CAPTURE_ALLOC_POOL_SIZE;
281 if (gHashCaptureAllocSize[hashVal] == NULL)
282 {
283 //static HPROCESS hProc = GEtProcessH
284 char symData[4096];
285 DWORD64 disp = 0;
286 SYMBOL_INFO* symInfo = (SYMBOL_INFO*)&symData;
287 memset(symInfo, 0, sizeof(SYMBOL_INFO));
288 symInfo->SizeOfStruct = sizeof(SYMBOL_INFO);

Callers

nothing calls this directly

Calls 3

strdupFunction · 0.85
ReallocEntryFunction · 0.85
RemoveAllocEntryFunction · 0.85

Tested by

no test coverage detected