From 9df8c2c15d4b35c08b34277df3985d7fd8a965f5 Mon Sep 17 00:00:00 2001 From: "robliao@chromium.org" Date: Wed, 4 Dec 2013 23:05:00 +0000 Subject: Revert of https://codereview.chromium.org/85403005/ Reason for revert: Breaks Chromium x64 TBR=robertshield@chromium.org,caitkp@chromium.org NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/105573003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238807 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_elf/ntdll_cache.cc | 50 ----------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 chrome_elf/ntdll_cache.cc (limited to 'chrome_elf/ntdll_cache.cc') diff --git a/chrome_elf/ntdll_cache.cc b/chrome_elf/ntdll_cache.cc deleted file mode 100644 index e04d181..0000000 --- a/chrome_elf/ntdll_cache.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "chrome_elf/ntdll_cache.h" - -FunctionLookupTable g_ntdll_lookup; - -void InitCache() { - HMODULE ntdll_handle = ::GetModuleHandle(L"ntdll.dll"); - - // To find the Export Address Table address, we start from the DOS header. - // The module handle is actually the address of the header. - IMAGE_DOS_HEADER* dos_header = - reinterpret_cast(ntdll_handle); - // The e_lfanew is an offset from the DOS header to the NT header. It should - // never be 0. - IMAGE_NT_HEADERS* nt_headers = reinterpret_cast( - ntdll_handle + dos_header->e_lfanew / sizeof(uintptr_t)); - // For modules that have an import address table, its offset from the - // DOS header is stored in the second data directory's VirtualAddress. - if (!nt_headers->OptionalHeader.DataDirectory[0].VirtualAddress) - return; - - BYTE* base_addr = reinterpret_cast(ntdll_handle); - - IMAGE_DATA_DIRECTORY* exports_data_dir = - &nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; - - IMAGE_EXPORT_DIRECTORY* exports = reinterpret_cast( - base_addr + exports_data_dir->VirtualAddress); - - WORD* ordinals = reinterpret_cast( - base_addr + exports->AddressOfNameOrdinals); - DWORD* names = reinterpret_cast( - base_addr + exports->AddressOfNames); - DWORD* funcs = reinterpret_cast( - base_addr + exports->AddressOfFunctions); - int num_entries = exports->NumberOfNames; - - for (int i = 0; i < num_entries; i++) { - char* name = reinterpret_cast(base_addr + names[i]); - WORD ord = ordinals[i]; - DWORD func = funcs[ord]; - FARPROC func_addr = reinterpret_cast(func + base_addr); - g_ntdll_lookup[std::string(name)] = func_addr; - } -} -- cgit v1.1