diff options
| author | 2024-11-12 22:40:28 +0000 | |
|---|---|---|
| committer | 2024-11-12 22:40:28 +0000 | |
| commit | c23c6f8e70998d336fb8e55d615f1a985f8ccc51 (patch) | |
| tree | 4be9249c66a3fdda70a4476fd3e7c56ab8169c61 | |
| parent | 103062efbfbd3666cbf99f7e4483363588e950fe (diff) | |
| parent | 4fe0c9b80dff17eb8704e9708deb5dc2c5444a5b (diff) | |
Merge "Separate out ELF header reading function" into main am: 4fe0c9b80d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3344841
Change-Id: I33ca7857881b5ac700dac3744fef9c69450fcdc9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | core/jni/com_android_internal_content_FileSystemUtils.cpp | 19 | ||||
| -rw-r--r-- | core/jni/com_android_internal_content_FileSystemUtils.h | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/core/jni/com_android_internal_content_FileSystemUtils.cpp b/core/jni/com_android_internal_content_FileSystemUtils.cpp index 6c72544a7958..76ead2a3ca31 100644 --- a/core/jni/com_android_internal_content_FileSystemUtils.cpp +++ b/core/jni/com_android_internal_content_FileSystemUtils.cpp @@ -22,7 +22,6 @@ #include <android-base/hex.h> #include <android-base/unique_fd.h> #include <bionic/macros.h> -#include <elf.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> @@ -204,7 +203,8 @@ bool punchHoles(const char *filePath, const uint64_t offset, return true; } -bool punchHolesInElf64(const char *filePath, const uint64_t offset) { +bool getLoadSegmentPhdrs(const char *filePath, const uint64_t offset, + std::vector<Elf64_Phdr> &programHeaders) { // Open Elf file Elf64_Ehdr ehdr; std::ifstream inputStream(filePath, std::ifstream::in); @@ -227,11 +227,6 @@ bool punchHolesInElf64(const char *filePath, const uint64_t offset) { uint64_t programHeaderOffset = ehdr.e_phoff; uint16_t programHeaderNum = ehdr.e_phnum; - IF_ALOGD() { - ALOGD("Punching holes in file: %s programHeaderOffset: %" PRIu64 " programHeaderNum: %hu", - filePath, programHeaderOffset, programHeaderNum); - } - // if this is a zip file, also consider elf offset inside a file uint64_t phOffset; if (__builtin_add_overflow(offset, programHeaderOffset, &phOffset)) { @@ -240,7 +235,6 @@ bool punchHolesInElf64(const char *filePath, const uint64_t offset) { } inputStream.seekg(phOffset); - std::vector<Elf64_Phdr> programHeaders; for (int headerIndex = 0; headerIndex < programHeaderNum; headerIndex++) { Elf64_Phdr header; inputStream.read((char *)&header, sizeof(header)); @@ -254,6 +248,15 @@ bool punchHolesInElf64(const char *filePath, const uint64_t offset) { programHeaders.push_back(header); } + return true; +} + +bool punchHolesInElf64(const char *filePath, const uint64_t offset) { + std::vector<Elf64_Phdr> programHeaders; + if (!getLoadSegmentPhdrs(filePath, offset, programHeaders)) { + ALOGE("Failed to read program headers from ELF file."); + return false; + } return punchHoles(filePath, offset, programHeaders); } diff --git a/core/jni/com_android_internal_content_FileSystemUtils.h b/core/jni/com_android_internal_content_FileSystemUtils.h index 52445e2b4229..4a95686c5a0c 100644 --- a/core/jni/com_android_internal_content_FileSystemUtils.h +++ b/core/jni/com_android_internal_content_FileSystemUtils.h @@ -15,8 +15,11 @@ */ #pragma once +#include <elf.h> #include <sys/types.h> +#include <vector> + namespace android { /* @@ -35,4 +38,11 @@ bool punchHolesInElf64(const char* filePath, uint64_t offset); */ bool punchHolesInZip(const char* filePath, uint64_t offset, uint16_t extraFieldLen); +/* + * This function reads program headers from ELF file. ELF can be specified with file path directly + * or it should be at offset inside Apk. Program headers passed to function is populated. + */ +bool getLoadSegmentPhdrs(const char* filePath, const uint64_t offset, + std::vector<Elf64_Phdr>& programHeaders); + } // namespace android
\ No newline at end of file |