ntdll_cache.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <stdint.h> 6#include <windows.h> 7 8#include "base/win/pe_image.h" 9#include "chrome_elf/ntdll_cache.h" 10 11FunctionLookupTable g_ntdll_lookup; 12 13namespace { 14 15bool EnumExportsCallback(const base::win::PEImage& image, 16 DWORD ordinal, 17 DWORD hint, 18 LPCSTR name, 19 PVOID function_addr, 20 LPCSTR forward, 21 PVOID cookie) { 22 // Our lookup only cares about named functions that are in ntdll, so skip 23 // unnamed or forwarded exports. 24 if (name && function_addr) 25 g_ntdll_lookup[std::string(name)] = function_addr; 26 27 return true; 28} 29 30} // namespace 31 32void InitCache() { 33 HMODULE ntdll_handle = ::GetModuleHandle(L"ntdll.dll"); 34 35 base::win::PEImage ntdll_image(ntdll_handle); 36 37 ntdll_image.EnumExports(EnumExportsCallback, NULL); 38} 39