Skip to content

Commit

Permalink
优化描述文件的处理
Browse files Browse the repository at this point in the history
  • Loading branch information
DargonLee committed Sep 27, 2024
1 parent 4e13efc commit 007e11f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .run/cli.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="esign" />
<option name="PARAMETERS" value="sign -f $USER_HOME$/Downloads/Payload/DingTalk.app --bundle_id com.laiwang.DingTalk.app -o ./ -b" />
<option name="PARAMETERS" value="sign -f $USER_HOME$/Downloads/Payload3/GitHub.app -b" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion esign/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.1.0"
12 changes: 9 additions & 3 deletions esign/app_info_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def print_app_info(self):
self.logger.default(f"{key}: {value}")
except Exception as e:
self.logger.error(f"Failed to retrieve application information: {str(e)}")

def modify_bundle_id(self, new_bundle_id: str):
try:
self.logger.info(f"Modifying Bundle ID:")
Expand All @@ -61,7 +61,9 @@ def modify_bundle_name(self, new_bundle_name: str):
except Exception as e:
self.logger.error(f"Failed to modify Bundle Name: {str(e)}")


def delete_support_devices(self):
self._delete_item_value(self.info_plist_file_path, "UISupportedDevices")

def get_executable_name(self) -> str:
executable_name = self._get_plist_value(self.info_plist_file_path, "CFBundleExecutable")
return executable_name
Expand Down Expand Up @@ -118,4 +120,8 @@ def _set_plist_value(self, plist_path: str, key: str, value: str):

def _get_plist_value(self, plist_path: str, key: str) -> str:
cmd = f'/usr/libexec/PlistBuddy -c "Print :{key}" {plist_path}'
return subprocess.getoutput(cmd).strip()
return subprocess.getoutput(cmd).strip()

def _delete_item_value(self, plist_path: str, key: str):
cmd = f'/usr/libexec/PlistBuddy -c "Delete :{key}" {plist_path}'
subprocess.getoutput(cmd).strip()
4 changes: 2 additions & 2 deletions esign/app_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ async def _clean_app(self, app_path: str):
dir_path = os.path.join(app_path, dir_name)
if os.path.exists(dir_path):
shutil.rmtree(dir_path)
self.logger.default(f"Deleting directory: {dir_name}")
self.logger.default(f"Deleting: directory: {dir_name}")

for file_name in files_to_remove:
file_path = os.path.join(app_path, file_name)
if os.path.exists(file_path):
os.remove(file_path)
self.logger.default(f"Deleting file: {file_name}")
self.logger.default(f"Deleting: file: {file_name}")
2 changes: 1 addition & 1 deletion esign/app_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def resign(self, app_path: str, options: Dict[str, any]):
try:
payload_path, prepared_app_path = await self.app_preparer.prepare(app_path, options.get('no_clear_plugins'))
app_info_printer = AppInfoManager(prepared_app_path)

app_info_printer.delete_support_devices()
executable_name = app_info_printer.get_executable_name()
executable_path = os.path.join(prepared_app_path, executable_name)

Expand Down
2 changes: 1 addition & 1 deletion esign/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
'restore_symbol': args.symbol,
'install': args.install,
'reinstall': args.reinstall,
'clear_plugins': args.clear_plugins,
'no_clear_plugins': args.no_clear_plugins,
}
signer.run(args.file, options)
elif args.command == "update":
Expand Down
29 changes: 26 additions & 3 deletions esign/encryption_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import shutil
import subprocess
from turtle import st

from esign.elogger import Logger
from esign.econfig import ConfigHandler
Expand All @@ -21,6 +22,10 @@ async def check_encryption(self, executable_path: str, prepared_app_path: str) -
plugins_dir = os.path.join(prepared_app_path, "PlugIns")
if os.path.exists(plugins_dir):
await self.check_plugins_encryption(plugins_dir)
# 检查Frameworks是否加密
frameworks_dir = os.path.join(prepared_app_path, "Frameworks")
if os.path.exists(frameworks_dir):
await self.check_frameworks_encryption(frameworks_dir)
# 删除 unrestrict
await self.remove_unrestrict(executable_path)
return is_encrypted
Expand All @@ -33,14 +38,31 @@ async def check_app_encryption(self, executable_path: str, prepared_app_path: st
'otool -l {} | grep cryptid'.format(executable_path)
)
otool_cmd_result = subprocess.getoutput(otool_cmd)
self.logger.default(f"{otool_cmd_result.strip()}")
is_encrypted = 'cryptid 1' in otool_cmd_result
if is_encrypted and not prepared_app_path.endswith('PlugIns'):
is_invalid_path = any(substring in prepared_app_path for substring in ['PlugIns', 'Frameworks'])
if is_encrypted and not is_invalid_path:
raise EncryptionCheckError("The application is encrypted")
return is_encrypted
except Exception as e:
raise EncryptionCheckError(str(e))

async def check_frameworks_encryption(self, framework_dir: str):
try:
for framework in os.listdir(framework_dir):
framework_path = os.path.join(framework_dir, framework)
if os.path.isdir(framework_path):
framework_executable = os.path.splitext(framework)[0]
framework_executable_path = os.path.join(framework_path, framework_executable)
if os.path.exists(framework_executable_path):
is_encrypted = await self.check_app_encryption(framework_executable_path, framework_dir)
if is_encrypted:
self.logger.warning(f"Framework encrypted: {framework}")
else:
self.logger.default(f"Framework not encrypted: {framework} ")
except Exception as e:
raise EncryptionCheckError(f"An error occurred while checking the framework encryption status: {str(e)}")


async def check_plugins_encryption(self, plugins_dir: str):
try:
for plugin in os.listdir(plugins_dir):
Expand All @@ -51,8 +73,9 @@ async def check_plugins_encryption(self, plugins_dir: str):
if os.path.exists(plugin_executable_path):
is_encrypted = await self.check_app_encryption(plugin_executable_path, plugins_dir)
if is_encrypted:
self.logger.warning(f"Plugin {plugin} is encrypted and will be removed")
self.logger.warning(f"Plugin encrypted: {plugin} will be removed")
shutil.rmtree(plugin_path)
self.logger.default(f"PlugIn not encrypted: {plugin} ")
except Exception as e:
raise EncryptionCheckError(f"An error occurred while checking the plugin encryption status: {str(e)}")

Expand Down
8 changes: 4 additions & 4 deletions esign/entitlements_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ async def process(self, identity: str, app_path: str, provisioning_profile_path:

try:
entitlements = await self._extract_entitlements(provisioning_profile_path)
app_entitlements = await self._extract_app_entitlements(app_path)
# app_entitlements = await self._extract_app_entitlements(app_path)

# entitlements.update(app_entitlements)
for key, value in app_entitlements.items():
if key not in entitlements:
entitlements[key] = value
# for key, value in app_entitlements.items():
# if key not in entitlements:
# entitlements[key] = value

entitlements_path = await self._update_entitlements(entitlements)
shutil.copy(provisioning_profile_path, os.path.join(app_path, 'embedded.mobileprovision'))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run(self):
setup(
name="esign",
description="A command-line tool for re-signing iOS IPA files",
version="1.0.0",
version="1.1.0",
license="MIT",
author="Harlans",
author_email="[email protected]",
Expand Down

0 comments on commit 007e11f

Please sign in to comment.