Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 725833e0 authored by Sen Jiang's avatar Sen Jiang Committed by android-build-merger
Browse files

Merge "applypatch: Compile libimgpatch for target and host."

am: 1f3616f3

* commit '1f3616f3':
  applypatch: Compile libimgpatch for target and host.
parents bb0e2754 1f3616f3
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -20,13 +20,35 @@ LOCAL_CLANG := true
LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.cpp
LOCAL_MODULE := libapplypatch
LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += external/bzip2 external/zlib bootable/recovery
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_STATIC_LIBRARIES += libbase libmtdutils libmincrypt libbz libz

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_CLANG := true
LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp
LOCAL_MODULE := libimgpatch
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_CLANG := true
LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp
LOCAL_MODULE := libimgpatch
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz

include $(BUILD_HOST_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_CLANG := true
LOCAL_SRC_FILES := main.cpp
LOCAL_MODULE := applypatch
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <malloc.h>
#include <unistd.h>
+19 −1
Original line number Diff line number Diff line
@@ -31,13 +31,22 @@
#include "imgdiff.h"
#include "utils.h"

int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
                    const unsigned char* patch_data, ssize_t patch_size,
                    SinkFn sink, void* token) {
  Value patch = {VAL_BLOB, patch_size,
      reinterpret_cast<char*>(const_cast<unsigned char*>(patch_data))};
  return ApplyImagePatch(
      old_data, old_size, &patch, sink, token, nullptr, nullptr);
}

/*
 * Apply the patch given in 'patch_filename' to the source data given
 * by (old_data, old_size).  Write the patched output to the 'output'
 * file, and update the SHA context with the output data as well.
 * Return 0 on success.
 */
int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
                    const Value* patch,
                    SinkFn sink, void* token, SHA_CTX* ctx,
                    const Value* bonus_data) {
@@ -80,6 +89,10 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
            size_t src_len = Read8(normal_header+8);
            size_t patch_offset = Read8(normal_header+16);

            if (src_start + src_len > static_cast<size_t>(old_size)) {
                printf("source data too short\n");
                return -1;
            }
            ApplyBSDiffPatch(old_data + src_start, src_len,
                             patch, patch_offset, sink, token, ctx);
        } else if (type == CHUNK_RAW) {
@@ -123,6 +136,11 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
            int memLevel = Read4(deflate_header+52);
            int strategy = Read4(deflate_header+56);

            if (src_start + src_len > static_cast<size_t>(old_size)) {
                printf("source data too short\n");
                return -1;
            }

            // Decompress the source data; the chunk header tells us exactly
            // how big we expect it to be when decompressed.

+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _IMGPATCH_H
#define _IMGPATCH_H

typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*);

int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
                    const unsigned char* patch_data, ssize_t patch_size,
                    SinkFn sink, void* token);

#endif  //_IMGPATCH_H