1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <libelf64/elf64.h> 20 21 #include <elf.h> 22 #include <vector> 23 24 namespace android { 25 namespace elf64 { 26 27 // Class to compare ELF64 binaries (shared libraries, executables). 28 // 29 // This class provides methods to compare: 30 // 31 // - Executable header (Elf64_Ehdr) 32 // - Program headers (Elf64_Phdr) 33 // - Section contents 34 // - Section headers (Elf64_Shdr) 35 class Elf64Comparator { 36 public: 37 // Compares the ELF64 Executable Header. 38 // Returns true if they are equal, otherwise false. 39 static bool compare(const Elf64_Ehdr& ehdr1, const Elf64_Ehdr& ehdr2); 40 41 // Compares the ELF64 Program (Segment) Headers. 42 // Returns true if they are equal, otherwise false. 43 static bool compare(const std::vector<Elf64_Phdr>& phdrs1, 44 const std::vector<Elf64_Phdr>& phdrs2); 45 46 // Compares the ELF64 Section Headers. 47 // Returns true if they are equal, otherwise false. 48 static bool compare(const std::vector<Elf64_Shdr>& shdrs1, 49 const std::vector<Elf64_Shdr>& shdrs2); 50 51 // Compares the ELF64 Section content. 52 // Returns true if they are equal, otherwise false. 53 static bool compare(const std::vector<Elf64_Sc>& sections1, 54 const std::vector<Elf64_Sc>& sections2); 55 }; 56 57 } // namespace elf64 58 } // namespace android 59