Chromium Code Reviews| Index: courgette/disassembler_win32_x86.cc |
| diff --git a/courgette/disassembler_win32_x86.cc b/courgette/disassembler_win32_x86.cc |
| index 974e864033d433bd5443e5ccd70d55036efe06d0..c24aed5074b36729c08058b9619b0f74aff61652 100644 |
| --- a/courgette/disassembler_win32_x86.cc |
| +++ b/courgette/disassembler_win32_x86.cc |
| @@ -252,6 +252,9 @@ bool DisassemblerWin32X86::Disassemble(AssemblyProgram* target) { |
| ParseRel32RelocsFromSections(); |
| + PrecomputeLabels(target); |
| + RemoveUnusedRel32Locations(target); |
| + |
| if (!ParseFile(target)) |
| return false; |
| @@ -362,6 +365,25 @@ std::string DisassemblerWin32X86::SectionName(const Section* section) { |
| return name; |
| } |
| +RvaVisitor* DisassemblerWin32X86::CreateAbs32TargetRvaVisitor() { |
| + return new RvaVisitor_Abs32(abs32_locations_, *this); |
| +} |
| + |
| +RvaVisitor* DisassemblerWin32X86::CreateRel32TargetRvaVisitor() { |
| + return new RvaVisitor_Rel32(rel32_locations_, *this); |
| +} |
| + |
| +void DisassemblerWin32X86::RemoveUnusedRel32Locations( |
|
Will Harris
2016/05/04 18:02:26
hmm I wonder if a future refactor could introduce
huangs
2016/05/04 19:33:59
Yup! That's planned in go/courgette-ideas-2016 un
|
| + AssemblyProgram* program) { |
| + auto cond = [this, program](RVA rva) -> bool { |
| + RVA target_rva = rva + 4 + Read32LittleEndian(RVAToPointer(rva)); |
|
Will Harris
2016/05/04 18:02:26
can you explain this +4?
huangs
2016/05/04 19:33:59
Added comment. Also updating rel32_finder_win32_x8
|
| + return program->FindRel32Label(target_rva) == nullptr; |
| + }; |
| + rel32_locations_.erase( |
| + std::remove_if(rel32_locations_.begin(), rel32_locations_.end(), cond), |
| + rel32_locations_.end()); |
| +} |
| + |
| CheckBool DisassemblerWin32X86::ParseFile(AssemblyProgram* program) { |
| // Walk all the bytes in the file, whether or not in a section. |
| FileOffset file_offset = 0; |
| @@ -543,7 +565,9 @@ CheckBool DisassemblerWin32X86::ParseFileRegion(const Section* section, |
| DCHECK_NE(kNoRVA, target_rva); |
| // TODO(sra): target could be Label+offset. It is not clear how to guess |
| // which it might be. We assume offset==0. |
| - if (!program->EmitAbs32(program->FindOrMakeAbs32Label(target_rva))) |
| + Label* label = program->FindAbs32Label(target_rva); |
| + DCHECK(label); |
| + if (!program->EmitAbs32(label)) |
| return false; |
| p += 4; |
| continue; |
| @@ -554,7 +578,9 @@ CheckBool DisassemblerWin32X86::ParseFileRegion(const Section* section, |
| if (rel32_pos != rel32_locations_.end() && *rel32_pos == current_rva) { |
| RVA target_rva = current_rva + 4 + Read32LittleEndian(p); |
| - if (!program->EmitRel32(program->FindOrMakeRel32Label(target_rva))) |
| + Label* label = program->FindRel32Label(target_rva); |
| + DCHECK(label); |
| + if (!program->EmitRel32(label)) |
| return false; |
| p += 4; |
| continue; |