#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/zucchini/disassembler_elf.h"
#include <stddef.h>
#include <utility>
#include "base/logging.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "components/zucchini/abs32_utils.h"
#include "components/zucchini/algorithm.h"
#include "components/zucchini/arm_utils.h"
#include "components/zucchini/buffer_source.h"
namespace zucchini {
namespace {
constexpr uint64_t kElfImageBase = …;
constexpr size_t kSizeBound = …;
constexpr double kAArch32BitCondAlwaysDensityThreshold = …;
enum SectionJudgement : int { … };
template <class TRAITS>
int JudgeSection(size_t image_size, const typename TRAITS::Elf_Shdr* section) { … }
template <class TRAITS>
bool IsRelocSection(const typename TRAITS::Elf_Shdr& section) { … }
template <class TRAITS>
bool IsExecSection(const typename TRAITS::Elf_Shdr& section) { … }
}
constexpr Bitness Elf32Traits::kBitness;
constexpr elf::FileClass Elf32Traits::kIdentificationClass;
constexpr ExecutableType Elf32IntelTraits::kExeType;
const char Elf32IntelTraits::kExeTypeString[] = …;
constexpr elf::MachineArchitecture Elf32IntelTraits::kMachineValue;
constexpr uint32_t Elf32IntelTraits::kRelType;
constexpr ExecutableType ElfAArch32Traits::kExeType;
const char ElfAArch32Traits::kExeTypeString[] = …;
constexpr elf::MachineArchitecture ElfAArch32Traits::kMachineValue;
constexpr uint32_t ElfAArch32Traits::kRelType;
constexpr Bitness Elf64Traits::kBitness;
constexpr elf::FileClass Elf64Traits::kIdentificationClass;
constexpr ExecutableType Elf64IntelTraits::kExeType;
const char Elf64IntelTraits::kExeTypeString[] = …;
constexpr elf::MachineArchitecture Elf64IntelTraits::kMachineValue;
constexpr uint32_t Elf64IntelTraits::kRelType;
constexpr ExecutableType ElfAArch64Traits::kExeType;
const char ElfAArch64Traits::kExeTypeString[] = …;
constexpr elf::MachineArchitecture ElfAArch64Traits::kMachineValue;
constexpr uint32_t ElfAArch64Traits::kRelType;
template <class TRAITS>
bool DisassemblerElf<TRAITS>::QuickDetect(ConstBufferView image) { … }
template <class TRAITS>
DisassemblerElf<TRAITS>::~DisassemblerElf() = default;
template <class TRAITS>
ExecutableType DisassemblerElf<TRAITS>::GetExeType() const { … }
template <class TRAITS>
std::string DisassemblerElf<TRAITS>::GetExeTypeString() const { … }
template <class TRAITS>
DisassemblerElf<TRAITS>::DisassemblerElf() : … { … }
template <class TRAITS>
bool DisassemblerElf<TRAITS>::Parse(ConstBufferView image) { … }
template <class TRAITS>
std::unique_ptr<ReferenceReader> DisassemblerElf<TRAITS>::MakeReadRelocs(
offset_t lo,
offset_t hi) { … }
template <class TRAITS>
std::unique_ptr<ReferenceWriter> DisassemblerElf<TRAITS>::MakeWriteRelocs(
MutableBufferView image) { … }
template <class TRAITS>
bool DisassemblerElf<TRAITS>::ParseHeader() { … }
template <class TRAITS>
void DisassemblerElf<TRAITS>::ExtractInterestingSectionHeaders() { … }
template <class TRAITS>
void DisassemblerElf<TRAITS>::GetAbs32FromRelocSections() { … }
template <class TRAITS>
void DisassemblerElf<TRAITS>::GetRel32FromCodeSections() { … }
template <class TRAITS>
void DisassemblerElf<TRAITS>::ParseSections() { … }
template <class TRAITS>
DisassemblerElfIntel<TRAITS>::DisassemblerElfIntel() = default;
template <class TRAITS>
DisassemblerElfIntel<TRAITS>::~DisassemblerElfIntel() = default;
template <class TRAITS>
std::vector<ReferenceGroup> DisassemblerElfIntel<TRAITS>::MakeReferenceGroups()
const { … }
template <class TRAITS>
void DisassemblerElfIntel<TRAITS>::ParseExecSection(
const typename TRAITS::Elf_Shdr& section) { … }
template <class TRAITS>
void DisassemblerElfIntel<TRAITS>::PostProcessRel32() { … }
template <class TRAITS>
std::unique_ptr<ReferenceReader> DisassemblerElfIntel<TRAITS>::MakeReadAbs32(
offset_t lo,
offset_t hi) { … }
template <class TRAITS>
std::unique_ptr<ReferenceWriter> DisassemblerElfIntel<TRAITS>::MakeWriteAbs32(
MutableBufferView image) { … }
template <class TRAITS>
std::unique_ptr<ReferenceReader> DisassemblerElfIntel<TRAITS>::MakeReadRel32(
offset_t lo,
offset_t hi) { … }
template <class TRAITS>
std::unique_ptr<ReferenceWriter> DisassemblerElfIntel<TRAITS>::MakeWriteRel32(
MutableBufferView image) { … }
template class DisassemblerElfIntel<Elf32IntelTraits>;
template class DisassemblerElfIntel<Elf64IntelTraits>;
template bool DisassemblerElf<Elf32IntelTraits>::QuickDetect(
ConstBufferView image);
template bool DisassemblerElf<Elf64IntelTraits>::QuickDetect(
ConstBufferView image);
template <class Traits>
DisassemblerElfArm<Traits>::DisassemblerElfArm() = default;
template <class Traits>
DisassemblerElfArm<Traits>::~DisassemblerElfArm() = default;
template <class Traits>
bool DisassemblerElfArm<Traits>::IsTargetOffsetInExecSection(
offset_t offset) const { … }
template <class Traits>
void DisassemblerElfArm<Traits>::ParseExecSection(
const typename Traits::Elf_Shdr& section) { … }
template <class Traits>
void DisassemblerElfArm<Traits>::PostProcessRel32() { … }
template <class Traits>
std::unique_ptr<ReferenceReader> DisassemblerElfArm<Traits>::MakeReadAbs32(
offset_t lo,
offset_t hi) { … }
template <class Traits>
std::unique_ptr<ReferenceWriter> DisassemblerElfArm<Traits>::MakeWriteAbs32(
MutableBufferView image) { … }
template <class TRAITS>
template <class ADDR_TRAITS>
std::unique_ptr<ReferenceReader> DisassemblerElfArm<TRAITS>::MakeReadRel32(
offset_t lower,
offset_t upper) { … }
template <class TRAITS>
template <class ADDR_TRAITS>
std::unique_ptr<ReferenceWriter> DisassemblerElfArm<TRAITS>::MakeWriteRel32(
MutableBufferView image) { … }
template <class TRAITS>
template <class ADDR_TRAITS>
std::unique_ptr<ReferenceMixer> DisassemblerElfArm<TRAITS>::MakeMixRel32(
ConstBufferView src_image,
ConstBufferView dst_image) { … }
DisassemblerElfAArch32::DisassemblerElfAArch32() = default;
DisassemblerElfAArch32::~DisassemblerElfAArch32() = default;
std::vector<ReferenceGroup> DisassemblerElfAArch32::MakeReferenceGroups()
const { … }
std::unique_ptr<DisassemblerElfAArch32::Traits::Rel32FinderUse>
DisassemblerElfAArch32::MakeRel32Finder(
const typename Traits::Elf_Shdr& section) { … }
bool DisassemblerElfAArch32::IsExecSectionThumb2(
const typename Traits::Elf_Shdr& section) const { … }
DisassemblerElfAArch64::DisassemblerElfAArch64() = default;
DisassemblerElfAArch64::~DisassemblerElfAArch64() = default;
std::vector<ReferenceGroup> DisassemblerElfAArch64::MakeReferenceGroups()
const { … }
std::unique_ptr<DisassemblerElfAArch64::Traits::Rel32FinderUse>
DisassemblerElfAArch64::MakeRel32Finder(
const typename Traits::Elf_Shdr& section) { … }
template class DisassemblerElfArm<ElfAArch32Traits>;
template class DisassemblerElfArm<ElfAArch64Traits>;
template bool DisassemblerElf<ElfAArch32Traits>::QuickDetect(
ConstBufferView image);
template bool DisassemblerElf<ElfAArch64Traits>::QuickDetect(
ConstBufferView image);
}