summaryrefslogtreecommitdiffstats
path: root/applypatch/applypatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'applypatch/applypatch.c')
-rw-r--r--applypatch/applypatch.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/applypatch/applypatch.c b/applypatch/applypatch.c
index 9e631dd4f..60e9e4a5c 100644
--- a/applypatch/applypatch.c
+++ b/applypatch/applypatch.c
@@ -24,6 +24,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdbool.h>
#include "mincrypt/sha.h"
#include "applypatch.h"
@@ -44,14 +45,11 @@ static int GenerateTarget(FileContents* source_file,
static int mtd_partitions_scanned = 0;
-// Read a file into memory; optionally (retouch_flag == RETOUCH_DO_MASK) mask
-// the retouched entries back to their original value (such that SHA-1 checks
-// don't fail due to randomization); store the file contents and associated
+// Read a file into memory; store the file contents and associated
// metadata in *file.
//
// Return 0 on success.
-int LoadFileContents(const char* filename, FileContents* file,
- int retouch_flag) {
+int LoadFileContents(const char* filename, FileContents* file) {
file->data = NULL;
// A special 'filename' beginning with "MTD:" or "EMMC:" means to
@@ -87,20 +85,6 @@ int LoadFileContents(const char* filename, FileContents* file,
}
fclose(f);
- // apply_patch[_check] functions are blind to randomization. Randomization
- // is taken care of in [Undo]RetouchBinariesFn. If there is a mismatch
- // within a file, this means the file is assumed "corrupt" for simplicity.
- if (retouch_flag) {
- int32_t desired_offset = 0;
- if (retouch_mask_data(file->data, file->size,
- &desired_offset, NULL) != RETOUCH_DATA_MATCHED) {
- printf("error trying to mask retouch entries\n");
- free(file->data);
- file->data = NULL;
- return -1;
- }
- }
-
SHA_hash(file->data, file->size, file->sha1);
return 0;
}
@@ -579,7 +563,7 @@ int applypatch_check(const char* filename,
// LoadFileContents is successful. (Useful for reading
// partitions, where the filename encodes the sha1s; no need to
// check them twice.)
- if (LoadFileContents(filename, &file, RETOUCH_DO_MASK) != 0 ||
+ if (LoadFileContents(filename, &file) != 0 ||
(num_patches > 0 &&
FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0)) {
printf("file \"%s\" doesn't have any of expected "
@@ -594,7 +578,7 @@ int applypatch_check(const char* filename,
// exists and matches the sha1 we're looking for, the check still
// passes.
- if (LoadFileContents(CACHE_TEMP_SOURCE, &file, RETOUCH_DO_MASK) != 0) {
+ if (LoadFileContents(CACHE_TEMP_SOURCE, &file) != 0) {
printf("failed to load cache file\n");
return 1;
}
@@ -730,8 +714,7 @@ int applypatch(const char* source_filename,
const Value* copy_patch_value = NULL;
// We try to load the target file into the source_file object.
- if (LoadFileContents(target_filename, &source_file,
- RETOUCH_DO_MASK) == 0) {
+ if (LoadFileContents(target_filename, &source_file) == 0) {
if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
// The early-exit case: the patch was already applied, this file
// has the desired hash, nothing for us to do.
@@ -750,8 +733,7 @@ int applypatch(const char* source_filename,
// target file, or we did but it's different from the source file.
free(source_file.data);
source_file.data = NULL;
- LoadFileContents(source_filename, &source_file,
- RETOUCH_DO_MASK);
+ LoadFileContents(source_filename, &source_file);
}
if (source_file.data != NULL) {
@@ -767,8 +749,7 @@ int applypatch(const char* source_filename,
source_file.data = NULL;
printf("source file is bad; trying copy\n");
- if (LoadFileContents(CACHE_TEMP_SOURCE, &copy_file,
- RETOUCH_DO_MASK) < 0) {
+ if (LoadFileContents(CACHE_TEMP_SOURCE, &copy_file) < 0) {
// fail.
printf("failed to read copy file\n");
return 1;