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

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

Issue 1370843003: Remove warning pragmas in pe_image.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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 | « no previous file | no next file » | 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 {
11 namespace win { 11 namespace win {
12 12
13 // TODO(jschuh): crbug.com/167707 Make sure this code works on 64-bit.
14
15 // Structure to perform imports enumerations. 13 // Structure to perform imports enumerations.
16 struct EnumAllImportsStorage { 14 struct EnumAllImportsStorage {
17 PEImage::EnumImportsFunction callback; 15 PEImage::EnumImportsFunction callback;
18 PVOID cookie; 16 PVOID cookie;
19 }; 17 };
20 18
21 namespace { 19 namespace {
22 20
23 // PdbInfo Signature 21 // PdbInfo Signature
24 const DWORD kPdbInfoSignature = 'SDSR'; 22 const DWORD kPdbInfoSignature = 'SDSR';
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 PBYTE function = reinterpret_cast<PBYTE>(RVAToAddr(*export_entry)); 204 PBYTE function = reinterpret_cast<PBYTE>(RVAToAddr(*export_entry));
207 205
208 PBYTE exports = reinterpret_cast<PBYTE>( 206 PBYTE exports = reinterpret_cast<PBYTE>(
209 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); 207 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT));
210 DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT); 208 DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT);
211 209
212 // Check for forwarded exports as a special case. 210 // Check for forwarded exports as a special case.
213 if (exports <= function && exports + size > function) 211 if (exports <= function && exports + size > function)
214 #pragma warning(push) 212 #pragma warning(push)
215 #pragma warning(disable: 4312) 213 #pragma warning(disable: 4312)
216 // This cast generates a warning because it is 32 bit specific. 214 // Cast from 32-bit value to 64-bit pointer generates C4312 on 64-bit.
Nico 2015/12/23 20:57:01 It'd be nice if the comment also said why the warn
Will Harris 2015/12/24 05:35:51 I changed this function to return -1 on both 64-bi
217 return reinterpret_cast<FARPROC>(0xFFFFFFFF); 215 return reinterpret_cast<FARPROC>(0xFFFFFFFF);
218 #pragma warning(pop) 216 #pragma warning(pop)
219 217
220 return reinterpret_cast<FARPROC>(function); 218 return reinterpret_cast<FARPROC>(function);
221 } 219 }
222 220
223 bool PEImage::GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const { 221 bool PEImage::GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const {
224 if (NULL == ordinal) 222 if (NULL == ordinal)
225 return false; 223 return false;
226 224
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (rvas) { 447 if (rvas) {
450 module_name = 448 module_name =
451 reinterpret_cast<LPCSTR>(RVAToAddr(delay_descriptor->rvaDLLName)); 449 reinterpret_cast<LPCSTR>(RVAToAddr(delay_descriptor->rvaDLLName));
452 name_table = reinterpret_cast<PIMAGE_THUNK_DATA>( 450 name_table = reinterpret_cast<PIMAGE_THUNK_DATA>(
453 RVAToAddr(delay_descriptor->rvaINT)); 451 RVAToAddr(delay_descriptor->rvaINT));
454 iat = reinterpret_cast<PIMAGE_THUNK_DATA>( 452 iat = reinterpret_cast<PIMAGE_THUNK_DATA>(
455 RVAToAddr(delay_descriptor->rvaIAT)); 453 RVAToAddr(delay_descriptor->rvaIAT));
456 } else { 454 } else {
457 #pragma warning(push) 455 #pragma warning(push)
458 #pragma warning(disable: 4312) 456 #pragma warning(disable: 4312)
459 // These casts generate warnings because they are 32 bit specific. 457 // Casts from 32-bit values to 64-bit pointers generates C4312 on 64-bit.
Nico 2015/12/23 20:57:01 ditto
Will Harris 2015/12/24 05:35:51 Done. Actually just changed the cast instead of su
460 module_name = reinterpret_cast<LPCSTR>(delay_descriptor->rvaDLLName); 458 module_name = reinterpret_cast<LPCSTR>(delay_descriptor->rvaDLLName);
461 name_table = 459 name_table =
462 reinterpret_cast<PIMAGE_THUNK_DATA>(delay_descriptor->rvaINT); 460 reinterpret_cast<PIMAGE_THUNK_DATA>(delay_descriptor->rvaINT);
463 iat = reinterpret_cast<PIMAGE_THUNK_DATA>(delay_descriptor->rvaIAT); 461 iat = reinterpret_cast<PIMAGE_THUNK_DATA>(delay_descriptor->rvaIAT);
464 #pragma warning(pop) 462 #pragma warning(pop)
465 } 463 }
466 464
467 if (!callback(*this, delay_descriptor, module_name, name_table, iat, 465 if (!callback(*this, delay_descriptor, module_name, name_table, iat,
468 cookie)) 466 cookie))
469 return false; 467 return false;
(...skipping 16 matching lines...) Expand all
486 if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) { 484 if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) {
487 ordinal = static_cast<WORD>(IMAGE_ORDINAL32(name_table->u1.Ordinal)); 485 ordinal = static_cast<WORD>(IMAGE_ORDINAL32(name_table->u1.Ordinal));
488 } else { 486 } else {
489 PIMAGE_IMPORT_BY_NAME import; 487 PIMAGE_IMPORT_BY_NAME import;
490 bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0; 488 bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0;
491 489
492 if (rvas) { 490 if (rvas) {
493 import = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>( 491 import = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(
494 RVAToAddr(name_table->u1.ForwarderString)); 492 RVAToAddr(name_table->u1.ForwarderString));
495 } else { 493 } else {
496 #pragma warning(push)
497 #pragma warning(disable: 4312)
498 // This cast generates a warning because it is 32 bit specific.
499 import = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>( 494 import = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(
500 name_table->u1.ForwarderString); 495 name_table->u1.ForwarderString);
501 #pragma warning(pop)
502 } 496 }
503 497
504 hint = import->Hint; 498 hint = import->Hint;
505 name = reinterpret_cast<LPCSTR>(&import->Name); 499 name = reinterpret_cast<LPCSTR>(&import->Name);
506 } 500 }
507 501
508 if (!callback(*this, module_name, ordinal, name, hint, iat, cookie)) 502 if (!callback(*this, module_name, ordinal, name, hint, iat, cookie))
509 return false; 503 return false;
510 } 504 }
511 505
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 DWORD disk_offset; 573 DWORD disk_offset;
580 574
581 if (!ImageAddrToOnDiskOffset(in_memory, &disk_offset)) 575 if (!ImageAddrToOnDiskOffset(in_memory, &disk_offset))
582 return NULL; 576 return NULL;
583 577
584 return PEImage::RVAToAddr(disk_offset); 578 return PEImage::RVAToAddr(disk_offset);
585 } 579 }
586 580
587 } // namespace win 581 } // namespace win
588 } // namespace base 582 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698