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

Side by Side Diff: courgette/disassembler_elf_32.cc

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_elf_32.h" 5 #include "courgette/disassembler_elf_32.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 found_rel32 = true; 598 found_rel32 = true;
599 if (!ParseRel32RelocsFromSection(section_header)) 599 if (!ParseRel32RelocsFromSection(section_header))
600 return false; 600 return false;
601 } 601 }
602 if (!found_rel32) 602 if (!found_rel32)
603 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?"; 603 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?";
604 604
605 return true; 605 return true;
606 } 606 }
607 607
608 bool DisassemblerElf32::QuickDetects(const uint8_t* start,
609 size_t length,
610 e_machine_values elf_em) {
611 if (length < sizeof(Elf32_Ehdr))
612 return false;
613
614 const Elf32_Ehdr* header = reinterpret_cast<const Elf32_Ehdr*>(start);
615
616 // Have magic for ELF header?
617 if (header->e_ident[0] != 0x7f || header->e_ident[1] != 'E' ||
618 header->e_ident[2] != 'L' || header->e_ident[3] != 'F')
619 return false;
620
621 if (header->e_type != ET_EXEC && header->e_type != ET_DYN)
622 return false;
623 if (header->e_machine != elf_em)
624 return false;
625 if (header->e_version != 1)
626 return false;
627 if (header->e_shentsize != sizeof(Elf32_Shdr))
628 return false;
629
630 return true;
631 }
632
608 } // namespace courgette 633 } // namespace courgette
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698