Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: base/win/pe_image.cc

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/win/object_watcher.cc ('k') | base/win/scoped_hdc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file implements PEImage, a generic class to manipulate PE files. 5 // This file implements PEImage, a generic class to manipulate PE files.
6 // This file was adapted from GreenBorder's Code. 6 // This file was adapted from GreenBorder's Code.
7 7
8 #include "base/win/pe_image.h" 8 #include "base/win/pe_image.h"
9 9
10 namespace base { 10 namespace base {
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 bool PEImage::ImageAddrToOnDiskOffset(LPVOID address, 561 bool PEImage::ImageAddrToOnDiskOffset(LPVOID address,
562 DWORD *on_disk_offset) const { 562 DWORD *on_disk_offset) const {
563 if (NULL == address) 563 if (NULL == address)
564 return false; 564 return false;
565 565
566 // Get the section that this address belongs to. 566 // Get the section that this address belongs to.
567 PIMAGE_SECTION_HEADER section_header = GetImageSectionFromAddr(address); 567 PIMAGE_SECTION_HEADER section_header = GetImageSectionFromAddr(address);
568 if (NULL == section_header) 568 if (NULL == section_header)
569 return false; 569 return false;
570 570
571 #pragma warning(suppress : 4302) // pointer truncation
572 // These casts generate warnings because they are 32 bit specific.
573 // Don't follow the virtual RVAToAddr, use the one on the base. 571 // Don't follow the virtual RVAToAddr, use the one on the base.
574 DWORD offset_within_section = reinterpret_cast<DWORD>(address) - 572 DWORD offset_within_section =
575 reinterpret_cast<DWORD>(PEImage::RVAToAddr( 573 static_cast<DWORD>(reinterpret_cast<uintptr_t>(address)) -
576 section_header->VirtualAddress)); 574 static_cast<DWORD>(reinterpret_cast<uintptr_t>(
575 PEImage::RVAToAddr(section_header->VirtualAddress)));
577 576
578 *on_disk_offset = section_header->PointerToRawData + offset_within_section; 577 *on_disk_offset = section_header->PointerToRawData + offset_within_section;
579 return true; 578 return true;
580 } 579 }
581 580
582 PVOID PEImage::RVAToAddr(DWORD rva) const { 581 PVOID PEImage::RVAToAddr(DWORD rva) const {
583 if (rva == 0) 582 if (rva == 0)
584 return NULL; 583 return NULL;
585 584
586 return reinterpret_cast<char*>(module_) + rva; 585 return reinterpret_cast<char*>(module_) + rva;
587 } 586 }
588 587
589 PVOID PEImageAsData::RVAToAddr(DWORD rva) const { 588 PVOID PEImageAsData::RVAToAddr(DWORD rva) const {
590 if (rva == 0) 589 if (rva == 0)
591 return NULL; 590 return NULL;
592 591
593 PVOID in_memory = PEImage::RVAToAddr(rva); 592 PVOID in_memory = PEImage::RVAToAddr(rva);
594 DWORD disk_offset; 593 DWORD disk_offset;
595 594
596 if (!ImageAddrToOnDiskOffset(in_memory, &disk_offset)) 595 if (!ImageAddrToOnDiskOffset(in_memory, &disk_offset))
597 return NULL; 596 return NULL;
598 597
599 return PEImage::RVAToAddr(disk_offset); 598 return PEImage::RVAToAddr(disk_offset);
600 } 599 }
601 600
602 } // namespace win 601 } // namespace win
603 } // namespace base 602 } // namespace base
OLDNEW
« no previous file with comments | « base/win/object_watcher.cc ('k') | base/win/scoped_hdc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698