diff options
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/applypatch.cpp | 2 | ||||
-rw-r--r-- | applypatch/applypatch_modes.cpp | 77 | ||||
-rw-r--r-- | applypatch/imgpatch.cpp | 14 |
3 files changed, 46 insertions, 47 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index fc29493b4..b1f5607a6 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -553,7 +553,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename, static int GenerateTarget(const FileContents& source_file, const std::unique_ptr<Value>& patch, const std::string& target_filename, const uint8_t target_sha1[SHA_DIGEST_LENGTH], const Value* bonus_data) { - if (patch->type != VAL_BLOB) { + if (patch->type != Value::Type::BLOB) { LOG(ERROR) << "patch is not a blob"; return 1; } diff --git a/applypatch/applypatch_modes.cpp b/applypatch/applypatch_modes.cpp index 6437e1be6..ec95325fc 100644 --- a/applypatch/applypatch_modes.cpp +++ b/applypatch/applypatch_modes.cpp @@ -81,52 +81,51 @@ static int FlashMode(const char* src_filename, const char* tgt_filename, } static int PatchMode(int argc, const char** argv) { - FileContents bonusFc; - Value bonus(VAL_INVALID, ""); - - if (argc >= 3 && strcmp(argv[1], "-b") == 0) { - if (LoadFileContents(argv[2], &bonusFc) != 0) { - LOG(ERROR) << "Failed to load bonus file " << argv[2]; - return 1; - } - bonus.type = VAL_BLOB; - bonus.data = std::string(bonusFc.data.cbegin(), bonusFc.data.cend()); - argc -= 2; - argv += 2; - } - - if (argc < 4) { - return 2; - } - - size_t target_size; - if (!android::base::ParseUint(argv[4], &target_size) || target_size == 0) { - LOG(ERROR) << "Failed to parse \"" << argv[4] << "\" as byte count"; + std::unique_ptr<Value> bonus; + if (argc >= 3 && strcmp(argv[1], "-b") == 0) { + FileContents bonus_fc; + if (LoadFileContents(argv[2], &bonus_fc) != 0) { + LOG(ERROR) << "Failed to load bonus file " << argv[2]; return 1; } + bonus = std::make_unique<Value>(Value::Type::BLOB, + std::string(bonus_fc.data.cbegin(), bonus_fc.data.cend())); + argc -= 2; + argv += 2; + } - // If no <src-sha1>:<patch> is provided, it is in flash mode. - if (argc == 5) { - if (bonus.type != VAL_INVALID) { - LOG(ERROR) << "bonus file not supported in flash mode"; - return 1; - } - return FlashMode(argv[1], argv[2], argv[3], target_size); - } + if (argc < 4) { + return 2; + } - std::vector<std::string> sha1s; - std::vector<FileContents> files; - if (!ParsePatchArgs(argc-5, argv+5, &sha1s, &files)) { - LOG(ERROR) << "Failed to parse patch args"; + size_t target_size; + if (!android::base::ParseUint(argv[4], &target_size) || target_size == 0) { + LOG(ERROR) << "Failed to parse \"" << argv[4] << "\" as byte count"; + return 1; + } + + // If no <src-sha1>:<patch> is provided, it is in flash mode. + if (argc == 5) { + if (bonus) { + LOG(ERROR) << "bonus file not supported in flash mode"; return 1; } + return FlashMode(argv[1], argv[2], argv[3], target_size); + } - std::vector<std::unique_ptr<Value>> patches; - for (size_t i = 0; i < files.size(); ++i) { - patches.push_back(std::make_unique<Value>( - VAL_BLOB, std::string(files[i].data.cbegin(), files[i].data.cend()))); - } - return applypatch(argv[1], argv[2], argv[3], target_size, sha1s, patches, &bonus); + std::vector<std::string> sha1s; + std::vector<FileContents> files; + if (!ParsePatchArgs(argc - 5, argv + 5, &sha1s, &files)) { + LOG(ERROR) << "Failed to parse patch args"; + return 1; + } + + std::vector<std::unique_ptr<Value>> patches; + for (const auto& file : files) { + patches.push_back(std::make_unique<Value>(Value::Type::BLOB, + std::string(file.data.cbegin(), file.data.cend()))); + } + return applypatch(argv[1], argv[2], argv[3], target_size, sha1s, patches, bonus.get()); } // This program (applypatch) applies binary patches to files in a way that diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index 2f8f4851d..da7569219 100644 --- a/applypatch/imgpatch.cpp +++ b/applypatch/imgpatch.cpp @@ -151,7 +151,8 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const unsigned char* patch_data, size_t patch_size, SinkFn sink) { - Value patch(VAL_BLOB, std::string(reinterpret_cast<const char*>(patch_data), patch_size)); + Value patch(Value::Type::BLOB, + std::string(reinterpret_cast<const char*>(patch_data), patch_size)); return ApplyImagePatch(old_data, old_size, patch, sink, nullptr); } @@ -246,11 +247,10 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& // Decompress the source data; the chunk header tells us exactly // how big we expect it to be when decompressed. - // Note: expanded_len will include the bonus data size if - // the patch was constructed with bonus data. The - // deflation will come up 'bonus_size' bytes short; these - // must be appended from the bonus_data value. - size_t bonus_size = (i == 1 && bonus_data != NULL) ? bonus_data->data.size() : 0; + // Note: expanded_len will include the bonus data size if the patch was constructed with + // bonus data. The deflation will come up 'bonus_size' bytes short; these must be appended + // from the bonus_data value. + size_t bonus_size = (i == 1 && bonus_data != nullptr) ? bonus_data->data.size() : 0; std::vector<unsigned char> expanded_source(expanded_len); @@ -288,7 +288,7 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& inflateEnd(&strm); if (bonus_size) { - memcpy(expanded_source.data() + (expanded_len - bonus_size), &bonus_data->data[0], + memcpy(expanded_source.data() + (expanded_len - bonus_size), bonus_data->data.data(), bonus_size); } } |