From 2d2f6fef13de40d1cf7fee7d9bc5273b2bbc7098 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Mon, 22 Aug 2022 15:36:19 -0700 Subject: [PATCH] Try and read the elf header Accidently removed file reads to check elf headers, add code to do so back. Signed-off-by: William Douglas --- elf-move.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/elf-move.py b/elf-move.py index 5861598..a3a9aee 100755 --- a/elf-move.py +++ b/elf-move.py @@ -59,19 +59,21 @@ def process_install(args): virtpath = os.path.join('/', filepath.removeprefix(args.installdir)) - # some files have the same contents so include the full path - # in the hash - sha.update(virtpath.encode()) - sha.update(args.btype.encode()) - elf = memv[:4] == b'\x7fELF' - if elf or virtpath in args.path: - filemap[virtpath] = [True, - filepath, - sha.hexdigest()] - else: - filemap[virtpath] = [False, - filepath, - sha.hexdigest()] + with open(filepath, 'rb', buffering=0) as ifile: + ifile.readinto(memv) + # some files have the same contents so include the full path + # in the hash + sha.update(virtpath.encode()) + sha.update(args.btype.encode()) + elf = memv[:4] == b'\x7fELF' + if elf or virtpath in args.path: + filemap[virtpath] = [True, + filepath, + sha.hexdigest()] + else: + filemap[virtpath] = [False, + filepath, + sha.hexdigest()] return filemap