diff options
Diffstat (limited to 'cmds/idmap')
-rw-r--r-- | cmds/idmap/create.cpp | 34 | ||||
-rw-r--r-- | cmds/idmap/idmap.cpp | 70 | ||||
-rw-r--r-- | cmds/idmap/idmap.h | 5 | ||||
-rw-r--r-- | cmds/idmap/inspect.cpp | 12 | ||||
-rw-r--r-- | cmds/idmap/scan.cpp | 2 |
5 files changed, 75 insertions, 48 deletions
diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp index 929f047..8c07eb0 100644 --- a/cmds/idmap/create.cpp +++ b/cmds/idmap/create.cpp @@ -153,26 +153,24 @@ fail: } int create_idmap(const char *target_apk_path, const char *overlay_apk_path, - uint32_t **data, size_t *size) + uint32_t target_hash, uint32_t overlay_hash, uint32_t **data, size_t *size) { uint32_t target_crc, overlay_crc; - if (get_zip_entry_crc(target_apk_path, AssetManager::RESOURCES_FILENAME, - &target_crc) == -1) { - return -1; - } - if (get_zip_entry_crc(overlay_apk_path, AssetManager::RESOURCES_FILENAME, - &overlay_crc) == -1) { - return -1; - } + + // In the original implementation, crc of the res tables are generated + // theme apks however do not need a restable, everything is in assets/ + // instead timestamps are used + target_crc = 0; + overlay_crc = 0; AssetManager am; bool b = am.createIdmap(target_apk_path, overlay_apk_path, target_crc, overlay_crc, - data, size); + target_hash, overlay_hash, data, size); return b ? 0 : -1; } int create_and_write_idmap(const char *target_apk_path, const char *overlay_apk_path, - int fd, bool check_if_stale) + uint32_t target_hash, uint32_t overlay_hash, int fd, bool check_if_stale) { if (check_if_stale) { if (!is_idmap_stale_fd(target_apk_path, overlay_apk_path, fd)) { @@ -184,7 +182,8 @@ fail: uint32_t *data = NULL; size_t size; - if (create_idmap(target_apk_path, overlay_apk_path, &data, &size) == -1) { + if (create_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash, + &data, &size) == -1) { return -1; } @@ -199,6 +198,7 @@ fail: } int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path, + uint32_t target_hash, uint32_t overlay_hash, const char *idmap_path) { if (!is_idmap_stale_path(target_apk_path, overlay_apk_path, idmap_path)) { @@ -211,7 +211,8 @@ int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path, return EXIT_FAILURE; } - int r = create_and_write_idmap(target_apk_path, overlay_apk_path, fd, false); + int r = create_and_write_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash, + fd, false); close(fd); if (r != 0) { unlink(idmap_path); @@ -219,8 +220,11 @@ int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path, return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, int fd) +int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, + uint32_t target_hash, uint32_t overlay_hash, + int fd) { - return create_and_write_idmap(target_apk_path, overlay_apk_path, fd, true) == 0 ? + return create_and_write_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash, + fd, true) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/cmds/idmap/idmap.cpp b/cmds/idmap/idmap.cpp index 90cfa2c..607cfd3 100644 --- a/cmds/idmap/idmap.cpp +++ b/cmds/idmap/idmap.cpp @@ -66,29 +66,31 @@ EXAMPLES \n\ Display an idmap file: \n\ \n\ $ adb shell idmap --inspect /data/resource-cache/vendor@overlay@overlay.apk@idmap \n\ - SECTION ENTRY VALUE COMMENT \n\ - IDMAP HEADER magic 0x706d6469 \n\ - base crc 0xb65a383f \n\ - overlay crc 0x7b9675e8 \n\ - base path .......... /path/to/target.apk \n\ - overlay path .......... /path/to/overlay.apk \n\ - DATA HEADER target pkg 0x0000007f \n\ - types count 0x00000003 \n\ - DATA BLOCK target type 0x00000002 \n\ - overlay type 0x00000002 \n\ - entry count 0x00000001 \n\ - entry offset 0x00000000 \n\ - entry 0x00000000 drawable/drawable \n\ - DATA BLOCK target type 0x00000003 \n\ - overlay type 0x00000003 \n\ - entry count 0x00000001 \n\ - entry offset 0x00000000 \n\ - entry 0x00000000 xml/integer \n\ - DATA BLOCK target type 0x00000004 \n\ - overlay type 0x00000004 \n\ - entry count 0x00000001 \n\ - entry offset 0x00000000 \n\ - entry 0x00000000 raw/lorem_ipsum \n\ + SECTION ENTRY VALUE COMMENT \n\ + IDMAP HEADER magic 0x706d6469 \n\ + base crc 0xb65a383f \n\ + overlay crc 0x7b9675e8 \n\ + base mtime 0x1eb47d51 \n\ + overlay mtime 0x185f87a2 \n\ + base path .......... /path/to/target.apk \n\ + overlay path .......... /path/to/overlay.apk \n\ + DATA HEADER target pkg 0x0000007f \n\ + types count 0x00000003 \n\ + DATA BLOCK target type 0x00000002 \n\ + overlay type 0x00000002 \n\ + entry count 0x00000001 \n\ + entry offset 0x00000000 \n\ + entry 0x00000000 drawable/drawable \n\ + DATA BLOCK target type 0x00000003 \n\ + overlay type 0x00000003 \n\ + entry count 0x00000001 \n\ + entry offset 0x00000000 \n\ + entry 0x00000000 xml/integer \n\ + DATA BLOCK target type 0x00000004 \n\ + overlay type 0x00000004 \n\ + entry count 0x00000001 \n\ + entry offset 0x00000000 \n\ + entry 0x00000000 raw/lorem_ipsum \n\ \n\ In this example, the overlay package provides three alternative resource values:\n\ drawable/drawable, xml/integer, and raw/lorem_ipsum \n\ @@ -120,7 +122,7 @@ NOTES \n\ } int maybe_create_fd(const char *target_apk_path, const char *overlay_apk_path, - const char *idmap_str) + const char *idmap_str, const char *target_hash_str, const char *overlay_hash_str) { // anyone (not just root or system) may do --fd -- the file has // already been opened by someone else on our behalf @@ -141,12 +143,15 @@ NOTES \n\ ALOGD("error: failed to read apk %s: %s\n", overlay_apk_path, strerror(errno)); return -1; } + int target_hash = strtol(target_hash_str, 0, 10); + int overlay_hash = strtol(overlay_hash_str, 0, 10); - return idmap_create_fd(target_apk_path, overlay_apk_path, idmap_fd); + return idmap_create_fd(target_apk_path, overlay_apk_path, target_hash, overlay_hash, + idmap_fd); } int maybe_create_path(const char *target_apk_path, const char *overlay_apk_path, - const char *idmap_path) + const char *idmap_path, const char *target_hash_str, const char *overlay_hash_str) { if (!verify_root_or_system()) { fprintf(stderr, "error: permission denied: not user root or user system\n"); @@ -163,7 +168,10 @@ NOTES \n\ return -1; } - return idmap_create_path(target_apk_path, overlay_apk_path, idmap_path); + int target_hash = strtol(target_hash_str, 0, 10); + int overlay_hash = strtol(overlay_hash_str, 0, 10); + return idmap_create_path(target_apk_path, overlay_apk_path, target_hash, overlay_hash, + idmap_path); } int maybe_scan(const char *overlay_dir, const char *target_package_name, @@ -222,12 +230,12 @@ int main(int argc, char **argv) return 0; } - if (argc == 5 && !strcmp(argv[1], "--fd")) { - return maybe_create_fd(argv[2], argv[3], argv[4]); + if (argc == 7 && !strcmp(argv[1], "--fd")) { + return maybe_create_fd(argv[2], argv[3], argv[4], argv[5], argv[6]); } - if (argc == 5 && !strcmp(argv[1], "--path")) { - return maybe_create_path(argv[2], argv[3], argv[4]); + if (argc == 7 && !strcmp(argv[1], "--path")) { + return maybe_create_path(argv[2], argv[3], argv[4], argv[5], argv[6]); } if (argc == 6 && !strcmp(argv[1], "--scan")) { diff --git a/cmds/idmap/idmap.h b/cmds/idmap/idmap.h index f507dd8..1794db7 100644 --- a/cmds/idmap/idmap.h +++ b/cmds/idmap/idmap.h @@ -19,9 +19,12 @@ #endif int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path, + uint32_t target_hash, uint32_t overlay_hash, const char *idmap_path); -int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, int fd); +int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, + uint32_t target_hash, uint32_t overlay_hash, + int fd); // Regarding target_package_name: the idmap_scan implementation should // be able to extract this from the manifest in target_apk_path, diff --git a/cmds/idmap/inspect.cpp b/cmds/idmap/inspect.cpp index f6afc85..a7844a9 100644 --- a/cmds/idmap/inspect.cpp +++ b/cmds/idmap/inspect.cpp @@ -200,6 +200,18 @@ namespace { } print("", "overlay crc", i, ""); + err = buf.nextUint32(&i); + if (err != NO_ERROR) { + return err; + } + print("", "base mtime", i, ""); + + err = buf.nextUint32(&i); + if (err != NO_ERROR) { + return err; + } + print("", "overlay mtime", i, ""); + err = buf.nextPath(path); if (err != NO_ERROR) { // printe done from IdmapBuffer::nextPath diff --git a/cmds/idmap/scan.cpp b/cmds/idmap/scan.cpp index 612a7eb..62ad6a9 100644 --- a/cmds/idmap/scan.cpp +++ b/cmds/idmap/scan.cpp @@ -203,7 +203,7 @@ int idmap_scan(const char *overlay_dir, const char *target_package_name, idmap_path.appendPath(flatten_path(overlay_apk_path + 1)); idmap_path.append("@idmap"); - if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) { + if (idmap_create_path(target_apk_path, overlay_apk_path, 0, 0, idmap_path.string()) != 0) { ALOGE("error: failed to create idmap for target=%s overlay=%s idmap=%s\n", target_apk_path, overlay_apk_path, idmap_path.string()); continue; |