Load kernel symbols.

This commit is contained in:
Bartosz Taudul 2021-06-15 21:28:02 +02:00
parent 2d5f6a411c
commit f1bf663160
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -157,6 +157,10 @@ void InitCallstack()
LPVOID dev[4096]; LPVOID dev[4096];
if( EnumDeviceDrivers( dev, sizeof(dev), &needed ) != 0 ) if( EnumDeviceDrivers( dev, sizeof(dev), &needed ) != 0 )
{ {
char windir[MAX_PATH];
if( !GetWindowsDirectoryA( windir, sizeof( windir ) ) ) memcpy( windir, "c:\\windows", 11 );
const auto windirlen = strlen( windir );
const auto sz = needed / sizeof( LPVOID ); const auto sz = needed / sizeof( LPVOID );
s_krnlCache = (KernelDriver*)tracy_malloc( sizeof(KernelDriver) * sz ); s_krnlCache = (KernelDriver*)tracy_malloc( sizeof(KernelDriver) * sz );
int cnt = 0; int cnt = 0;
@ -171,6 +175,22 @@ void InitCallstack()
memcpy( buf+1, fn, len ); memcpy( buf+1, fn, len );
memcpy( buf+len+1, ">", 2 ); memcpy( buf+len+1, ">", 2 );
s_krnlCache[cnt++] = KernelDriver { (uint64_t)dev[i], buf }; s_krnlCache[cnt++] = KernelDriver { (uint64_t)dev[i], buf };
const auto len = GetDeviceDriverFileNameA( dev[i], fn, sizeof( fn ) );
if( len != 0 )
{
char full[MAX_PATH];
char* path = fn;
if( memcmp( fn, "\\SystemRoot\\", 12 ) == 0 )
{
memcpy( full, windir, windirlen );
strcpy( full + windirlen, fn + 11 );
path = full;
}
SymLoadModuleEx( GetCurrentProcess(), nullptr, path, nullptr, (DWORD64)dev[i], 0, nullptr, 0 );
}
} }
} }
s_krnlCacheCnt = cnt; s_krnlCacheCnt = cnt;