diff --git a/contextpatch.py b/contextpatch.py index bc17658..593caec 100644 --- a/contextpatch.py +++ b/contextpatch.py @@ -5,6 +5,8 @@ from re import escape fix_permission = { + "system/app/*/.apk": "u:object_r:system_file:s0", + "data-app/.apk": "u:object_r:system_file:s0", "android.hardware.wifi": "u:object_r:hal_wifi_default_exec:s0", "bin/idmap": "u:object_r:idmap_exec:s0", "bin/fsck": "u:object_r:fsck_exec:s0", @@ -52,7 +54,7 @@ def context_patch(fs_file, dir_path) -> tuple: # 接收两个字典对比 add_new = 0 print("ContextPatcher: Load origin %d" % (len(fs_file.keys())) + " entries") # 定义默认SeLinux标签 - permission_d = [f'u:object_r:{os.path.basename(dir_path)}_file:s0'] + permission_d = [f'u:object_r:{os.path.basename(dir_path).replace("_a", "")}_file:s0'] for i in scan_dir(os.path.abspath(dir_path)): # 把不可打印字符替换为* if not i.isprintable(): @@ -78,7 +80,7 @@ def context_patch(fs_file, dir_path) -> tuple: # 接收两个字典对比 permission = [fix_permission[f]] if not permission: for e in fs_file.keys(): - if SequenceMatcher(None, (path := os.path.dirname(i)), e).quick_ratio() >= 0.85: + if SequenceMatcher(None, (path := os.path.dirname(i)), e).quick_ratio() >= 0.75: if e == path: continue permission = fs_file[e] diff --git a/imgextractor.py b/imgextractor.py index 52f3447..04c784e 100644 --- a/imgextractor.py +++ b/imgextractor.py @@ -92,6 +92,9 @@ def scan_dir(root_inode, root_path=""): continue entry_inode = root_inode.volume.get_inode(entry_inode_idx, entry_type) entry_inode_path = root_path + '/' + entry_name + if entry_inode_path[-1:] == '/' and not entry_inode.is_dir: + continue + mode = self.__get_perm(entry_inode.mode_str) uid = entry_inode.inode.i_uid gid = entry_inode.inode.i_gid @@ -258,6 +261,14 @@ def main(self, target: str, output_dir: str, work: str, target_type: str = 'img' self.OUTPUT_IMAGE_FILE = (os.path.realpath(os.path.dirname(target)) + os.sep) + os.path.basename(target) self.FileName = self.__out_name(os.path.basename(target), out=0) self.CONFING_DIR = work + os.sep + 'config' + with open(self.OUTPUT_IMAGE_FILE, 'rb+') as file: + mount = ext4.Volume(file).get_mount_point + if mount[:1] == '/': + mount = mount[1:] + if self.__out_name(os.path.basename(output_dir)) != mount: + print(f"[N]:Your File Name Not Right , We will Extract {self.OUTPUT_IMAGE_FILE} to {mount}") + self.EXTRACT_DIR = os.path.realpath(os.path.dirname(output_dir)) + os.sep + mount + self.FileName = mount if target_type == 's_img': simg2img(target) target_type = 'img'