applypatch: Compile libimgpatch for target and host.
update_engine need it for the new IMGDIFF operation. Also removed __unused in ApplyImagePatch() as I got error building it for the host, and I think it's dangerous not checking the size of the input. Test: mma Bug: 26628339 Change-Id: I22d4cd55c2c3f87697d6afdf10e8106fef7d1a9c
This commit is contained in:
parent
5797bf9c90
commit
0cce9cda0c
4 changed files with 69 additions and 2 deletions
|
@ -20,13 +20,35 @@ LOCAL_CLANG := true
|
||||||
LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.cpp
|
LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.cpp
|
||||||
LOCAL_MODULE := libapplypatch
|
LOCAL_MODULE := libapplypatch
|
||||||
LOCAL_MODULE_TAGS := eng
|
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
|
LOCAL_STATIC_LIBRARIES += libbase libmtdutils libmincrypt libbz libz
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
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_CLANG := true
|
||||||
LOCAL_SRC_FILES := main.cpp
|
LOCAL_SRC_FILES := main.cpp
|
||||||
LOCAL_MODULE := applypatch
|
LOCAL_MODULE := applypatch
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -31,13 +31,22 @@
|
||||||
#include "imgdiff.h"
|
#include "imgdiff.h"
|
||||||
#include "utils.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
|
* Apply the patch given in 'patch_filename' to the source data given
|
||||||
* by (old_data, old_size). Write the patched output to the 'output'
|
* by (old_data, old_size). Write the patched output to the 'output'
|
||||||
* file, and update the SHA context with the output data as well.
|
* file, and update the SHA context with the output data as well.
|
||||||
* Return 0 on success.
|
* 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,
|
const Value* patch,
|
||||||
SinkFn sink, void* token, SHA_CTX* ctx,
|
SinkFn sink, void* token, SHA_CTX* ctx,
|
||||||
const Value* bonus_data) {
|
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 src_len = Read8(normal_header+8);
|
||||||
size_t patch_offset = Read8(normal_header+16);
|
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,
|
ApplyBSDiffPatch(old_data + src_start, src_len,
|
||||||
patch, patch_offset, sink, token, ctx);
|
patch, patch_offset, sink, token, ctx);
|
||||||
} else if (type == CHUNK_RAW) {
|
} 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 memLevel = Read4(deflate_header+52);
|
||||||
int strategy = Read4(deflate_header+56);
|
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
|
// Decompress the source data; the chunk header tells us exactly
|
||||||
// how big we expect it to be when decompressed.
|
// how big we expect it to be when decompressed.
|
||||||
|
|
||||||
|
|
26
applypatch/include/applypatch/imgpatch.h
Normal file
26
applypatch/include/applypatch/imgpatch.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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
|
Loading…
Reference in a new issue