Skip to content

Commit

Permalink
[Normal] Support android
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdWindScholar committed Feb 23, 2024
1 parent b2525c8 commit 082b003
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contextpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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():
Expand All @@ -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]
Expand Down
11 changes: 11 additions & 0 deletions imgextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 082b003

Please sign in to comment.