diff options
36 files changed, 144 insertions, 144 deletions
diff --git a/abs32_utils.cc b/abs32_utils.cc index 5d3d6ea..ad1c85e 100644 --- a/abs32_utils.cc +++ b/abs32_utils.cc @@ -110,7 +110,7 @@ Abs32RvaExtractorWin32::Abs32RvaExtractorWin32(Abs32RvaExtractorWin32&&) = Abs32RvaExtractorWin32::~Abs32RvaExtractorWin32() = default; -base::Optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { +absl::optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { while (cur_abs32_ < end_abs32_) { offset_t location = *(cur_abs32_++); if (!addr_.Read(location, image_)) @@ -120,7 +120,7 @@ base::Optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { continue; return Unit{location, target_rva}; } - return base::nullopt; + return absl::nullopt; } /******** Abs32ReaderWin32 ********/ @@ -132,7 +132,7 @@ Abs32ReaderWin32::Abs32ReaderWin32(Abs32RvaExtractorWin32&& abs32_rva_extractor, Abs32ReaderWin32::~Abs32ReaderWin32() = default; -base::Optional<Reference> Abs32ReaderWin32::GetNext() { +absl::optional<Reference> Abs32ReaderWin32::GetNext() { for (auto unit = abs32_rva_extractor_.GetNext(); unit.has_value(); unit = abs32_rva_extractor_.GetNext()) { offset_t location = unit->location; @@ -140,7 +140,7 @@ base::Optional<Reference> Abs32ReaderWin32::GetNext() { if (unsafe_target != kInvalidOffset) return Reference{location, unsafe_target}; } - return base::nullopt; + return absl::nullopt; } /******** Abs32WriterWin32 ********/ diff --git a/abs32_utils.h b/abs32_utils.h index 5bc9cf2..f13f562 100644 --- a/abs32_utils.h +++ b/abs32_utils.h @@ -11,10 +11,10 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -78,8 +78,8 @@ class Abs32RvaExtractorWin32 { ~Abs32RvaExtractorWin32(); // Visits given abs32 locations, rejects invalid locations and non-existent - // RVAs, and returns reference as Unit, or base::nullopt on completion. - base::Optional<Unit> GetNext(); + // RVAs, and returns reference as Unit, or absl::nullopt on completion. + absl::optional<Unit> GetNext(); private: ConstBufferView image_; @@ -97,7 +97,7 @@ class Abs32ReaderWin32 : public ReferenceReader { ~Abs32ReaderWin32() override; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: Abs32RvaExtractorWin32 abs32_rva_extractor_; diff --git a/abs32_utils_unittest.cc b/abs32_utils_unittest.cc index 77a2599..ddbb685 100644 --- a/abs32_utils_unittest.cc +++ b/abs32_utils_unittest.cc @@ -287,7 +287,7 @@ TEST(Abs32UtilsTest, Win32Read32) { Abs32ReaderWin32 reader(std::move(extractor), translator); // Loop over |expected_ref| to check element-by-element. - base::Optional<Reference> ref; + absl::optional<Reference> ref; for (const auto& expected_ref : test_case.expected_refs) { ref = reader.GetNext(); EXPECT_TRUE(ref.has_value()); @@ -322,7 +322,7 @@ TEST(Abs32UtilsTest, Win32Read64) { Abs32ReaderWin32 reader(std::move(extractor), translator); std::vector<Reference> refs; - base::Optional<Reference> ref; + absl::optional<Reference> ref; for (ref = reader.GetNext(); ref.has_value(); ref = reader.GetNext()) refs.push_back(ref.value()); EXPECT_EQ(expected_refs, refs); diff --git a/disassembler.cc b/disassembler.cc index 0411791..4a210ac 100644 --- a/disassembler.cc +++ b/disassembler.cc @@ -10,8 +10,8 @@ namespace zucchini { /******** EmptyReferenceReader ********/ -base::Optional<Reference> EmptyReferenceReader::GetNext() { - return base::nullopt; +absl::optional<Reference> EmptyReferenceReader::GetNext() { + return absl::nullopt; } /******** EmptyReferenceWriter ********/ diff --git a/disassembler.h b/disassembler.h index 52c69a4..8fd5a3a 100644 --- a/disassembler.h +++ b/disassembler.h @@ -20,7 +20,7 @@ namespace zucchini { // A vacuous ReferenceReader that produces no references. class EmptyReferenceReader : public ReferenceReader { public: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; }; // A vacuous EmptyReferenceWriter that does not write. diff --git a/disassembler_dex.cc b/disassembler_dex.cc index 373d645..256ccde 100644 --- a/disassembler_dex.cc +++ b/disassembler_dex.cc @@ -18,11 +18,11 @@ #include "base/callback.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "base/strings/stringprintf.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/io_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -363,13 +363,13 @@ class InstructionReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (true) { while (parser_.ReadNext()) { const auto& v = parser_.value(); DCHECK_NE(v.instr, nullptr); if (v.instr_offset >= hi_) - return base::nullopt; + return absl::nullopt; const offset_t location = filter_.Run(v); if (location == kInvalidOffset || location < lo_) continue; @@ -377,7 +377,7 @@ class InstructionReferenceReader : public ReferenceReader { // assumption |hi_| and |lo_| do not straddle the body of a Reference. // So |reference_width| is unneeded. if (location >= hi_) - return base::nullopt; + return absl::nullopt; offset_t target = mapper_.Run(location); if (target != kInvalidOffset) return Reference{location, target}; @@ -386,7 +386,7 @@ class InstructionReferenceReader : public ReferenceReader { } ++cur_it_; if (cur_it_ == end_it_) - return base::nullopt; + return absl::nullopt; parser_ = InstructionParser(image_, *cur_it_); } } @@ -447,7 +447,7 @@ class ItemReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_idx_ < num_items_) { const offset_t item_offset = OffsetOfIndex(cur_idx_); const offset_t location = item_offset + rel_location_; @@ -478,7 +478,7 @@ class ItemReferenceReader : public ReferenceReader { ++cur_idx_; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: @@ -631,7 +631,7 @@ class CachedItemListReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_it_ < end_it_) { const offset_t location = *cur_it_ + rel_location_; if (location >= hi_) // Check is simplified by atomicity assumption. @@ -649,7 +649,7 @@ class CachedItemListReferenceReader : public ReferenceReader { continue; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: diff --git a/disassembler_ztf.cc b/disassembler_ztf.cc index c54a7b0..f822d8b 100644 --- a/disassembler_ztf.cc +++ b/disassembler_ztf.cc @@ -290,7 +290,7 @@ class ZtfReferenceReader : public ReferenceReader { // Walks |offset_| from |lo| to |hi_| running |parser_|. If any matches are // found they are returned. - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { T line_col; for (; offset_ < hi_; ++offset_) { if (!parser_.MatchAtOffset(offset_, &line_col)) @@ -304,7 +304,7 @@ class ZtfReferenceReader : public ReferenceReader { offset_ += config_.Width(line_col); return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: @@ -456,12 +456,12 @@ offset_t ZtfTranslator::LineColToOffset(ztf::LineCol lc) const { return target; } -base::Optional<ztf::LineCol> ZtfTranslator::OffsetToLineCol( +absl::optional<ztf::LineCol> ZtfTranslator::OffsetToLineCol( offset_t offset) const { DCHECK(!line_starts_.empty()); // Don't place a target outside the image. if (offset >= line_starts_.back()) - return base::nullopt; + return absl::nullopt; auto it = SearchForRange(offset); ztf::LineCol lc; lc.line = std::distance(line_starts_.cbegin(), it) + 1; diff --git a/disassembler_ztf.h b/disassembler_ztf.h index 0719093..adbead5 100644 --- a/disassembler_ztf.h +++ b/disassembler_ztf.h @@ -13,10 +13,10 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/disassembler.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/type_ztf.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -97,8 +97,8 @@ class ZtfTranslator { offset_t LineColToOffset(ztf::LineCol line_col) const; // Returns the ztf::LineCol for an |offset| if it is valid. Otherwise returns - // base::nullopt. - base::Optional<ztf::LineCol> OffsetToLineCol(offset_t offset) const; + // absl::nullopt. + absl::optional<ztf::LineCol> OffsetToLineCol(offset_t offset) const; private: // Returns an iterator to the range containing |offset|. Which is represented diff --git a/element_detection.cc b/element_detection.cc index bec16be..8682c78 100644 --- a/element_detection.cc +++ b/element_detection.cc @@ -118,11 +118,11 @@ std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image, } } -base::Optional<Element> DetectElementFromDisassembler(ConstBufferView image) { +absl::optional<Element> DetectElementFromDisassembler(ConstBufferView image) { std::unique_ptr<Disassembler> disasm = MakeDisassemblerWithoutFallback(image); if (disasm) return Element({0, disasm->size()}, disasm->GetExeType()); - return base::nullopt; + return absl::nullopt; } /******** ProgramScanner ********/ @@ -132,18 +132,18 @@ ElementFinder::ElementFinder(ConstBufferView image, ElementDetector&& detector) ElementFinder::~ElementFinder() = default; -base::Optional<Element> ElementFinder::GetNext() { +absl::optional<Element> ElementFinder::GetNext() { for (; pos_ < image_.size(); ++pos_) { ConstBufferView test_image = ConstBufferView::FromRange(image_.begin() + pos_, image_.end()); - base::Optional<Element> element = detector_.Run(test_image); + absl::optional<Element> element = detector_.Run(test_image); if (element) { element->offset += pos_; pos_ = element->EndOffset(); return element; } } - return base::nullopt; + return absl::nullopt; } } // namespace zucchini diff --git a/element_detection.h b/element_detection.h index f90c033..d3dcb47 100644 --- a/element_detection.h +++ b/element_detection.h @@ -11,9 +11,9 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -32,10 +32,10 @@ std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image, // Attempts to detect an element associated with |image| and returns it, or // returns nullopt if no element is detected. using ElementDetector = - base::RepeatingCallback<base::Optional<Element>(ConstBufferView image)>; + base::RepeatingCallback<absl::optional<Element>(ConstBufferView image)>; // Implementation of ElementDetector using disassemblers. -base::Optional<Element> DetectElementFromDisassembler(ConstBufferView image); +absl::optional<Element> DetectElementFromDisassembler(ConstBufferView image); // A class to scan through an image and iteratively detect elements. class ElementFinder { @@ -45,7 +45,7 @@ class ElementFinder { // Scans for the next executable using |detector|. Returns the next element // found, or nullopt if no more element can be found. - base::Optional<Element> GetNext(); + absl::optional<Element> GetNext(); private: ConstBufferView image_; diff --git a/element_detection_unittest.cc b/element_detection_unittest.cc index 769c839..319a88a 100644 --- a/element_detection_unittest.cc +++ b/element_detection_unittest.cc @@ -45,7 +45,7 @@ class ElementDetectionTest : public ::testing::Test { image, base::BindRepeating( [](ExeTypeMap exe_map, ConstBufferView image, - ConstBufferView region) -> base::Optional<Element> { + ConstBufferView region) -> absl::optional<Element> { EXPECT_GE(region.begin(), image.begin()); EXPECT_LE(region.end(), image.end()); EXPECT_GE(region.size(), 0U); @@ -56,7 +56,7 @@ class ElementDetectionTest : public ::testing::Test { ++length; return Element{{0, length}, exe_map[region[0]]}; } - return base::nullopt; + return absl::nullopt; }, exe_map_, image)); std::vector<Element> elements; @@ -74,10 +74,10 @@ TEST_F(ElementDetectionTest, ElementFinderEmpty) { std::vector<uint8_t> buffer(10, 0); ElementFinder finder( ConstBufferView(buffer.data(), buffer.size()), - base::BindRepeating([](ConstBufferView image) -> base::Optional<Element> { - return base::nullopt; + base::BindRepeating([](ConstBufferView image) -> absl::optional<Element> { + return absl::nullopt; })); - EXPECT_EQ(base::nullopt, finder.GetNext()); + EXPECT_EQ(absl::nullopt, finder.GetNext()); } TEST_F(ElementDetectionTest, ElementFinder) { diff --git a/fuzzers/patch_fuzzer.cc b/fuzzers/patch_fuzzer.cc index 2d1c9b7..83bebcf 100644 --- a/fuzzers/patch_fuzzer.cc +++ b/fuzzers/patch_fuzzer.cc @@ -5,15 +5,15 @@ #include <stddef.h> #include <stdint.h> -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/patch_reader.h" +#include "third_party/abseil-cpp/absl/types/optional.h" // Entry point for LibFuzzer. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { logging::SetMinLogLevel(3); // Disable console spamming. zucchini::ConstBufferView patch(data, size); - base::Optional<zucchini::EnsemblePatchReader> patch_reader = + absl::optional<zucchini::EnsemblePatchReader> patch_reader = zucchini::EnsemblePatchReader::Create(patch); return 0; } diff --git a/heuristic_ensemble_matcher.cc b/heuristic_ensemble_matcher.cc index d6acdbd..c812cb4 100644 --- a/heuristic_ensemble_matcher.cc +++ b/heuristic_ensemble_matcher.cc @@ -26,9 +26,9 @@ namespace { /******** Helper Functions ********/ // Uses |detector| to find embedded executables inside |image|, and returns the -// result on success, or base::nullopt on failure, which occurs if too many (> +// result on success, or absl::nullopt on failure, which occurs if too many (> // |kElementLimit|) elements are found. -base::Optional<std::vector<Element>> FindEmbeddedElements( +absl::optional<std::vector<Element>> FindEmbeddedElements( ConstBufferView image, const std::string& name, ElementDetector&& detector) { @@ -46,7 +46,7 @@ base::Optional<std::vector<Element>> FindEmbeddedElements( } if (elements.size() >= kElementLimit) { LOG(WARNING) << name << ": Found too many elements."; - return base::nullopt; + return absl::nullopt; } LOG(INFO) << name << ": Found " << elements.size() << " elements."; return elements; @@ -246,12 +246,12 @@ bool HeuristicEnsembleMatcher::RunMatch(ConstBufferView old_image, LOG(INFO) << "Start matching."; // Find all elements in "old" and "new". - base::Optional<std::vector<Element>> old_elements = + absl::optional<std::vector<Element>> old_elements = FindEmbeddedElements(old_image, "Old file", base::BindRepeating(DetectElementFromDisassembler)); if (!old_elements.has_value()) return false; - base::Optional<std::vector<Element>> new_elements = + absl::optional<std::vector<Element>> new_elements = FindEmbeddedElements(new_image, "New file", base::BindRepeating(DetectElementFromDisassembler)); if (!new_elements.has_value()) diff --git a/image_utils.h b/image_utils.h index b34b9dc..3d4a83a 100644 --- a/image_utils.h +++ b/image_utils.h @@ -13,10 +13,10 @@ #include "base/format_macros.h" #include "base/macros.h" #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "base/strings/stringprintf.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/typed_value.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -94,7 +94,7 @@ class ReferenceReader { // Returns the next available Reference, or nullopt_t if exhausted. // Extracted References must be ordered by their location in the image. - virtual base::Optional<Reference> GetNext() = 0; + virtual absl::optional<Reference> GetNext() = 0; }; // Interface for writing References through member function diff --git a/imposed_ensemble_matcher.cc b/imposed_ensemble_matcher.cc index e735bc4..1c1301b 100644 --- a/imposed_ensemble_matcher.cc +++ b/imposed_ensemble_matcher.cc @@ -89,8 +89,8 @@ ImposedMatchParser::Status ImposedMatchParser::Parse( continue; } // Check executable types of sub-images. - base::Optional<Element> old_element = detector.Run(old_sub_image); - base::Optional<Element> new_element = detector.Run(new_sub_image); + absl::optional<Element> old_element = detector.Run(old_sub_image); + absl::optional<Element> new_element = detector.Run(new_sub_image); if (!old_element || !new_element) { // Skip unknown types, including those mixed with known types. bad_matches_.push_back(matches_[read_idx]); diff --git a/imposed_ensemble_matcher_unittest.cc b/imposed_ensemble_matcher_unittest.cc index 85f1016..9a6dc7d 100644 --- a/imposed_ensemble_matcher_unittest.cc +++ b/imposed_ensemble_matcher_unittest.cc @@ -14,12 +14,12 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/check_op.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/disassembler.h" #include "components/zucchini/element_detection.h" #include "components/zucchini/image_utils.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -36,14 +36,14 @@ class TestElementDetector { public: TestElementDetector() {} - base::Optional<Element> Run(ConstBufferView image) const { + absl::optional<Element> Run(ConstBufferView image) const { DCHECK_GT(image.size(), 0U); char first_char = *image.begin(); if (first_char == 'W' || first_char == 'w') return Element(image.local_region(), kExeTypeWin32X86); if (first_char == 'E' || first_char == 'e') return Element(image.local_region(), kExeTypeElfX86); - return base::nullopt; + return absl::nullopt; } }; diff --git a/integration_test.cc b/integration_test.cc index 2d2e61f..1baccc3 100644 --- a/integration_test.cc +++ b/integration_test.cc @@ -10,13 +10,13 @@ #include "base/files/file_path.h" #include "base/files/memory_mapped_file.h" -#include "base/optional.h" #include "base/path_service.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/patch_reader.h" #include "components/zucchini/patch_writer.h" #include "components/zucchini/zucchini.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -59,7 +59,7 @@ void TestGenApply(const std::string& old_filename, patch_writer.SerializeInto({patch_buffer.data(), patch_buffer.size()}); // Read back generated patch. - base::Optional<EnsemblePatchReader> patch_reader = + absl::optional<EnsemblePatchReader> patch_reader = EnsemblePatchReader::Create({patch_buffer.data(), patch_buffer.size()}); ASSERT_TRUE(patch_reader.has_value()); diff --git a/patch_reader.cc b/patch_reader.cc index 3ec17e4..99951da 100644 --- a/patch_reader.cc +++ b/patch_reader.cc @@ -78,42 +78,42 @@ bool EquivalenceSource::Initialize(BufferSource* source) { patch::ParseBuffer(source, ©_count_); } -base::Optional<Equivalence> EquivalenceSource::GetNext() { +absl::optional<Equivalence> EquivalenceSource::GetNext() { if (src_skip_.empty() || dst_skip_.empty() || copy_count_.empty()) - return base::nullopt; + return absl::nullopt; Equivalence equivalence = {}; uint32_t length = 0; if (!patch::ParseVarUInt<uint32_t>(©_count_, &length)) - return base::nullopt; + return absl::nullopt; equivalence.length = base::strict_cast<offset_t>(length); int32_t src_offset_diff = 0; // Intentionally signed. if (!patch::ParseVarInt<int32_t>(&src_skip_, &src_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> src_offset = previous_src_offset_ + src_offset_diff; if (!src_offset.IsValid()) - return base::nullopt; + return absl::nullopt; equivalence.src_offset = src_offset.ValueOrDie(); previous_src_offset_ = src_offset + equivalence.length; if (!previous_src_offset_.IsValid()) - return base::nullopt; + return absl::nullopt; uint32_t dst_offset_diff = 0; // Intentionally unsigned. if (!patch::ParseVarUInt<uint32_t>(&dst_skip_, &dst_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> dst_offset = previous_dst_offset_ + dst_offset_diff; if (!dst_offset.IsValid()) - return base::nullopt; + return absl::nullopt; equivalence.dst_offset = dst_offset.ValueOrDie(); previous_dst_offset_ = equivalence.dst_offset + equivalence.length; if (!previous_dst_offset_.IsValid()) - return base::nullopt; + return absl::nullopt; // Caveat: |equivalence| is assumed to be safe only once the // ValidateEquivalencesAndExtraData() method has returned true. Prior to this @@ -131,10 +131,10 @@ bool ExtraDataSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &extra_data_); } -base::Optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) { +absl::optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) { ConstBufferView buffer; if (!extra_data_.GetRegion(size, &buffer)) - return base::nullopt; + return absl::nullopt; // |buffer| is assumed to always be safe/valid. return buffer; } @@ -150,32 +150,32 @@ bool RawDeltaSource::Initialize(BufferSource* source) { patch::ParseBuffer(source, &raw_delta_diff_); } -base::Optional<RawDeltaUnit> RawDeltaSource::GetNext() { +absl::optional<RawDeltaUnit> RawDeltaSource::GetNext() { if (raw_delta_skip_.empty() || raw_delta_diff_.empty()) - return base::nullopt; + return absl::nullopt; RawDeltaUnit raw_delta = {}; uint32_t copy_offset_diff = 0; if (!patch::ParseVarUInt<uint32_t>(&raw_delta_skip_, ©_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> copy_offset = copy_offset_diff + copy_offset_compensation_; if (!copy_offset.IsValid()) - return base::nullopt; + return absl::nullopt; raw_delta.copy_offset = copy_offset.ValueOrDie(); if (!raw_delta_diff_.GetValue<int8_t>(&raw_delta.diff)) - return base::nullopt; + return absl::nullopt; // A 0 value for a delta.diff is considered invalid since it has no meaning. if (!raw_delta.diff) - return base::nullopt; + return absl::nullopt; // We keep track of the compensation needed for next offset, taking into // account delta encoding and bias of -1. copy_offset_compensation_ = copy_offset + 1; if (!copy_offset_compensation_.IsValid()) - return base::nullopt; + return absl::nullopt; // |raw_delta| is assumed to always be safe/valid. return raw_delta; } @@ -191,12 +191,12 @@ bool ReferenceDeltaSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &source_); } -base::Optional<int32_t> ReferenceDeltaSource::GetNext() { +absl::optional<int32_t> ReferenceDeltaSource::GetNext() { if (source_.empty()) - return base::nullopt; + return absl::nullopt; int32_t ref_delta = 0; if (!patch::ParseVarInt<int32_t>(&source_, &ref_delta)) - return base::nullopt; + return absl::nullopt; // |ref_delta| is assumed to always be safe/valid. return ref_delta; } @@ -211,22 +211,22 @@ bool TargetSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &extra_targets_); } -base::Optional<offset_t> TargetSource::GetNext() { +absl::optional<offset_t> TargetSource::GetNext() { if (extra_targets_.empty()) - return base::nullopt; + return absl::nullopt; uint32_t target_diff = 0; if (!patch::ParseVarUInt<uint32_t>(&extra_targets_, &target_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> target = target_diff + target_compensation_; if (!target.IsValid()) - return base::nullopt; + return absl::nullopt; // We keep track of the compensation needed for next target, taking into // account delta encoding and bias of -1. target_compensation_ = target + 1; if (!target_compensation_.IsValid()) - return base::nullopt; + return absl::nullopt; // Caveat: |target| will be a valid offset_t, but it's up to the caller to // check whether it's a valid offset for an image. return offset_t(target.ValueOrDie()); @@ -312,12 +312,12 @@ bool PatchElementReader::ValidateEquivalencesAndExtraData() { /******** EnsemblePatchReader ********/ -base::Optional<EnsemblePatchReader> EnsemblePatchReader::Create( +absl::optional<EnsemblePatchReader> EnsemblePatchReader::Create( ConstBufferView buffer) { BufferSource source(buffer); EnsemblePatchReader patch; if (!patch.Initialize(&source)) - return base::nullopt; + return absl::nullopt; return patch; } diff --git a/patch_reader.h b/patch_reader.h index 515da50..93d64b0 100644 --- a/patch_reader.h +++ b/patch_reader.h @@ -14,11 +14,11 @@ #include "base/debug/stack_trace.h" #include "base/logging.h" #include "base/numerics/checked_math.h" -#include "base/optional.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -77,8 +77,8 @@ bool ParseVarInt(BufferSource* source, T* value) { // - bool Initialize(BufferSource* source): Consumes data from BufferSource and // initializes internal states. Returns true if successful, and false // otherwise (|source| may be partially consumed). -// - base::Optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and -// returns the next item as base::Optional (returns base::nullopt on failure). +// - absl::optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and +// returns the next item as absl::optional (returns absl::nullopt on failure). // - bool Done() const: Returns true if no more items remain; otherwise false. // // Usage of *Source instances don't mix, and GetNext() have dissimilar @@ -94,7 +94,7 @@ class EquivalenceSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<Equivalence> GetNext(); + absl::optional<Equivalence> GetNext(); bool Done() const { return src_skip_.empty() && dst_skip_.empty() && copy_count_.empty(); } @@ -123,7 +123,7 @@ class ExtraDataSource { // Core functions. bool Initialize(BufferSource* source); // |size| is the size in bytes of the buffer requested. - base::Optional<ConstBufferView> GetNext(offset_t size); + absl::optional<ConstBufferView> GetNext(offset_t size); bool Done() const { return extra_data_.empty(); } // Accessors for unittest. @@ -142,7 +142,7 @@ class RawDeltaSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<RawDeltaUnit> GetNext(); + absl::optional<RawDeltaUnit> GetNext(); bool Done() const { return raw_delta_skip_.empty() && raw_delta_diff_.empty(); } @@ -167,7 +167,7 @@ class ReferenceDeltaSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<int32_t> GetNext(); + absl::optional<int32_t> GetNext(); bool Done() const { return source_.empty(); } // Accessors for unittest. @@ -186,7 +186,7 @@ class TargetSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<offset_t> GetNext(); + absl::optional<offset_t> GetNext(); bool Done() const { return extra_targets_.empty(); } // Accessors for unittest. @@ -256,8 +256,8 @@ class PatchElementReader { class EnsemblePatchReader { public: // If data read from |buffer| is well-formed, initializes and returns - // an instance of EnsemblePatchReader. Otherwise returns base::nullopt. - static base::Optional<EnsemblePatchReader> Create(ConstBufferView buffer); + // an instance of EnsemblePatchReader. Otherwise returns absl::nullopt. + static absl::optional<EnsemblePatchReader> Create(ConstBufferView buffer); EnsemblePatchReader(); EnsemblePatchReader(EnsemblePatchReader&&); diff --git a/patch_writer.h b/patch_writer.h index 34acaf1..3d42173 100644 --- a/patch_writer.h +++ b/patch_writer.h @@ -14,11 +14,11 @@ #include "base/check.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_sink.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -224,10 +224,10 @@ class PatchElementWriter { private: ElementMatch element_match_; - base::Optional<EquivalenceSink> equivalences_; - base::Optional<ExtraDataSink> extra_data_; - base::Optional<RawDeltaSink> raw_delta_; - base::Optional<ReferenceDeltaSink> reference_delta_; + absl::optional<EquivalenceSink> equivalences_; + absl::optional<ExtraDataSink> extra_data_; + absl::optional<RawDeltaSink> raw_delta_; + absl::optional<ReferenceDeltaSink> reference_delta_; std::map<PoolTag, TargetSink> extra_targets_; }; diff --git a/rel32_finder.cc b/rel32_finder.cc index 8fb88f5..45810d6 100644 --- a/rel32_finder.cc +++ b/rel32_finder.cc @@ -41,7 +41,7 @@ Abs32GapFinder::Abs32GapFinder(ConstBufferView image, Abs32GapFinder::~Abs32GapFinder() = default; -base::Optional<ConstBufferView> Abs32GapFinder::GetNext() { +absl::optional<ConstBufferView> Abs32GapFinder::GetNext() { // Iterate over |[abs32_current_, abs32_end_)| and emit segments. while (abs32_current_ != abs32_end_ && base_ + *abs32_current_ < region_end_) { @@ -58,7 +58,7 @@ base::Optional<ConstBufferView> Abs32GapFinder::GetNext() { current_lo_ = region_end_; return gap; } - return base::nullopt; + return absl::nullopt; } /******** Rel32Finder ********/ diff --git a/rel32_finder.h b/rel32_finder.h index b70b1be..5953755 100644 --- a/rel32_finder.h +++ b/rel32_finder.h @@ -10,9 +10,9 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -52,7 +52,7 @@ class Abs32GapFinder { ~Abs32GapFinder(); // Returns the next available gap, or nullopt if exhausted. - base::Optional<ConstBufferView> GetNext(); + absl::optional<ConstBufferView> GetNext(); private: const ConstBufferView::const_iterator base_; @@ -134,10 +134,10 @@ class Rel32FinderIntel : public Rel32Finder { using Rel32Finder::Rel32Finder; // Returns the next available Result, or nullopt if exhausted. - base::Optional<Result> GetNext() { + absl::optional<Result> GetNext() { if (FindNext()) return rel32_; - return base::nullopt; + return absl::nullopt; } protected: diff --git a/rel32_finder_unittest.cc b/rel32_finder_unittest.cc index 9da88bf..42a442c 100644 --- a/rel32_finder_unittest.cc +++ b/rel32_finder_unittest.cc @@ -234,7 +234,7 @@ TEST(Rel32FinderX86Test, FindNext) { EXPECT_FALSE(result->can_point_outside_section); rel_finder.Accept(); } - EXPECT_EQ(base::nullopt, rel_finder.GetNext()); + EXPECT_EQ(absl::nullopt, rel_finder.GetNext()); } TEST(Rel32FinderX86Test, Accept) { @@ -349,7 +349,7 @@ TEST(Rel32FinderX64Test, FindNext) { EXPECT_TRUE(result->can_point_outside_section); rel_finder.Accept(); } - EXPECT_EQ(base::nullopt, rel_finder.GetNext()); + EXPECT_EQ(absl::nullopt, rel_finder.GetNext()); } // TODO(huangs): Test that integrates Abs32GapFinder and Rel32Finder. diff --git a/rel32_utils.cc b/rel32_utils.cc index e6d187d..c22cb23 100644 --- a/rel32_utils.cc +++ b/rel32_utils.cc @@ -30,7 +30,7 @@ Rel32ReaderX86::Rel32ReaderX86(ConstBufferView image, Rel32ReaderX86::~Rel32ReaderX86() = default; -base::Optional<Reference> Rel32ReaderX86::GetNext() { +absl::optional<Reference> Rel32ReaderX86::GetNext() { while (current_ < last_ && *current_ < hi_) { offset_t loc_offset = *(current_++); DCHECK_LE(loc_offset + 4, image_.size()); // Sanity check. @@ -41,7 +41,7 @@ base::Optional<Reference> Rel32ReaderX86::GetNext() { DCHECK_NE(kInvalidOffset, target_offset); return Reference{loc_offset, target_offset}; } - return base::nullopt; + return absl::nullopt; } /******** Rel32ReceptorX86 ********/ diff --git a/rel32_utils.h b/rel32_utils.h index 946fcc6..4f7e0f3 100644 --- a/rel32_utils.h +++ b/rel32_utils.h @@ -11,12 +11,12 @@ #include "base/logging.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/arm_utils.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/io_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -36,8 +36,8 @@ class Rel32ReaderX86 : public ReferenceReader { const AddressTranslator& translator); ~Rel32ReaderX86() override; - // Returns the next reference, or base::nullopt if exhausted. - base::Optional<Reference> GetNext() override; + // Returns the next reference, or absl::nullopt if exhausted. + absl::optional<Reference> GetNext() override; private: ConstBufferView image_; @@ -91,7 +91,7 @@ class Rel32ReaderArm : public ReferenceReader { rel32_end_ = rel32_locations.end(); } - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_it_ < rel32_end_ && *cur_it_ < hi_) { offset_t location = *(cur_it_++); CODE_T code = ADDR_TRAITS::Fetch(view_, location); @@ -103,7 +103,7 @@ class Rel32ReaderArm : public ReferenceReader { return Reference{location, target}; } } - return base::nullopt; + return absl::nullopt; } private: diff --git a/rel32_utils_unittest.cc b/rel32_utils_unittest.cc index 3fdf5d6..32fd7ae 100644 --- a/rel32_utils_unittest.cc +++ b/rel32_utils_unittest.cc @@ -11,12 +11,12 @@ #include <utility> #include <vector> -#include "base/optional.h" #include "base/test/gtest_util.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/arm_utils.h" #include "components/zucchini/image_utils.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -40,7 +40,7 @@ void CheckReader(const std::vector<Reference>& expected_refs, EXPECT_TRUE(ref.has_value()); EXPECT_EQ(expected_ref, ref.value()); } - EXPECT_EQ(base::nullopt, reader->GetNext()); // Nothing should be left. + EXPECT_EQ(absl::nullopt, reader->GetNext()); // Nothing should be left. } // Copies displacements from |bytes1| to |bytes2| and checks results against diff --git a/reloc_elf.cc b/reloc_elf.cc index d4857e8..a7d1b38 100644 --- a/reloc_elf.cc +++ b/reloc_elf.cc @@ -89,7 +89,7 @@ rva_t RelocReaderElf::GetRelocationTarget(elf::Elf64_Rel rel) const { return kInvalidRva; } -base::Optional<Reference> RelocReaderElf::GetNext() { +absl::optional<Reference> RelocReaderElf::GetNext() { offset_t cur_entry_size = cur_section_dimensions_->entry_size; offset_t cur_section_dimensions_end = base::checked_cast<offset_t>(cur_section_dimensions_->region.hi()); @@ -98,12 +98,12 @@ base::Optional<Reference> RelocReaderElf::GetNext() { while (cursor_ >= cur_section_dimensions_end) { ++cur_section_dimensions_; if (cur_section_dimensions_ == reloc_section_dimensions_.end()) - return base::nullopt; + return absl::nullopt; cur_entry_size = cur_section_dimensions_->entry_size; cursor_ = base::checked_cast<offset_t>(cur_section_dimensions_->region.offset); if (cursor_ + cur_entry_size > hi_) - return base::nullopt; + return absl::nullopt; cur_section_dimensions_end = base::checked_cast<offset_t>(cur_section_dimensions_->region.hi()); } @@ -132,7 +132,7 @@ base::Optional<Reference> RelocReaderElf::GetNext() { cursor_ += cur_entry_size; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } /******** RelocWriterElf ********/ diff --git a/reloc_elf.h b/reloc_elf.h index 7fcdbd3..ebf2577 100644 --- a/reloc_elf.h +++ b/reloc_elf.h @@ -11,11 +11,11 @@ #include <vector> #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/type_elf.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -68,7 +68,7 @@ class RelocReaderElf : public ReferenceReader { rva_t GetRelocationTarget(elf::Elf64_Rel rel) const; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: const ConstBufferView image_; diff --git a/reloc_elf_unittest.cc b/reloc_elf_unittest.cc index acbc186..ac5086a 100644 --- a/reloc_elf_unittest.cc +++ b/reloc_elf_unittest.cc @@ -85,7 +85,7 @@ class FakeImageWithReloc { // Read all references and check. std::vector<Reference> refs; - for (base::Optional<Reference> ref = reader->GetNext(); ref.has_value(); + for (absl::optional<Reference> ref = reader->GetNext(); ref.has_value(); ref = reader->GetNext()) { refs.push_back(ref.value()); } diff --git a/reloc_win32.cc b/reloc_win32.cc index 6da48f2..b70aa8a 100644 --- a/reloc_win32.cc +++ b/reloc_win32.cc @@ -93,14 +93,14 @@ RelocRvaReaderWin32::RelocRvaReaderWin32(RelocRvaReaderWin32&&) = default; RelocRvaReaderWin32::~RelocRvaReaderWin32() = default; // Unrolls a nested loop: outer = reloc blocks and inner = reloc entries. -base::Optional<RelocUnitWin32> RelocRvaReaderWin32::GetNext() { +absl::optional<RelocUnitWin32> RelocRvaReaderWin32::GetNext() { // "Outer loop" to find non-empty reloc block. while (cur_reloc_units_.Remaining() < kRelocUnitSize) { if (!LoadRelocBlock(cur_reloc_units_.end())) - return base::nullopt; + return absl::nullopt; } if (end_it_ - cur_reloc_units_.begin() < kRelocUnitSize) - return base::nullopt; + return absl::nullopt; // "Inner loop" to extract single reloc unit. offset_t location = base::checked_cast<offset_t>(cur_reloc_units_.begin() - image_.begin()); @@ -144,8 +144,8 @@ RelocReaderWin32::RelocReaderWin32(RelocRvaReaderWin32&& reloc_rva_reader, RelocReaderWin32::~RelocReaderWin32() = default; // ReferenceReader: -base::Optional<Reference> RelocReaderWin32::GetNext() { - for (base::Optional<RelocUnitWin32> unit = reloc_rva_reader_.GetNext(); +absl::optional<Reference> RelocReaderWin32::GetNext() { + for (absl::optional<RelocUnitWin32> unit = reloc_rva_reader_.GetNext(); unit.has_value(); unit = reloc_rva_reader_.GetNext()) { if (unit->type != reloc_type_) continue; @@ -158,7 +158,7 @@ base::Optional<Reference> RelocReaderWin32::GetNext() { offset_t location = unit->location; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } /******** RelocWriterWin32 ********/ diff --git a/reloc_win32.h b/reloc_win32.h index 207c6e7..6393702 100644 --- a/reloc_win32.h +++ b/reloc_win32.h @@ -10,11 +10,11 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -65,9 +65,9 @@ class RelocRvaReaderWin32 { RelocRvaReaderWin32(RelocRvaReaderWin32&&); ~RelocRvaReaderWin32(); - // Successively visits and returns data for each reloc unit, or base::nullopt + // Successively visits and returns data for each reloc unit, or absl::nullopt // when all reloc units are found. Encapsulates block transition details. - base::Optional<RelocUnitWin32> GetNext(); + absl::optional<RelocUnitWin32> GetNext(); private: // Assuming that |block_begin| points to the beginning of a reloc block, loads @@ -102,7 +102,7 @@ class RelocReaderWin32 : public ReferenceReader { ~RelocReaderWin32() override; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: RelocRvaReaderWin32 reloc_rva_reader_; diff --git a/reloc_win32_unittest.cc b/reloc_win32_unittest.cc index 1b9894f..e3d33ca 100644 --- a/reloc_win32_unittest.cc +++ b/reloc_win32_unittest.cc @@ -219,7 +219,7 @@ TEST_F(RelocUtilsWin32Test, ReadWrite) { // Read all references and check. std::vector<Reference> refs; - for (base::Optional<Reference> ref = reader->GetNext(); ref.has_value(); + for (absl::optional<Reference> ref = reader->GetNext(); ref.has_value(); ref = reader->GetNext()) { refs.push_back(ref.value()); } diff --git a/test_reference_reader.cc b/test_reference_reader.cc index 5517fa0..b7f8ece 100644 --- a/test_reference_reader.cc +++ b/test_reference_reader.cc @@ -11,9 +11,9 @@ TestReferenceReader::TestReferenceReader(const std::vector<Reference>& refs) TestReferenceReader::~TestReferenceReader() = default; -base::Optional<Reference> TestReferenceReader::GetNext() { +absl::optional<Reference> TestReferenceReader::GetNext() { if (index_ == references_.size()) - return base::nullopt; + return absl::nullopt; return references_[index_++]; } diff --git a/test_reference_reader.h b/test_reference_reader.h index afae188..cc8c0de 100644 --- a/test_reference_reader.h +++ b/test_reference_reader.h @@ -9,8 +9,8 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -20,7 +20,7 @@ class TestReferenceReader : public ReferenceReader { explicit TestReferenceReader(const std::vector<Reference>& refs); ~TestReferenceReader() override; - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: std::vector<Reference> references_; diff --git a/zucchini_apply.cc b/zucchini_apply.cc index 2d001a1..10c5638 100644 --- a/zucchini_apply.cc +++ b/zucchini_apply.cc @@ -32,7 +32,7 @@ bool ApplyEquivalenceAndExtraData(ConstBufferView old_image, CHECK(next_dst_it >= dst_it); offset_t gap = static_cast<offset_t>(next_dst_it - dst_it); - base::Optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); + absl::optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); if (!extra_data) { LOG(ERROR) << "Error reading extra_data"; return false; @@ -46,7 +46,7 @@ bool ApplyEquivalenceAndExtraData(ConstBufferView old_image, CHECK_EQ(dst_it, next_dst_it + equivalence->length); } offset_t gap = static_cast<offset_t>(new_image.end() - dst_it); - base::Optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); + absl::optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); if (!extra_data) { LOG(ERROR) << "Error reading extra_data"; return false; diff --git a/zucchini_gen.h b/zucchini_gen.h index 17f1fd4..c92248d 100644 --- a/zucchini_gen.h +++ b/zucchini_gen.h @@ -7,10 +7,10 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/zucchini.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { |