diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2014-11-21 20:54:27 +0100 |
---|---|---|
committer | Ethan Yonker <dees_troy@teamw.in> | 2014-12-02 17:34:15 +0100 |
commit | 75bf041a8ad75f8fc9bba69e937e12b129338a4c (patch) | |
tree | 9a3202b8c06e075e1749a44948a3a3f184edf95e | |
parent | TWRP MTP: make sure inotify_fd is set (diff) | |
download | android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar.gz android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar.bz2 android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar.lz android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar.xz android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.tar.zst android_bootable_recovery-75bf041a8ad75f8fc9bba69e937e12b129338a4c.zip |
Diffstat (limited to '')
-rw-r--r-- | Android.mk | 21 | ||||
-rw-r--r-- | etc/init.rc | 1 | ||||
-rw-r--r-- | fuse.h | 574 | ||||
-rw-r--r-- | fuse_sideload.c | 2 | ||||
-rw-r--r-- | gui/Android.mk | 5 | ||||
-rw-r--r-- | gui/pages.cpp | 18 | ||||
-rw-r--r-- | libmincrypt/Android.mk | 3 | ||||
-rw-r--r-- | minzipold/Android.mk | 10 | ||||
-rw-r--r-- | minzipold/DirUtil.c | 5 | ||||
-rw-r--r-- | minzipold/DirUtil.h | 4 | ||||
-rw-r--r-- | minzipold/SysUtil.c | 8 | ||||
-rw-r--r-- | minzipold/Zip.c | 10 | ||||
-rw-r--r-- | minzipold/Zip.h | 4 | ||||
-rw-r--r-- | prebuilt/Android.mk | 25 | ||||
-rw-r--r-- | tests/Android.mk | 3 | ||||
-rw-r--r-- | toolbox/Android.mk | 158 | ||||
-rw-r--r-- | twinstall.cpp | 25 | ||||
-rw-r--r-- | twrp-functions.cpp | 12 | ||||
-rw-r--r-- | uncrypt/Android.mk | 2 | ||||
-rw-r--r-- | verifierold.cpp | 344 | ||||
-rw-r--r-- | verifierold.h | 43 |
21 files changed, 1225 insertions, 52 deletions
diff --git a/Android.mk b/Android.mk index 5bf90ce48..569ff8b9c 100644 --- a/Android.mk +++ b/Android.mk @@ -84,7 +84,7 @@ LOCAL_CFLAGS += -Wno-unused-parameter # libm \ # libc -LOCAL_C_INCLUDES += bionic external/stlport/stlport external/openssl/include +LOCAL_C_INCLUDES += bionic external/stlport/stlport external/openssl/include $(LOCAL_PATH)/libmincrypt/includes LOCAL_STATIC_LIBRARIES := LOCAL_SHARED_LIBRARIES := @@ -326,6 +326,11 @@ ifneq ($(wildcard bionic/libc/include/sys/capability.h),) LOCAL_CFLAGS += -DHAVE_CAPABILITIES endif +# Auto filled build flag +ifeq ($(PLATFORM_VERSION), 5.0) + LOCAL_CFLAGS += -DANDROID_VERSION=5 +endif + LOCAL_LDFLAGS += -Wl,-dynamic-linker,/sbin/linker LOCAL_ADDITIONAL_DEPENDENCIES := \ @@ -339,8 +344,7 @@ LOCAL_ADDITIONAL_DEPENDENCIES := \ teamwin \ toolbox_symlinks \ twrp \ - unpigz_symlink \ - updater + unpigz_symlink ifneq ($(TARGET_ARCH), arm64) LOCAL_ADDITIONAL_DEPENDENCIES += \ @@ -439,7 +443,7 @@ LOCAL_SRC_FILES := fuse_sideload.c LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE - +LOCAL_MODULE_TAGS := optional LOCAL_MODULE := libfusesideload LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes LOCAL_SHARED_LIBRARIES := libcutils libc libmincrypttwrp @@ -474,7 +478,12 @@ include $(CLEAR_VARS) LOCAL_MODULE := libaosprecovery LOCAL_MODULE_TAGS := eng optional LOCAL_C_INCLUDES := $(LOCAL_PATH)/libmincrypt/includes -LOCAL_SRC_FILES = adb_install.cpp asn1_decoder.cpp bootloader.cpp verifier.cpp mtdutils/mtdutils.c legacy_property_service.c +LOCAL_SRC_FILES := adb_install.cpp asn1_decoder.cpp bootloader.cpp mtdutils/mtdutils.c legacy_property_service.c +ifeq ($(PLATFORM_VERSION), 5.0) + LOCAL_SRC_FILES += verifier.cpp +else + LOCAL_SRC_FILES += verifierold.cpp +endif LOCAL_SHARED_LIBRARIES += libc liblog libcutils libmtdutils libfusesideload libmincrypttwrp ifneq ($(BOARD_RECOVERY_BLDRMSG_OFFSET),) @@ -533,7 +542,7 @@ endif ifeq ($(TW_INCLUDE_L_CRYPTO), true) include $(commands_recovery_local_path)/crypto/lollipop/Android.mk endif -ifeq ($(TWHAVE_SELINUX), true) +ifeq ($(PLATFORM_VERSION), 5.0) include $(commands_recovery_local_path)/minzip/Android.mk else include $(commands_recovery_local_path)/minzipold/Android.mk diff --git a/etc/init.rc b/etc/init.rc index 67b6a6f14..7dae1c9e8 100644 --- a/etc/init.rc +++ b/etc/init.rc @@ -113,7 +113,6 @@ service healthd /sbin/healthd -r seclabel u:r:healthd:s0 service recovery /sbin/recovery - seclabel u:r:recovery:s0 service adbd /sbin/adbd --root_seclabel=u:r:su:s0 --device_banner=recovery disabled @@ -0,0 +1,574 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + *** To edit the content of this header, modify the corresponding + *** source file (e.g. under external/kernel-headers/original/) then + *** run bionic/libc/kernel/tools/update_all.py + *** + *** Any manual change here will be lost the next time this script will + *** be run. You've been warned! + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_FUSE_H +#define _LINUX_FUSE_H +#include <stdint.h> +#define FUSE_KERNEL_VERSION 7 +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_KERNEL_MINOR_VERSION 22 +#define FUSE_ROOT_ID 1 +struct fuse_attr { + uint64_t ino; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t size; + uint64_t blocks; + uint64_t atime; + uint64_t mtime; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t ctime; + uint32_t atimensec; + uint32_t mtimensec; + uint32_t ctimensec; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t mode; + uint32_t nlink; + uint32_t uid; + uint32_t gid; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t rdev; + uint32_t blksize; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_kstatfs { + uint64_t blocks; + uint64_t bfree; + uint64_t bavail; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t files; + uint64_t ffree; + uint32_t bsize; + uint32_t namelen; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t frsize; + uint32_t padding; + uint32_t spare[6]; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_file_lock { + uint64_t start; + uint64_t end; + uint32_t type; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t pid; +}; +#define FATTR_MODE (1 << 0) +#define FATTR_UID (1 << 1) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FATTR_GID (1 << 2) +#define FATTR_SIZE (1 << 3) +#define FATTR_ATIME (1 << 4) +#define FATTR_MTIME (1 << 5) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FATTR_FH (1 << 6) +#define FATTR_ATIME_NOW (1 << 7) +#define FATTR_MTIME_NOW (1 << 8) +#define FATTR_LOCKOWNER (1 << 9) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FOPEN_DIRECT_IO (1 << 0) +#define FOPEN_KEEP_CACHE (1 << 1) +#define FOPEN_NONSEEKABLE (1 << 2) +#define FUSE_ASYNC_READ (1 << 0) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_POSIX_LOCKS (1 << 1) +#define FUSE_FILE_OPS (1 << 2) +#define FUSE_ATOMIC_O_TRUNC (1 << 3) +#define FUSE_EXPORT_SUPPORT (1 << 4) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_BIG_WRITES (1 << 5) +#define FUSE_DONT_MASK (1 << 6) +#define FUSE_SPLICE_WRITE (1 << 7) +#define FUSE_SPLICE_MOVE (1 << 8) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_SPLICE_READ (1 << 9) +#define FUSE_FLOCK_LOCKS (1 << 10) +#define FUSE_HAS_IOCTL_DIR (1 << 11) +#define FUSE_AUTO_INVAL_DATA (1 << 12) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_DO_READDIRPLUS (1 << 13) +#define FUSE_READDIRPLUS_AUTO (1 << 14) +#define FUSE_ASYNC_DIO (1 << 15) +#define CUSE_UNRESTRICTED_IOCTL (1 << 0) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_RELEASE_FLUSH (1 << 0) +#define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1) +#define FUSE_GETATTR_FH (1 << 0) +#define FUSE_LK_FLOCK (1 << 0) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_WRITE_CACHE (1 << 0) +#define FUSE_WRITE_LOCKOWNER (1 << 1) +#define FUSE_READ_LOCKOWNER (1 << 1) +#define FUSE_IOCTL_COMPAT (1 << 0) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_IOCTL_UNRESTRICTED (1 << 1) +#define FUSE_IOCTL_RETRY (1 << 2) +#define FUSE_IOCTL_32BIT (1 << 3) +#define FUSE_IOCTL_DIR (1 << 4) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_IOCTL_MAX_IOV 256 +#define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0) +enum fuse_opcode { + FUSE_LOOKUP = 1, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_FORGET = 2, + FUSE_GETATTR = 3, + FUSE_SETATTR = 4, + FUSE_READLINK = 5, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_SYMLINK = 6, + FUSE_MKNOD = 8, + FUSE_MKDIR = 9, + FUSE_UNLINK = 10, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_RMDIR = 11, + FUSE_RENAME = 12, + FUSE_LINK = 13, + FUSE_OPEN = 14, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_READ = 15, + FUSE_WRITE = 16, + FUSE_STATFS = 17, + FUSE_RELEASE = 18, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_FSYNC = 20, + FUSE_SETXATTR = 21, + FUSE_GETXATTR = 22, + FUSE_LISTXATTR = 23, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_REMOVEXATTR = 24, + FUSE_FLUSH = 25, + FUSE_INIT = 26, + FUSE_OPENDIR = 27, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_READDIR = 28, + FUSE_RELEASEDIR = 29, + FUSE_FSYNCDIR = 30, + FUSE_GETLK = 31, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_SETLK = 32, + FUSE_SETLKW = 33, + FUSE_ACCESS = 34, + FUSE_CREATE = 35, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_INTERRUPT = 36, + FUSE_BMAP = 37, + FUSE_DESTROY = 38, + FUSE_IOCTL = 39, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_POLL = 40, + FUSE_NOTIFY_REPLY = 41, + FUSE_BATCH_FORGET = 42, + FUSE_FALLOCATE = 43, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_READDIRPLUS = 44, + CUSE_INIT = 4096, +}; +enum fuse_notify_code { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_NOTIFY_POLL = 1, + FUSE_NOTIFY_INVAL_INODE = 2, + FUSE_NOTIFY_INVAL_ENTRY = 3, + FUSE_NOTIFY_STORE = 4, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + FUSE_NOTIFY_RETRIEVE = 5, + FUSE_NOTIFY_DELETE = 6, + FUSE_NOTIFY_CODE_MAX, +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_MIN_READ_BUFFER 8192 +#define FUSE_COMPAT_ENTRY_OUT_SIZE 120 +struct fuse_entry_out { + uint64_t nodeid; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t generation; + uint64_t entry_valid; + uint64_t attr_valid; + uint32_t entry_valid_nsec; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t attr_valid_nsec; + struct fuse_attr attr; +}; +struct fuse_forget_in { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t nlookup; +}; +struct fuse_forget_one { + uint64_t nodeid; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t nlookup; +}; +struct fuse_batch_forget_in { + uint32_t count; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t dummy; +}; +struct fuse_getattr_in { + uint32_t getattr_flags; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t dummy; + uint64_t fh; +}; +#define FUSE_COMPAT_ATTR_OUT_SIZE 96 +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_attr_out { + uint64_t attr_valid; + uint32_t attr_valid_nsec; + uint32_t dummy; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + struct fuse_attr attr; +}; +#define FUSE_COMPAT_MKNOD_IN_SIZE 8 +struct fuse_mknod_in { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t mode; + uint32_t rdev; + uint32_t umask; + uint32_t padding; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_mkdir_in { + uint32_t mode; + uint32_t umask; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_rename_in { + uint64_t newdir; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_link_in { + uint64_t oldnodeid; +}; +struct fuse_setattr_in { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t valid; + uint32_t padding; + uint64_t fh; + uint64_t size; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t lock_owner; + uint64_t atime; + uint64_t mtime; + uint64_t unused2; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t atimensec; + uint32_t mtimensec; + uint32_t unused3; + uint32_t mode; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t unused4; + uint32_t uid; + uint32_t gid; + uint32_t unused5; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_open_in { + uint32_t flags; + uint32_t unused; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_create_in { + uint32_t flags; + uint32_t mode; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t umask; + uint32_t padding; +}; +struct fuse_open_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t fh; + uint32_t open_flags; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_release_in { + uint64_t fh; + uint32_t flags; + uint32_t release_flags; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t lock_owner; +}; +struct fuse_flush_in { + uint64_t fh; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t unused; + uint32_t padding; + uint64_t lock_owner; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_read_in { + uint64_t fh; + uint64_t offset; + uint32_t size; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t read_flags; + uint64_t lock_owner; + uint32_t flags; + uint32_t padding; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +#define FUSE_COMPAT_WRITE_IN_SIZE 24 +struct fuse_write_in { + uint64_t fh; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t offset; + uint32_t size; + uint32_t write_flags; + uint64_t lock_owner; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t flags; + uint32_t padding; +}; +struct fuse_write_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t size; + uint32_t padding; +}; +#define FUSE_COMPAT_STATFS_SIZE 48 +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_statfs_out { + struct fuse_kstatfs st; +}; +struct fuse_fsync_in { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t fh; + uint32_t fsync_flags; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_setxattr_in { + uint32_t size; + uint32_t flags; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_getxattr_in { + uint32_t size; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_getxattr_out { + uint32_t size; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_lk_in { + uint64_t fh; + uint64_t owner; + struct fuse_file_lock lk; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t lk_flags; + uint32_t padding; +}; +struct fuse_lk_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + struct fuse_file_lock lk; +}; +struct fuse_access_in { + uint32_t mask; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t padding; +}; +struct fuse_init_in { + uint32_t major; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t minor; + uint32_t max_readahead; + uint32_t flags; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_init_out { + uint32_t major; + uint32_t minor; + uint32_t max_readahead; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t flags; + uint16_t max_background; + uint16_t congestion_threshold; + uint32_t max_write; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +#define CUSE_INIT_INFO_MAX 4096 +struct cuse_init_in { + uint32_t major; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t minor; + uint32_t unused; + uint32_t flags; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct cuse_init_out { + uint32_t major; + uint32_t minor; + uint32_t unused; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t flags; + uint32_t max_read; + uint32_t max_write; + uint32_t dev_major; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t dev_minor; + uint32_t spare[10]; +}; +struct fuse_interrupt_in { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t unique; +}; +struct fuse_bmap_in { + uint64_t block; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t blocksize; + uint32_t padding; +}; +struct fuse_bmap_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t block; +}; +struct fuse_ioctl_in { + uint64_t fh; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t flags; + uint32_t cmd; + uint64_t arg; + uint32_t in_size; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t out_size; +}; +struct fuse_ioctl_iovec { + uint64_t base; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t len; +}; +struct fuse_ioctl_out { + int32_t result; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t flags; + uint32_t in_iovs; + uint32_t out_iovs; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_poll_in { + uint64_t fh; + uint64_t kh; + uint32_t flags; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t events; +}; +struct fuse_poll_out { + uint32_t revents; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t padding; +}; +struct fuse_notify_poll_wakeup_out { + uint64_t kh; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_fallocate_in { + uint64_t fh; + uint64_t offset; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t length; + uint32_t mode; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_in_header { + uint32_t len; + uint32_t opcode; + uint64_t unique; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t nodeid; + uint32_t uid; + uint32_t gid; + uint32_t pid; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t padding; +}; +struct fuse_out_header { + uint32_t len; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + int32_t error; + uint64_t unique; +}; +struct fuse_dirent { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t ino; + uint64_t off; + uint32_t namelen; + uint32_t type; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + char name[]; +}; +#define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name) +#define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1)) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define FUSE_DIRENT_SIZE(d) FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen) +struct fuse_direntplus { + struct fuse_entry_out entry_out; + struct fuse_dirent dirent; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +#define FUSE_NAME_OFFSET_DIRENTPLUS offsetof(struct fuse_direntplus, dirent.name) +#define FUSE_DIRENTPLUS_SIZE(d) FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET_DIRENTPLUS + (d)->dirent.namelen) +struct fuse_notify_inval_inode_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t ino; + int64_t off; + int64_t len; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_notify_inval_entry_out { + uint64_t parent; + uint32_t namelen; + uint32_t padding; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_notify_delete_out { + uint64_t parent; + uint64_t child; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t namelen; + uint32_t padding; +}; +struct fuse_notify_store_out { +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t nodeid; + uint64_t offset; + uint32_t size; + uint32_t padding; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +struct fuse_notify_retrieve_out { + uint64_t notify_unique; + uint64_t nodeid; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint64_t offset; + uint32_t size; + uint32_t padding; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct fuse_notify_retrieve_in { + uint64_t dummy1; + uint64_t offset; + uint32_t size; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + uint32_t dummy2; + uint64_t dummy3; + uint64_t dummy4; +}; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#endif diff --git a/fuse_sideload.c b/fuse_sideload.c index ab91defbf..f5f20ea47 100644 --- a/fuse_sideload.c +++ b/fuse_sideload.c @@ -46,7 +46,7 @@ #include <errno.h> #include <fcntl.h> #include <limits.h> -#include <linux/fuse.h> +#include "fuse.h" #include <pthread.h> #include <stdio.h> #include <stdlib.h> diff --git a/gui/Android.mk b/gui/Android.mk index 479bc76f9..15a27a204 100644 --- a/gui/Android.mk +++ b/gui/Android.mk @@ -81,6 +81,11 @@ ifeq ($(TW_CUSTOM_THEME),) endif endif +# Auto filled build flag +ifeq ($(PLATFORM_VERSION), 5.0) + LOCAL_CFLAGS += -DANDROID_VERSION=5 +endif + LOCAL_C_INCLUDES += bionic external/stlport/stlport $(commands_recovery_local_path)/gui/devices/$(DEVICE_RESOLUTION) include $(BUILD_STATIC_LIBRARY) diff --git a/gui/pages.cpp b/gui/pages.cpp index bea39e902..b110e3820 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -39,8 +39,13 @@ extern "C" { #include "../twcommon.h" #include "../minuitwrp/minui.h" +#if (ANDROID_VERSION >= 5) #include "../minzip/SysUtil.h" #include "../minzip/Zip.h" +#else +#include "../minzipold/SysUtil.h" +#include "../minzipold/Zip.h" +#endif } #include "rapidxml.hpp" @@ -921,7 +926,9 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string char* xmlFile = NULL; PageSet* pageSet = NULL; int ret; +#if (ANDROID_VERSION >= 5) MemMapping map; +#endif // Open the XML file LOGINFO("Loading package: %s (%s)\n", name.c_str(), package.c_str()); @@ -948,6 +955,7 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string else { LOGINFO("Loading zip theme\n"); +#if (ANDROID_VERSION >= 5) if (!TWFunc::Path_Exists(package)) return -1; if (sysMapFile(package.c_str(), &map) != 0) { @@ -959,6 +967,12 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string sysReleaseMap(&map); return -1; } +#else + if (mzOpenZipArchive(package.c_str(), &zip)) { + LOGERR("Failed to open theme zip.\n"); + return -1; + } +#endif pZip = &zip; const ZipEntry* ui_xml = mzFindZipEntry(&zip, "ui.xml"); if (ui_xml == NULL) @@ -1006,7 +1020,9 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string if (pZip) { mzCloseZipArchive(pZip); +#if (ANDROID_VERSION >= 5) sysReleaseMap(&map); +#endif } return ret; @@ -1014,7 +1030,9 @@ error: LOGERR("An internal error has occurred.\n"); if (pZip) { mzCloseZipArchive(pZip); +#if (ANDROID_VERSION >= 5) sysReleaseMap(&map); +#endif } if (xmlFile) free(xmlFile); diff --git a/libmincrypt/Android.mk b/libmincrypt/Android.mk index fa6bc7884..774e9187a 100644 --- a/libmincrypt/Android.mk +++ b/libmincrypt/Android.mk @@ -4,6 +4,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypttwrp +LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(commands_recovery_local_path)/libmincrypt/includes LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c LOCAL_CFLAGS := -Wall -Werror @@ -11,6 +12,7 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypttwrp +LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(commands_recovery_local_path)/libmincrypt/includes LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c LOCAL_CFLAGS := -Wall -Werror @@ -18,6 +20,7 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypttwrp +LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(commands_recovery_local_path)/libmincrypt/includes LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c LOCAL_CFLAGS := -Wall -Werror diff --git a/minzipold/Android.mk b/minzipold/Android.mk index 0435c6afb..68485abe1 100644 --- a/minzipold/Android.mk +++ b/minzipold/Android.mk @@ -8,15 +8,11 @@ LOCAL_SRC_FILES := \ Inlines.c \ Zip.c -LOCAL_C_INCLUDES += \ +LOCAL_C_INCLUDES := \ external/zlib \ external/safe-iop/include -ifeq ($(HAVE_SELINUX),true) -LOCAL_C_INCLUDES += external/libselinux/include -LOCAL_STATIC_LIBRARIES += libselinux -LOCAL_CFLAGS += -DHAVE_SELINUX -endif +LOCAL_STATIC_LIBRARIES := libselinux LOCAL_MODULE := libminzip @@ -39,7 +35,7 @@ LOCAL_C_INCLUDES += \ external/zlib \ external/safe-iop/include -ifeq ($(HAVE_SELINUX),true) +ifeq ($(TWHAVE_SELINUX),true) LOCAL_C_INCLUDES += external/libselinux/include LOCAL_STATIC_LIBRARIES += libselinux LOCAL_CFLAGS += -DHAVE_SELINUX diff --git a/minzipold/DirUtil.c b/minzipold/DirUtil.c index 0d49b5780..8dd5da1da 100644 --- a/minzipold/DirUtil.c +++ b/minzipold/DirUtil.c @@ -145,24 +145,19 @@ dirCreateHierarchy(const char *path, int mode, } else if (ds == DMISSING) { int err; -#ifdef HAVE_SELINUX char *secontext = NULL; if (sehnd) { selabel_lookup(sehnd, &secontext, cpath, mode); setfscreatecon(secontext); } -#endif err = mkdir(cpath, mode); -#ifdef HAVE_SELINUX - if (secontext) { freecon(secontext); setfscreatecon(NULL); } -#endif if (err != 0) { free(cpath); diff --git a/minzipold/DirUtil.h b/minzipold/DirUtil.h index f8be64026..a5cfa761b 100644 --- a/minzipold/DirUtil.h +++ b/minzipold/DirUtil.h @@ -24,12 +24,8 @@ extern "C" { #endif -#ifdef HAVE_SELINUX #include <selinux/selinux.h> #include <selinux/label.h> -#else -struct selabel_handle; -#endif /* Like "mkdir -p", try to guarantee that all directories * specified in path are present, creating as many directories diff --git a/minzipold/SysUtil.c b/minzipold/SysUtil.c index 49a2522d6..31c76d6d4 100644 --- a/minzipold/SysUtil.c +++ b/minzipold/SysUtil.c @@ -95,16 +95,16 @@ int sysLoadFileInShmem(int fd, MemMapping* pMap) if (memPtr == NULL) return -1; - actual = read(fd, memPtr, length); + pMap->baseAddr = pMap->addr = memPtr; + pMap->baseLength = pMap->length = length; + + actual = TEMP_FAILURE_RETRY(read(fd, memPtr, length)); if (actual != length) { LOGE("only read %d of %d bytes\n", (int) actual, (int) length); sysReleaseShmem(pMap); return -1; } - pMap->baseAddr = pMap->addr = memPtr; - pMap->baseLength = pMap->length = length; - return 0; } diff --git a/minzipold/Zip.c b/minzipold/Zip.c index 54d5d55a3..439e5d9cd 100644 --- a/minzipold/Zip.c +++ b/minzipold/Zip.c @@ -985,6 +985,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive, unsigned int i; bool seenMatch = false; int ok = true; + int extractCount = 0; for (i = 0; i < pArchive->numEntries; i++) { ZipEntry *pEntry = pArchive->pEntries + i; if (pEntry->fileNameLen < zipDirLen) { @@ -1115,23 +1116,19 @@ bool mzExtractRecursive(const ZipArchive *pArchive, * Open the target for writing. */ -#ifdef HAVE_SELINUX char *secontext = NULL; if (sehnd) { selabel_lookup(sehnd, &secontext, targetFile, UNZIP_FILEMODE); setfscreatecon(secontext); } -#endif int fd = creat(targetFile, UNZIP_FILEMODE); -#ifdef HAVE_SELINUX if (secontext) { freecon(secontext); setfscreatecon(NULL); } -#endif if (fd < 0) { LOGE("Can't create target file \"%s\": %s\n", @@ -1154,13 +1151,16 @@ bool mzExtractRecursive(const ZipArchive *pArchive, break; } - LOGD("Extracted file \"%s\"\n", targetFile); + LOGV("Extracted file \"%s\"\n", targetFile); + ++extractCount; } } if (callback != NULL) callback(targetFile, cookie); } + LOGD("Extracted %d file(s)\n", extractCount); + free(helper.buf); free(zpath); diff --git a/minzipold/Zip.h b/minzipold/Zip.h index 4bb9ef6a4..c94282827 100644 --- a/minzipold/Zip.h +++ b/minzipold/Zip.h @@ -18,12 +18,8 @@ extern "C" { #endif -#ifdef HAVE_SELINUX #include <selinux/selinux.h> #include <selinux/label.h> -#else -struct selabel_handle; -#endif /* * One entry in the Zip archive. Treat this as opaque -- use accessors below. diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk index 7d860b00e..bb1a7c1d6 100644 --- a/prebuilt/Android.mk +++ b/prebuilt/Android.mk @@ -33,8 +33,6 @@ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/linker #RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/twrpmtp RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libc.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so -# Not available in 5.0 -#RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcorkscrew.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcrecovery.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libusbhost.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libgccdemangle.so @@ -61,12 +59,16 @@ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libmmcutils.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libbmlutils.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libflashutils.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libstlport.so -# libraries from lollipop RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libfusesideload.so -RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libbacktrace.so -RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libunwind.so -RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libunwind-ptrace.so -# end libraries from lollipop +ifeq ($(PLATFORM_VERSION), 5.0) + # libraries from lollipop + RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libbacktrace.so + RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libunwind.so + RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libunwind-ptrace.so +else + # Not available in lollipop + RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libcorkscrew.so +endif RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libmincrypttwrp.so RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/toolbox ifneq ($(TW_OEM_BUILD),true) @@ -143,9 +145,14 @@ ifneq ($(TW_EXCLUDE_ENCRYPTED_BACKUPS), true) RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libopenaes.so endif ifeq ($(TARGET_USERIMAGES_USE_F2FS), true) - RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/mkfs.f2fs + ifeq ($(PLATFORM_VERSION), 5.0) + RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/mkfs.f2fs + #RELINK_SOURCE_FILES += $(TARGET_ROOT_OUT_SBIN)/fibmap.f2fs + else + RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mkfs.f2fs + RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fibmap.f2fs + endif RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fsck.f2fs - #RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/fibmap.f2fs endif ifneq ($(wildcard system/core/reboot/Android.mk),) RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/reboot diff --git a/tests/Android.mk b/tests/Android.mk index 4d99d5249..0079be4c2 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -22,5 +22,6 @@ $(foreach file,$(test_src_files), \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/..) \ + $(eval LOCAL_MODULE_TAGS := optional) \ $(eval include $(BUILD_NATIVE_TEST)) \ -)
\ No newline at end of file +) diff --git a/toolbox/Android.mk b/toolbox/Android.mk index ad2e24c5c..2154479a4 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -1,6 +1,9 @@ LOCAL_PATH:= system/core/toolbox/ +ifeq ($(PLATFORM_VERSION), 5.0) + +# Rule for lollipop common_cflags := \ -std=gnu99 \ -Werror -Wno-unused-parameter \ @@ -187,3 +190,158 @@ SYMLINKS := # local module name ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \ $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS) + +else + +# Rule for older trees +LOCAL_PATH:= system/core/toolbox/ +include $(CLEAR_VARS) + +TOOLS := \ + start \ + stop \ + getprop \ + setprop + +# If busybox does not have SELinux support, provide these tools with toolbox. +# Note that RECOVERY_BUSYBOX_TOOLS will be empty if TW_USE_TOOLBOX == true. +ifeq ($(TWHAVE_SELINUX), true) + TOOLS_FOR_SELINUX := \ + ls \ + getenforce \ + setenforce \ + chcon \ + restorecon \ + runcon \ + getsebool \ + setsebool \ + load_policy + TOOLS += $(filter-out $(RECOVERY_BUSYBOX_TOOLS), $(TOOLS_FOR_SELINUX)) +endif + +ifeq ($(TW_USE_TOOLBOX), true) + TOOLS += \ + mount \ + cat \ + ps \ + kill \ + ln \ + insmod \ + rmmod \ + lsmod \ + ifconfig \ + setconsole \ + rm \ + mkdir \ + rmdir \ + getevent \ + sendevent \ + date \ + wipe \ + sync \ + umount \ + notify \ + cmp \ + dmesg \ + route \ + hd \ + dd \ + df \ + watchprops \ + log \ + sleep \ + renice \ + printenv \ + smd \ + chmod \ + chown \ + newfs_msdos \ + netstat \ + ioctl \ + mv \ + schedtop \ + top \ + iftop \ + id \ + uptime \ + vmstat \ + nandread \ + ionice \ + touch \ + lsof \ + du \ + md5 \ + clear \ + swapon \ + swapoff \ + mkswap \ + readlink + ifneq ($(TWHAVE_SELINUX), true) + TOOLS += ls + endif +endif + +LOCAL_SRC_FILES := \ + toolbox.c \ + $(patsubst %,%.c,$(TOOLS)) + +ifneq ($(wildcard system/core/toolbox/dynarray.c),) + LOCAL_SRC_FILES += dynarray.c +endif + +# reboot.c was removed in 4.4 kitkat +#TOOLS += reboot + +#ifeq ($(BOARD_USES_BOOTMENU),true) +# LOCAL_SRC_FILES += ../../../external/bootmenu/libreboot/reboot.c +#else +# LOCAL_SRC_FILES += reboot.c +#endif + +LOCAL_C_INCLUDES := bionic/libc/bionic + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + liblog \ + libc + +ifeq ($(TWHAVE_SELINUX), true) + LOCAL_SHARED_LIBRARIES += libselinux +endif + +LOCAL_MODULE := toolbox_recovery +LOCAL_MODULE_STEM := toolbox +LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin +LOCAL_MODULE_TAGS := optional + +# Including this will define $(intermediates). +# +include $(BUILD_EXECUTABLE) + +$(LOCAL_PATH)/toolbox.c: $(intermediates)/tools.h + +TOOLS_H := $(intermediates)/tools.h +$(TOOLS_H): PRIVATE_TOOLS := $(TOOLS) +$(TOOLS_H): PRIVATE_CUSTOM_TOOL = echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done +$(TOOLS_H): $(LOCAL_PATH)/Android.mk +$(TOOLS_H): + $(transform-generated-source) + +# Make #!/system/bin/toolbox launchers for each tool. +# +SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(TOOLS)) +$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE_STEM) +$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk + @echo "Symlink: $@ -> $(TOOLBOX_BINARY)" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf $(TOOLBOX_BINARY) $@ + +include $(CLEAR_VARS) +LOCAL_MODULE := toolbox_symlinks +LOCAL_MODULE_TAGS := optional +LOCAL_ADDITIONAL_DEPENDENCIES := $(SYMLINKS) +include $(BUILD_PHONY_PACKAGE) +SYMLINKS := + +endif diff --git a/twinstall.cpp b/twinstall.cpp index f18570186..01bd67278 100644 --- a/twinstall.cpp +++ b/twinstall.cpp @@ -31,16 +31,17 @@ #include "mincrypt/rsa.h" #include "mincrypt/sha.h" #include "minui/minui.h" -#ifdef HAVE_SELINUX +#include "mtdutils/mounts.h" +#include "mtdutils/mtdutils.h" +#if (ANDROID_VERSION >= 5) #include "minzip/SysUtil.h" #include "minzip/Zip.h" +#include "verifier.h" #else +#include "verifierold.h" #include "minzipold/SysUtil.h" #include "minzipold/Zip.h" #endif -#include "mtdutils/mounts.h" -#include "mtdutils/mtdutils.h" -#include "verifier.h" #include "variables.h" #include "data.hpp" #include "partitions.hpp" @@ -278,28 +279,44 @@ extern "C" int TWinstall_zip(const char* path, int* wipe_cache) { #endif DataManager::SetProgress(0); +#if (ANDROID_VERSION >= 5) MemMapping map; if (sysMapFile(path, &map) != 0) { LOGERR("Failed to sysMapFile '%s'\n", path); return -1; } +#endif if (zip_verify) { gui_print("Verifying zip signature...\n"); +#if (ANDROID_VERSION >= 5) ret_val = verify_file(map.addr, map.length); +#else + ret_val = verify_file(path); +#endif if (ret_val != VERIFY_SUCCESS) { LOGERR("Zip signature verification failed: %i\n", ret_val); +#if (ANDROID_VERSION >= 5) sysReleaseMap(&map); +#endif return -1; } } +#if (ANDROID_VERSION >= 5) ret_val = mzOpenZipArchive(map.addr, map.length, &Zip); +#else + ret_val = mzOpenZipArchive(path, &Zip); +#endif if (ret_val != 0) { LOGERR("Zip file is corrupt!\n", path); +#if (ANDROID_VERSION >= 5) sysReleaseMap(&map); +#endif return INSTALL_CORRUPT; } ret_val = Run_Update_Binary(path, &Zip, wipe_cache); +#if (ANDROID_VERSION >= 5) sysReleaseMap(&map); +#endif return ret_val; } diff --git a/twrp-functions.cpp b/twrp-functions.cpp index a2970b007..96114241f 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -525,12 +525,20 @@ int TWFunc::tw_reboot(RebootCommand command) return reboot(RB_AUTOBOOT); case rb_recovery: check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery"); +#ifdef ANDROID_RB_PROPERTY property_set(ANDROID_RB_PROPERTY, "reboot,recovery"); +#else + return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery"); +#endif sleep(5); return 0; case rb_bootloader: check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader"); +#ifdef ANDROID_RB_PROPERTY property_set(ANDROID_RB_PROPERTY, "reboot,bootloader"); +#else + return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader"); +#endif sleep(5); return 0; case rb_poweroff: @@ -541,7 +549,11 @@ int TWFunc::tw_reboot(RebootCommand command) return reboot(RB_POWER_OFF); case rb_download: check_and_run_script("/sbin/rebootdownload.sh", "reboot download"); +#ifdef ANDROID_RB_PROPERTY property_set(ANDROID_RB_PROPERTY, "reboot,download"); +#else + return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download"); +#endif sleep(5); return 0; default: diff --git a/uncrypt/Android.mk b/uncrypt/Android.mk index b8755fb08..e782ef43d 100644 --- a/uncrypt/Android.mk +++ b/uncrypt/Android.mk @@ -20,7 +20,7 @@ LOCAL_C_INCLUDES += $(commands_recovery_local_path) LOCAL_SRC_FILES := uncrypt.c LOCAL_MODULE := uncrypt - +LOCAL_MODULE_TAGS := optional LOCAL_STATIC_LIBRARIES := libfs_mgr liblog libcutils include $(BUILD_EXECUTABLE) diff --git a/verifierold.cpp b/verifierold.cpp new file mode 100644 index 000000000..4387ab5a4 --- /dev/null +++ b/verifierold.cpp @@ -0,0 +1,344 @@ +/* + * Copyright (C) 2008 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. + */ + +#include "common.h" +#include "verifierold.h" +#include "ui.h" + +#include "mincrypt/rsa.h" +#include "mincrypt/sha.h" +#include "mincrypt/sha256.h" + +#include <string.h> +#include <stdio.h> +#include <errno.h> + +//extern RecoveryUI* ui; + +#define PUBLIC_KEYS_FILE "/res/keys" + +// Look for an RSA signature embedded in the .ZIP file comment given +// the path to the zip. Verify it matches one of the given public +// keys. +// +// Return VERIFY_SUCCESS, VERIFY_FAILURE (if any error is encountered +// or no key matches the signature). +int verify_file(const char* path) { + //ui->SetProgress(0.0); + + int numKeys; + Certificate* pKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); + if (pKeys == NULL) { + LOGE("Failed to load keys\n"); + return INSTALL_CORRUPT; + } + LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); + + FILE* f = fopen(path, "rb"); + if (f == NULL) { + LOGE("failed to open %s (%s)\n", path, strerror(errno)); + return VERIFY_FAILURE; + } + + // An archive with a whole-file signature will end in six bytes: + // + // (2-byte signature start) $ff $ff (2-byte comment size) + // + // (As far as the ZIP format is concerned, these are part of the + // archive comment.) We start by reading this footer, this tells + // us how far back from the end we have to start reading to find + // the whole comment. + +#define FOOTER_SIZE 6 + + if (fseek(f, -FOOTER_SIZE, SEEK_END) != 0) { + LOGE("failed to seek in %s (%s)\n", path, strerror(errno)); + fclose(f); + return VERIFY_FAILURE; + } + + unsigned char footer[FOOTER_SIZE]; + if (fread(footer, 1, FOOTER_SIZE, f) != FOOTER_SIZE) { + LOGE("failed to read footer from %s (%s)\n", path, strerror(errno)); + fclose(f); + return VERIFY_FAILURE; + } + + if (footer[2] != 0xff || footer[3] != 0xff) { + LOGE("footer is wrong\n"); + fclose(f); + return VERIFY_FAILURE; + } + + size_t comment_size = footer[4] + (footer[5] << 8); + size_t signature_start = footer[0] + (footer[1] << 8); + LOGI("comment is %d bytes; signature %d bytes from end\n", + comment_size, signature_start); + + if (signature_start - FOOTER_SIZE < RSANUMBYTES) { + // "signature" block isn't big enough to contain an RSA block. + LOGE("signature is too short\n"); + fclose(f); + return VERIFY_FAILURE; + } + +#define EOCD_HEADER_SIZE 22 + + // The end-of-central-directory record is 22 bytes plus any + // comment length. + size_t eocd_size = comment_size + EOCD_HEADER_SIZE; + + if (fseek(f, -eocd_size, SEEK_END) != 0) { + LOGE("failed to seek in %s (%s)\n", path, strerror(errno)); + fclose(f); + return VERIFY_FAILURE; + } + + // Determine how much of the file is covered by the signature. + // This is everything except the signature data and length, which + // includes all of the EOCD except for the comment length field (2 + // bytes) and the comment data. + size_t signed_len = ftell(f) + EOCD_HEADER_SIZE - 2; + + unsigned char* eocd = (unsigned char*)malloc(eocd_size); + if (eocd == NULL) { + LOGE("malloc for EOCD record failed\n"); + fclose(f); + return VERIFY_FAILURE; + } + if (fread(eocd, 1, eocd_size, f) != eocd_size) { + LOGE("failed to read eocd from %s (%s)\n", path, strerror(errno)); + fclose(f); + return VERIFY_FAILURE; + } + + // If this is really is the EOCD record, it will begin with the + // magic number $50 $4b $05 $06. + if (eocd[0] != 0x50 || eocd[1] != 0x4b || + eocd[2] != 0x05 || eocd[3] != 0x06) { + LOGE("signature length doesn't match EOCD marker\n"); + fclose(f); + return VERIFY_FAILURE; + } + + size_t i; + for (i = 4; i < eocd_size-3; ++i) { + if (eocd[i ] == 0x50 && eocd[i+1] == 0x4b && + eocd[i+2] == 0x05 && eocd[i+3] == 0x06) { + // if the sequence $50 $4b $05 $06 appears anywhere after + // the real one, minzip will find the later (wrong) one, + // which could be exploitable. Fail verification if + // this sequence occurs anywhere after the real one. + LOGE("EOCD marker occurs after start of EOCD\n"); + fclose(f); + return VERIFY_FAILURE; + } + } + +#define BUFFER_SIZE 4096 + + bool need_sha1 = false; + bool need_sha256 = false; + for (i = 0; i < numKeys; ++i) { + switch (pKeys[i].hash_len) { + case SHA_DIGEST_SIZE: need_sha1 = true; break; + case SHA256_DIGEST_SIZE: need_sha256 = true; break; + } + } + + SHA_CTX sha1_ctx; + SHA256_CTX sha256_ctx; + SHA_init(&sha1_ctx); + SHA256_init(&sha256_ctx); + unsigned char* buffer = (unsigned char*)malloc(BUFFER_SIZE); + if (buffer == NULL) { + LOGE("failed to alloc memory for sha1 buffer\n"); + fclose(f); + return VERIFY_FAILURE; + } + + double frac = -1.0; + size_t so_far = 0; + fseek(f, 0, SEEK_SET); + while (so_far < signed_len) { + size_t size = BUFFER_SIZE; + if (signed_len - so_far < size) size = signed_len - so_far; + if (fread(buffer, 1, size, f) != size) { + LOGE("failed to read data from %s (%s)\n", path, strerror(errno)); + fclose(f); + return VERIFY_FAILURE; + } + if (need_sha1) SHA_update(&sha1_ctx, buffer, size); + if (need_sha256) SHA256_update(&sha256_ctx, buffer, size); + so_far += size; + double f = so_far / (double)signed_len; + if (f > frac + 0.02 || size == so_far) { + //ui->SetProgress(f); + frac = f; + } + } + fclose(f); + free(buffer); + + const uint8_t* sha1 = SHA_final(&sha1_ctx); + const uint8_t* sha256 = SHA256_final(&sha256_ctx); + + for (i = 0; i < numKeys; ++i) { + const uint8_t* hash; + switch (pKeys[i].hash_len) { + case SHA_DIGEST_SIZE: hash = sha1; break; + case SHA256_DIGEST_SIZE: hash = sha256; break; + default: continue; + } + + // The 6 bytes is the "(signature_start) $ff $ff (comment_size)" that + // the signing tool appends after the signature itself. + if (RSA_verify(pKeys[i].public_key, eocd + eocd_size - 6 - RSANUMBYTES, + RSANUMBYTES, hash, pKeys[i].hash_len)) { + LOGI("whole-file signature verified against key %d\n", i); + free(eocd); + return VERIFY_SUCCESS; + } else { + LOGI("failed to verify against key %d\n", i); + } + LOGI("i: %i, eocd_size: %i, RSANUMBYTES: %i\n", i, eocd_size, RSANUMBYTES); + } + free(eocd); + LOGE("failed to verify whole-file signature\n"); + return VERIFY_FAILURE; +} + +// Reads a file containing one or more public keys as produced by +// DumpPublicKey: this is an RSAPublicKey struct as it would appear +// as a C source literal, eg: +// +// "{64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}" +// +// For key versions newer than the original 2048-bit e=3 keys +// supported by Android, the string is preceded by a version +// identifier, eg: +// +// "v2 {64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}" +// +// (Note that the braces and commas in this example are actual +// characters the parser expects to find in the file; the ellipses +// indicate more numbers omitted from this example.) +// +// The file may contain multiple keys in this format, separated by +// commas. The last key must not be followed by a comma. +// +// A Certificate is a pair of an RSAPublicKey and a particular hash +// (we support SHA-1 and SHA-256; we store the hash length to signify +// which is being used). The hash used is implied by the version number. +// +// 1: 2048-bit RSA key with e=3 and SHA-1 hash +// 2: 2048-bit RSA key with e=65537 and SHA-1 hash +// 3: 2048-bit RSA key with e=3 and SHA-256 hash +// 4: 2048-bit RSA key with e=65537 and SHA-256 hash +// +// Returns NULL if the file failed to parse, or if it contain zero keys. +Certificate* +load_keys(const char* filename, int* numKeys) { + Certificate* out = NULL; + *numKeys = 0; + + FILE* f = fopen(filename, "r"); + if (f == NULL) { + LOGE("opening %s: %s\n", filename, strerror(errno)); + goto exit; + } + + { + int i; + bool done = false; + while (!done) { + ++*numKeys; + out = (Certificate*)realloc(out, *numKeys * sizeof(Certificate)); + Certificate* cert = out + (*numKeys - 1); + cert->public_key = (RSAPublicKey*)malloc(sizeof(RSAPublicKey)); + + char start_char; + if (fscanf(f, " %c", &start_char) != 1) goto exit; + if (start_char == '{') { + // a version 1 key has no version specifier. + cert->public_key->exponent = 3; + cert->hash_len = SHA_DIGEST_SIZE; + } else if (start_char == 'v') { + int version; + if (fscanf(f, "%d {", &version) != 1) goto exit; + switch (version) { + case 2: + cert->public_key->exponent = 65537; + cert->hash_len = SHA_DIGEST_SIZE; + break; + case 3: + cert->public_key->exponent = 3; + cert->hash_len = SHA256_DIGEST_SIZE; + break; + case 4: + cert->public_key->exponent = 65537; + cert->hash_len = SHA256_DIGEST_SIZE; + break; + default: + goto exit; + } + } + + RSAPublicKey* key = cert->public_key; + if (fscanf(f, " %i , 0x%x , { %u", + &(key->len), &(key->n0inv), &(key->n[0])) != 3) { + goto exit; + } + if (key->len != RSANUMWORDS) { + LOGE("key length (%d) does not match expected size\n", key->len); + goto exit; + } + for (i = 1; i < key->len; ++i) { + if (fscanf(f, " , %u", &(key->n[i])) != 1) goto exit; + } + if (fscanf(f, " } , { %u", &(key->rr[0])) != 1) goto exit; + for (i = 1; i < key->len; ++i) { + if (fscanf(f, " , %u", &(key->rr[i])) != 1) goto exit; + } + fscanf(f, " } } "); + + // if the line ends in a comma, this file has more keys. + switch (fgetc(f)) { + case ',': + // more keys to come. + break; + + case EOF: + done = true; + break; + + default: + LOGE("unexpected character between keys\n"); + goto exit; + } + LOGI("read key e=%d hash=%d\n", key->exponent, cert->hash_len); + } + } + + fclose(f); + return out; + +exit: + if (f) fclose(f); + free(out); + *numKeys = 0; + return NULL; +} diff --git a/verifierold.h b/verifierold.h new file mode 100644 index 000000000..d70417340 --- /dev/null +++ b/verifierold.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008 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 _RECOVERY_VERIFIER_H +#define _RECOVERY_VERIFIER_H + +#include "mincrypt/rsa.h" + +#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" + +enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT }; + +static const float VERIFICATION_PROGRESS_FRACTION = 0.25; + +typedef struct Certificate { + int hash_len; // SHA_DIGEST_SIZE (SHA-1) or SHA256_DIGEST_SIZE (SHA-256) + RSAPublicKey* public_key; +} Certificate; + +/* Look in the file for a signature footer, and verify that it + * matches one of the given keys. Return one of the constants below. + */ +int verify_file(const char* path); + +Certificate* load_keys(const char* filename, int* numKeys); + +#define VERIFY_SUCCESS 0 +#define VERIFY_FAILURE 1 + +#endif /* _RECOVERY_VERIFIER_H */ |