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

Side by Side Diff: courgette/disassembler_win32.cc

Issue 2583373002: [Courgette] Simple AssemblyProgram and Disassembler cleanups. (Closed)
Patch Set: Tune up header inclusion. Created 3 years, 11 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 | « courgette/disassembler_win32.h ('k') | courgette/program_detector.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "courgette/disassembler_win32.h" 5 #include "courgette/disassembler_win32.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <algorithm> 7 #include <algorithm>
11 8
12 #include "base/bind.h" 9 #include "base/bind.h"
13 #include "base/logging.h" 10 #include "base/logging.h"
14 #include "courgette/assembly_program.h" 11 #include "courgette/assembly_program.h"
15 #include "courgette/courgette.h" 12 #include "courgette/courgette.h"
16 13
17 #if COURGETTE_HISTOGRAM_TARGETS 14 #if COURGETTE_HISTOGRAM_TARGETS
18 #include <iostream> 15 #include <iostream>
19 #endif 16 #endif
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Pretend our in-memory copy is only as long as our detected length. 214 // Pretend our in-memory copy is only as long as our detected length.
218 ReduceLength(detected_length); 215 ReduceLength(detected_length);
219 216
220 if (!has_text_section()) { 217 if (!has_text_section()) {
221 return Bad("Resource-only executables are not yet supported"); 218 return Bad("Resource-only executables are not yet supported");
222 } 219 }
223 220
224 return Good(); 221 return Good();
225 } 222 }
226 223
227 bool DisassemblerWin32::Disassemble(AssemblyProgram* target) { 224 bool DisassemblerWin32::Disassemble(AssemblyProgram* program) {
228 if (!ok()) 225 if (!ok())
229 return false; 226 return false;
230 227
231 target->set_image_base(image_base());
232
233 if (!ParseAbs32Relocs()) 228 if (!ParseAbs32Relocs())
234 return false; 229 return false;
235 230
236 ParseRel32RelocsFromSections(); 231 ParseRel32RelocsFromSections();
237 232
238 PrecomputeLabels(target); 233 PrecomputeLabels(program);
239 RemoveUnusedRel32Locations(target); 234 RemoveUnusedRel32Locations(program);
240 235
241 if (!target->GenerateInstructions( 236 if (!program->GenerateInstructions(
242 base::Bind(&DisassemblerWin32::ParseFile, base::Unretained(this)))) { 237 base::Bind(&DisassemblerWin32::ParseFile, base::Unretained(this)))) {
243 return false; 238 return false;
244 } 239 }
245 240
246 target->DefaultAssignIndexes(); 241 program->DefaultAssignIndexes();
247 return true; 242 return true;
248 } 243 }
249 244
250 //////////////////////////////////////////////////////////////////////////////// 245 ////////////////////////////////////////////////////////////////////////////////
251 246
252 bool DisassemblerWin32::ParseRelocs(std::vector<RVA>* relocs) { 247 bool DisassemblerWin32::ParseRelocs(std::vector<RVA>* relocs) {
253 relocs->clear(); 248 relocs->clear();
254 249
255 size_t relocs_size = base_relocation_table_.size_; 250 size_t relocs_size = base_relocation_table_.size_;
256 if (relocs_size == 0) 251 if (relocs_size == 0)
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 directory->size_ = static_cast<uint32_t>(size); 677 directory->size_ = static_cast<uint32_t>(size);
683 return true; 678 return true;
684 } else { 679 } else {
685 directory->address_ = 0; 680 directory->address_ = 0;
686 directory->size_ = 0; 681 directory->size_ = 0;
687 return true; 682 return true;
688 } 683 }
689 } 684 }
690 685
691 } // namespace courgette 686 } // namespace courgette
OLDNEW
« no previous file with comments | « courgette/disassembler_win32.h ('k') | courgette/program_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698