diff options
-rw-r--r-- | base/file_util.h | 12 | ||||
-rw-r--r-- | base/file_util_win.cc | 26 | ||||
-rw-r--r-- | webkit/plugins/npapi/plugin_list_win.cc | 28 |
3 files changed, 63 insertions, 3 deletions
diff --git a/base/file_util.h b/base/file_util.h index d89fa71..108c998 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -506,6 +506,12 @@ class MemoryMappedFile { // ownership of |file| and close it when done. bool Initialize(base::PlatformFile file); +#if defined(OS_WIN) + // Opens an existing file and maps it as an image section. Please refer to + // the Initialize function above for additional information. + bool InitializeAsImageSection(const FilePath& file_name); +#endif // OS_WIN + const uint8* data() const { return data_; } size_t length() const { return length_; } @@ -523,10 +529,14 @@ class MemoryMappedFile { // Closes all open handles. Later we may want to make this public. void CloseHandles(); - base::PlatformFile file_; #if defined(OS_WIN) + // MapFileToMemoryInternal calls this function. It provides the ability to + // pass in flags which control the mapped section. + bool MapFileToMemoryInternalEx(int flags); + HANDLE file_mapping_; #endif + base::PlatformFile file_; uint8* data_; size_t length_; diff --git a/base/file_util_win.cc b/base/file_util_win.cc index ab1dc94..2c26a16 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -938,7 +938,31 @@ MemoryMappedFile::MemoryMappedFile() length_(INVALID_FILE_SIZE) { } +bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) { + if (IsValid()) + return false; + file_ = base::CreatePlatformFile( + file_name, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, + NULL, NULL); + + if (file_ == base::kInvalidPlatformFileValue) { + LOG(ERROR) << "Couldn't open " << file_name.value(); + return false; + } + + if (!MapFileToMemoryInternalEx(SEC_IMAGE)) { + CloseHandles(); + return false; + } + + return true; +} + bool MemoryMappedFile::MapFileToMemoryInternal() { + return MapFileToMemoryInternalEx(0); +} + +bool MemoryMappedFile::MapFileToMemoryInternalEx(int flags) { base::ThreadRestrictions::AssertIOAllowed(); if (file_ == INVALID_HANDLE_VALUE) @@ -950,7 +974,7 @@ bool MemoryMappedFile::MapFileToMemoryInternal() { // length_ value comes from GetFileSize() above. GetFileSize() returns DWORD, // therefore the cast here is safe. - file_mapping_ = ::CreateFileMapping(file_, NULL, PAGE_READONLY, + file_mapping_ = ::CreateFileMapping(file_, NULL, PAGE_READONLY | flags, 0, static_cast<DWORD>(length_), NULL); if (!file_mapping_) { // According to msdn, system error codes are only reserved up to 15999. diff --git a/webkit/plugins/npapi/plugin_list_win.cc b/webkit/plugins/npapi/plugin_list_win.cc index 22eb670..95004f8 100644 --- a/webkit/plugins/npapi/plugin_list_win.cc +++ b/webkit/plugins/npapi/plugin_list_win.cc @@ -16,7 +16,9 @@ #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/string_util.h" +#include "base/win/pe_image.h" #include "base/win/registry.h" +#include "base/win/scoped_handle.h" #include "webkit/plugins/npapi/plugin_constants_win.h" #include "webkit/plugins/npapi/plugin_lib.h" #include "webkit/plugins/plugin_switches.h" @@ -215,6 +217,18 @@ void GetJavaDirectory(std::set<FilePath>* plugin_dirs) { } } +bool IsValid32BitImage(FilePath path) { + file_util::MemoryMappedFile plugin_image; + + if (!plugin_image.InitializeAsImageSection(path)) + return false; + + base::win::PEImage image(plugin_image.data()); + + PIMAGE_NT_HEADERS nt_headers = image.GetNTHeaders(); + return (nt_headers->FileHeader.Machine == IMAGE_FILE_MACHINE_I386); +} + } // anonymous namespace void PluginList::PlatformInit() { @@ -421,7 +435,19 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, } } - return true; + HMODULE plugin_dll = NULL; + bool load_plugin = true; + + // The plugin list could contain a 64 bit plugin which we cannot load. + for (size_t i = 0; i < internal_plugins_.size(); ++i) { + if (info.path == internal_plugins_[i].info.path) + continue; + + if (!IsValid32BitImage(info.path)) + load_plugin = false; + break; + } + return load_plugin; } } // namespace npapi |