From d2e8ecc646d407d9df9b3367d8975c9920c2c5de Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 10 Jun 2018 17:57:40 +0800 Subject: [PATCH] Fix error return code when patching dtb --- native/jni/utils/pattern.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/native/jni/utils/pattern.c b/native/jni/utils/pattern.c index f69a3630a..c5dba1e72 100644 --- a/native/jni/utils/pattern.c +++ b/native/jni/utils/pattern.c @@ -59,15 +59,18 @@ void patch_init_rc(void **buf, size_t *size) { } int patch_verity(void **buf, uint32_t *size, int patch) { - int skip, src_size = *size; + int skip, src_size = *size, found = 0; char *src = *buf, *patched = patch ? xcalloc(src_size, 1) : NULL; for (int read = 0, write = 0; read < src_size; ++read, ++write) { if ((skip = check_verity_pattern(src + read)) > 0) { - if (!patch) - return 1; - fprintf(stderr, "Remove pattern [%.*s]\n", skip, src + read); + if (patch) { + fprintf(stderr, "Remove pattern [%.*s]\n", skip, src + read); + *size -= skip; + } else { + fprintf(stderr, "Found pattern [%.*s]\n", skip, src + read); + } read += skip; - *size -= skip; + found = 1; } if (patch) patched[write] = src[read]; @@ -76,7 +79,7 @@ int patch_verity(void **buf, uint32_t *size, int patch) { free(*buf); *buf = patched; } - return 0; + return found; } void patch_encryption(void **buf, uint32_t *size) {