ipsw-parser 1.4.4__tar.gz → 1.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.github/workflows/python-app.yml +1 -1
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.github/workflows/python-publish.yml +2 -2
- ipsw_parser-1.5.0/.pre-commit-config.yaml +9 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/PKG-INFO +2 -1
- ipsw_parser-1.5.0/ipsw_parser/__main__.py +99 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/_version.py +16 -3
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/build_identity.py +52 -70
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/build_manifest.py +21 -20
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/component.py +16 -8
- ipsw_parser-1.5.0/ipsw_parser/dsc.py +83 -0
- ipsw_parser-1.5.0/ipsw_parser/firmware.py +39 -0
- ipsw_parser-1.5.0/ipsw_parser/ipsw.py +147 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/PKG-INFO +2 -1
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/SOURCES.txt +1 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/pyproject.toml +50 -0
- ipsw_parser-1.4.4/.pre-commit-config.yaml +0 -14
- ipsw_parser-1.4.4/ipsw_parser/__main__.py +0 -95
- ipsw_parser-1.4.4/ipsw_parser/firmware.py +0 -39
- ipsw_parser-1.4.4/ipsw_parser/ipsw.py +0 -132
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.gitattributes +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.github/workflows/codeql.yml +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/.gitignore +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/CODE_OF_CONDUCT.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/LICENSE +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/README.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/__init__.py +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser/exceptions.py +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/dependency_links.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/entry_points.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/requires.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/ipsw_parser.egg-info/top_level.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/pytest.ini +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/requirements.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.5.0}/setup.cfg +0 -0
|
@@ -13,9 +13,9 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
|
|
15
15
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
17
|
- name: Set up Python
|
|
18
|
-
uses: actions/setup-python@
|
|
18
|
+
uses: actions/setup-python@v4
|
|
19
19
|
with:
|
|
20
20
|
python-version: '3.x'
|
|
21
21
|
- name: Install dependencies
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ipsw-parser
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: python3 utility for parsing and extracting data from IPSW
|
|
5
5
|
Author-email: doronz88 <doron88@gmail.com>
|
|
6
6
|
Maintainer-email: doronz88 <doron88@gmail.com>
|
|
@@ -690,6 +690,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
690
690
|
Classifier: Programming Language :: Python :: 3.11
|
|
691
691
|
Classifier: Programming Language :: Python :: 3.12
|
|
692
692
|
Classifier: Programming Language :: Python :: 3.13
|
|
693
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
693
694
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
694
695
|
Requires-Python: >=3.9
|
|
695
696
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
from zipfile import ZipFile
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
import coloredlogs
|
|
9
|
+
from remotezip2 import RemoteZip
|
|
10
|
+
|
|
11
|
+
from ipsw_parser.ipsw import IPSW
|
|
12
|
+
|
|
13
|
+
coloredlogs.install(level=logging.DEBUG)
|
|
14
|
+
|
|
15
|
+
logging.getLogger("asyncio").disabled = True
|
|
16
|
+
logging.getLogger("parso.cache").disabled = True
|
|
17
|
+
logging.getLogger("parso.cache.pickle").disabled = True
|
|
18
|
+
logging.getLogger("parso.python.diff").disabled = True
|
|
19
|
+
logging.getLogger("humanfriendly.prompts").disabled = True
|
|
20
|
+
logging.getLogger("blib2to3.pgen2.driver").disabled = True
|
|
21
|
+
logging.getLogger("urllib3.connectionpool").disabled = True
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
PEM_DB_ENV_VAR = "IPSW_PARSER_PEM_DB"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def handle_ipsw_argument(ctx: click.Context, param: click.Argument, value: str) -> IPSW:
|
|
29
|
+
if value.startswith("http://") or value.startswith("https://"):
|
|
30
|
+
return IPSW(RemoteZip(value))
|
|
31
|
+
return IPSW(ZipFile(Path(value).expanduser()))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
ipsw_argument = click.argument("ipsw", callback=handle_ipsw_argument)
|
|
35
|
+
pem_db_option = click.option(
|
|
36
|
+
"--pem-db",
|
|
37
|
+
envvar=PEM_DB_ENV_VAR,
|
|
38
|
+
help="Path DB file url (can be either a filesystem path or an HTTP URL). "
|
|
39
|
+
"Alternatively, use the IPSW_PARSER_PEM_DB envvar.",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@click.group()
|
|
44
|
+
def cli() -> None:
|
|
45
|
+
"""CLI utility for extracting info from IPSW files"""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@cli.command("info")
|
|
50
|
+
@ipsw_argument
|
|
51
|
+
def info(ipsw) -> None:
|
|
52
|
+
"""Parse given .ipsw basic info"""
|
|
53
|
+
print(f"SupportedProductTypes: {ipsw.build_manifest.supported_product_types}")
|
|
54
|
+
print(f"ProductVersion: {ipsw.build_manifest.product_version}")
|
|
55
|
+
print(f"ProductBuildVersion: {ipsw.build_manifest.product_build_version}")
|
|
56
|
+
|
|
57
|
+
development_files = ipsw.get_development_files()
|
|
58
|
+
if development_files:
|
|
59
|
+
print("DevelopmentFiles:")
|
|
60
|
+
for file in development_files:
|
|
61
|
+
print(f"- {file}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@cli.command("extract")
|
|
65
|
+
@ipsw_argument
|
|
66
|
+
@click.argument("output", type=click.Path(exists=False))
|
|
67
|
+
@pem_db_option
|
|
68
|
+
def extract(ipsw: IPSW, output: str, pem_db: Optional[str]) -> None:
|
|
69
|
+
"""Extract .ipsw into filesystem layout"""
|
|
70
|
+
output = Path(output)
|
|
71
|
+
|
|
72
|
+
if not output.exists():
|
|
73
|
+
output.mkdir(parents=True, exist_ok=True)
|
|
74
|
+
|
|
75
|
+
ipsw.build_manifest.build_identities[0].extract(output, pem_db=pem_db)
|
|
76
|
+
ipsw.archive.extractall(
|
|
77
|
+
path=output, members=[f for f in ipsw.archive.filelist if f.filename.startswith("Firmware")]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@cli.command("extract-kernel")
|
|
82
|
+
@ipsw_argument
|
|
83
|
+
@click.argument("output", type=click.Path(exists=False))
|
|
84
|
+
@click.option("--arch", help="Arch name to extract using lipo")
|
|
85
|
+
def extract_kernel(ipsw: IPSW, output: str, arch: Optional[str]) -> None:
|
|
86
|
+
"""Extract kernelcache from given .ipsw into given output filename"""
|
|
87
|
+
Path(output).write_bytes(ipsw.build_manifest.build_identities[0].get_kernelcache_payload(arch=arch))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@cli.command("device-support")
|
|
91
|
+
@ipsw_argument
|
|
92
|
+
@pem_db_option
|
|
93
|
+
def device_support(ipsw: IPSW, pem_db: Optional[str]) -> None:
|
|
94
|
+
"""Create DeviceSupport directory"""
|
|
95
|
+
ipsw.create_device_support(pem_db=pem_db)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
cli()
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# file generated by setuptools-scm
|
|
2
2
|
# don't change, don't track in version control
|
|
3
3
|
|
|
4
|
-
__all__ = [
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
5
12
|
|
|
6
13
|
TYPE_CHECKING = False
|
|
7
14
|
if TYPE_CHECKING:
|
|
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
|
|
|
9
16
|
from typing import Union
|
|
10
17
|
|
|
11
18
|
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
12
20
|
else:
|
|
13
21
|
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
14
23
|
|
|
15
24
|
version: str
|
|
16
25
|
__version__: str
|
|
17
26
|
__version_tuple__: VERSION_TUPLE
|
|
18
27
|
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
19
30
|
|
|
20
|
-
__version__ = version = '1.
|
|
21
|
-
__version_tuple__ = version_tuple = (1,
|
|
31
|
+
__version__ = version = '1.5.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 5, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'gd02ef0cd1'
|
|
@@ -13,74 +13,56 @@ from plumbum import ProcessExecutionError, local
|
|
|
13
13
|
from pyimg4 import IM4P
|
|
14
14
|
|
|
15
15
|
from ipsw_parser.component import Component
|
|
16
|
+
from ipsw_parser.dsc import split_dsc
|
|
16
17
|
|
|
17
18
|
logger = logging.getLogger(__name__)
|
|
18
19
|
|
|
19
|
-
AEA_MAGIC = b
|
|
20
|
+
AEA_MAGIC = b"AEA1"
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def extract_as(zipf: ZipFile, member_name, output_path, chunk_size=64 * 1024):
|
|
23
24
|
"""Extract a single member from a ZIP archive to a custom output path"""
|
|
24
25
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
|
25
|
-
with zipf.open(member_name) as source, open(output_path,
|
|
26
|
+
with zipf.open(member_name) as source, open(output_path, "wb") as target:
|
|
26
27
|
shutil.copyfileobj(source, target, length=chunk_size)
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
def _extract_dmg(dmg: Path, output: Path, sub_path: Optional[Path] = None, pem_db: Optional[str] = None) -> None:
|
|
30
|
-
ipsw = local[
|
|
31
|
-
hdiutil = local[
|
|
31
|
+
ipsw = local["ipsw"]
|
|
32
|
+
hdiutil = local["hdiutil"]
|
|
32
33
|
# darwin system statistically have problems cleaning up after detaching the mountpoint
|
|
33
34
|
with TemporaryDirectory() as temp_dir:
|
|
34
35
|
temp_dir = Path(temp_dir)
|
|
35
|
-
mnt = temp_dir /
|
|
36
|
+
mnt = temp_dir / "mnt"
|
|
36
37
|
mnt.mkdir()
|
|
37
38
|
|
|
38
|
-
with dmg.open(
|
|
39
|
+
with dmg.open("rb") as f:
|
|
39
40
|
magic = f.read(len(AEA_MAGIC))
|
|
40
41
|
if magic == AEA_MAGIC:
|
|
41
|
-
logger.debug(
|
|
42
|
-
aea_dmg = str(dmg.absolute()) +
|
|
42
|
+
logger.debug("Found Apple Encrypted Archive. Decrypting...")
|
|
43
|
+
aea_dmg = str(dmg.absolute()) + ".aea"
|
|
43
44
|
dmg.rename(aea_dmg)
|
|
44
|
-
dmg = temp_dir / Path(aea_dmg).name.rsplit(
|
|
45
|
-
args = [
|
|
45
|
+
dmg = temp_dir / Path(aea_dmg).name.rsplit(".", 1)[0]
|
|
46
|
+
args = ["fw", "aea", aea_dmg, "-o", temp_dir]
|
|
46
47
|
if pem_db is not None:
|
|
47
|
-
if
|
|
48
|
+
if "://" in pem_db:
|
|
48
49
|
# create a local file containing it
|
|
49
|
-
temp_pem_db = temp_dir /
|
|
50
|
+
temp_pem_db = temp_dir / "pem-db.json"
|
|
50
51
|
temp_pem_db.write_text(requests.get(pem_db, verify=False).text)
|
|
51
52
|
pem_db = temp_pem_db
|
|
52
|
-
args += [
|
|
53
|
+
args += ["--pem-db", pem_db]
|
|
53
54
|
ipsw(args)
|
|
54
55
|
|
|
55
|
-
hdiutil(
|
|
56
|
+
hdiutil("attach", "-mountpoint", mnt, dmg)
|
|
56
57
|
|
|
57
58
|
try:
|
|
58
|
-
if sub_path is None
|
|
59
|
-
src = mnt
|
|
60
|
-
else:
|
|
61
|
-
src = mnt / sub_path
|
|
59
|
+
src = mnt if sub_path is None else mnt / sub_path
|
|
62
60
|
shutil.copytree(src, output, symlinks=True, dirs_exist_ok=True)
|
|
63
61
|
except shutil.Error:
|
|
64
62
|
# when overwriting the same files, some of them don't contain write permissions
|
|
65
63
|
pass
|
|
66
64
|
|
|
67
|
-
hdiutil(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def _split_dsc(root: Path) -> None:
|
|
71
|
-
ipsw = local['ipsw']
|
|
72
|
-
dsc_paths = [
|
|
73
|
-
root / 'System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64',
|
|
74
|
-
root / 'System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e',
|
|
75
|
-
root / 'private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64',
|
|
76
|
-
root / 'private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e']
|
|
77
|
-
|
|
78
|
-
for dsc in dsc_paths:
|
|
79
|
-
if not dsc.exists():
|
|
80
|
-
continue
|
|
81
|
-
|
|
82
|
-
logger.info(f'splitting DSC: {dsc}')
|
|
83
|
-
ipsw('dyld', 'split', dsc, '-o', root)
|
|
65
|
+
hdiutil("detach", "-force", mnt)
|
|
84
66
|
|
|
85
67
|
|
|
86
68
|
class BuildIdentity(UserDict):
|
|
@@ -90,30 +72,30 @@ class BuildIdentity(UserDict):
|
|
|
90
72
|
|
|
91
73
|
@cached_property
|
|
92
74
|
def device_class(self) -> str:
|
|
93
|
-
return self[
|
|
75
|
+
return self["Info"]["DeviceClass"].lower()
|
|
94
76
|
|
|
95
77
|
@cached_property
|
|
96
78
|
def restore_behavior(self) -> str:
|
|
97
|
-
return self[
|
|
79
|
+
return self["Info"].get("RestoreBehavior")
|
|
98
80
|
|
|
99
81
|
@cached_property
|
|
100
82
|
def variant(self):
|
|
101
|
-
return self[
|
|
83
|
+
return self["Info"].get("Variant")
|
|
102
84
|
|
|
103
85
|
@cached_property
|
|
104
86
|
def macos_variant(self) -> str:
|
|
105
|
-
return self[
|
|
87
|
+
return self["Info"].get("MacOSVariant")
|
|
106
88
|
|
|
107
89
|
@cached_property
|
|
108
90
|
def manifest(self) -> dict:
|
|
109
|
-
return self[
|
|
91
|
+
return self["Manifest"]
|
|
110
92
|
|
|
111
93
|
@cached_property
|
|
112
94
|
def minimum_system_partition(self):
|
|
113
|
-
return self[
|
|
95
|
+
return self["Info"].get("MinimumSystemPartition")
|
|
114
96
|
|
|
115
97
|
def get_component_path(self, component: str) -> str:
|
|
116
|
-
return self.manifest[component][
|
|
98
|
+
return self.manifest[component]["Info"]["Path"]
|
|
117
99
|
|
|
118
100
|
def has_component(self, name: str) -> bool:
|
|
119
101
|
return name in self.manifest
|
|
@@ -121,79 +103,79 @@ class BuildIdentity(UserDict):
|
|
|
121
103
|
def get_component(self, name: str, **args) -> Component:
|
|
122
104
|
return Component(self, name, **args)
|
|
123
105
|
|
|
124
|
-
def extract_dsc(self, output: Path, pem_db: Optional[str] = None) -> None:
|
|
106
|
+
def extract_dsc(self, output: Path, pem_db: Optional[str] = None, split: bool = True) -> None:
|
|
125
107
|
build_identity = self.build_manifest.build_identities[0]
|
|
126
|
-
if not build_identity.has_component(
|
|
108
|
+
if not build_identity.has_component("Cryptex1,SystemOS"):
|
|
127
109
|
return
|
|
128
110
|
|
|
129
|
-
device_support_symbols_path = output /
|
|
111
|
+
device_support_symbols_path = output / "private/preboot/Cryptexes/OS/System"
|
|
130
112
|
device_support_symbols_path.mkdir(parents=True, exist_ok=True)
|
|
131
113
|
|
|
132
114
|
with TemporaryDirectory() as temp_dir:
|
|
133
|
-
system_os = Path(temp_dir) /
|
|
134
|
-
system_os_component_path = build_identity.get_component_path(
|
|
115
|
+
system_os = Path(temp_dir) / "system_os.dmg"
|
|
116
|
+
system_os_component_path = build_identity.get_component_path("Cryptex1,SystemOS")
|
|
135
117
|
extract_as(self.build_manifest.ipsw.archive, system_os_component_path, system_os)
|
|
136
|
-
_extract_dmg(system_os, device_support_symbols_path,
|
|
137
|
-
|
|
138
|
-
|
|
118
|
+
_extract_dmg(system_os, device_support_symbols_path, sub_path=Path("System"), pem_db=pem_db)
|
|
119
|
+
if split:
|
|
120
|
+
split_dsc(output)
|
|
139
121
|
|
|
140
122
|
def get_kernelcache_payload(self, arch: Optional[str] = None) -> bytes:
|
|
141
|
-
im4p = IM4P(self.build_manifest.build_identities[0].get_component(
|
|
123
|
+
im4p = IM4P(self.build_manifest.build_identities[0].get_component("KernelCache").data)
|
|
142
124
|
im4p.payload.decompress()
|
|
143
125
|
payload = im4p.payload.output().data
|
|
144
126
|
if arch is None:
|
|
145
127
|
return payload
|
|
146
128
|
|
|
147
129
|
with TemporaryDirectory() as temp_dir:
|
|
148
|
-
kernel_output = Path(temp_dir) /
|
|
149
|
-
local[
|
|
150
|
-
return Path(next(kernel_output.parent.glob(f
|
|
130
|
+
kernel_output = Path(temp_dir) / "kernel"
|
|
131
|
+
local["ipsw"]("macho", "lipo", "-a", arch, kernel_output)
|
|
132
|
+
return Path(next(kernel_output.parent.glob(f"*.{arch}"))).read_bytes()
|
|
151
133
|
|
|
152
134
|
def extract(self, output: Path, pem_db: Optional[str] = None) -> None:
|
|
153
|
-
logger.info(f
|
|
135
|
+
logger.info(f"extracting into: {output}")
|
|
154
136
|
|
|
155
137
|
build_identity = self.build_manifest.build_identities[0]
|
|
156
138
|
|
|
157
|
-
logger.info(f
|
|
139
|
+
logger.info(f"extracting OS into: {output}")
|
|
158
140
|
with TemporaryDirectory() as temp_dir:
|
|
159
|
-
os_dmg = Path(temp_dir) /
|
|
160
|
-
os_component_path = build_identity.get_component_path(
|
|
141
|
+
os_dmg = Path(temp_dir) / "os.dmg"
|
|
142
|
+
os_component_path = build_identity.get_component_path("OS")
|
|
161
143
|
extract_as(self.build_manifest.ipsw.archive, os_component_path, os_dmg)
|
|
162
144
|
_extract_dmg(os_dmg, output, pem_db=pem_db)
|
|
163
145
|
|
|
164
|
-
kernel_component = build_identity.get_component(
|
|
146
|
+
kernel_component = build_identity.get_component("KernelCache")
|
|
165
147
|
kernel_path = Path(kernel_component.path)
|
|
166
|
-
kernel_output = output /
|
|
148
|
+
kernel_output = output / "System/Library/Caches/com.apple.kernelcaches" / kernel_path.parts[-1]
|
|
167
149
|
kernel_output.parent.mkdir(parents=True, exist_ok=True)
|
|
168
150
|
|
|
169
|
-
logger.info(f
|
|
151
|
+
logger.info(f"extracting kernel into: {kernel_output}")
|
|
170
152
|
im4p = IM4P(kernel_component.data)
|
|
171
153
|
im4p.payload.decompress()
|
|
172
154
|
kernel_output.write_bytes(im4p.payload.output().data)
|
|
173
155
|
try:
|
|
174
156
|
# In case the kernel is a FAT image, extract the arm64 macho
|
|
175
|
-
local[
|
|
176
|
-
|
|
157
|
+
local["ipsw"]("macho", "lipo", "-a", "arm64", kernel_output)
|
|
158
|
+
next(iter(kernel_output.parent.glob("*.arm64"))).rename(kernel_output)
|
|
177
159
|
except ProcessExecutionError:
|
|
178
160
|
pass
|
|
179
161
|
|
|
180
|
-
for cryptex in (
|
|
162
|
+
for cryptex in ("App", "OS"):
|
|
181
163
|
name = {
|
|
182
|
-
|
|
183
|
-
|
|
164
|
+
"App": "Cryptex1,AppOS",
|
|
165
|
+
"OS": "Cryptex1,SystemOS",
|
|
184
166
|
}[cryptex]
|
|
185
167
|
|
|
186
168
|
if not build_identity.has_component(name):
|
|
187
169
|
continue
|
|
188
170
|
|
|
189
|
-
cryptex_path = output /
|
|
171
|
+
cryptex_path = output / "private/preboot/Cryptexes" / cryptex
|
|
190
172
|
cryptex_path.mkdir(parents=True, exist_ok=True)
|
|
191
173
|
|
|
192
|
-
logger.info(f
|
|
174
|
+
logger.info(f"extracting {name} into: {cryptex_path}")
|
|
193
175
|
with TemporaryDirectory() as temp_dir:
|
|
194
|
-
temp_component = (Path(temp_dir) / name).with_suffix(
|
|
176
|
+
temp_component = (Path(temp_dir) / name).with_suffix(".dmg")
|
|
195
177
|
component_path = build_identity.get_component_path(name)
|
|
196
178
|
extract_as(self.build_manifest.ipsw.archive, component_path, temp_component)
|
|
197
179
|
_extract_dmg(temp_component, cryptex_path, pem_db=pem_db)
|
|
198
180
|
|
|
199
|
-
|
|
181
|
+
split_dsc(output)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import plistlib
|
|
2
|
+
from typing import Optional
|
|
2
3
|
|
|
3
4
|
from cached_property import cached_property
|
|
4
5
|
|
|
@@ -14,8 +15,8 @@ class BuildManifest:
|
|
|
14
15
|
|
|
15
16
|
@cached_property
|
|
16
17
|
def build_major(self) -> int:
|
|
17
|
-
build_major =
|
|
18
|
-
for i in self._manifest[
|
|
18
|
+
build_major = ""
|
|
19
|
+
for i in self._manifest["ProductBuildVersion"]:
|
|
19
20
|
if i.isdigit():
|
|
20
21
|
build_major += i
|
|
21
22
|
else:
|
|
@@ -25,45 +26,45 @@ class BuildManifest:
|
|
|
25
26
|
|
|
26
27
|
@cached_property
|
|
27
28
|
def supported_product_types(self) -> list[str]:
|
|
28
|
-
return self._manifest[
|
|
29
|
+
return self._manifest["SupportedProductTypes"]
|
|
29
30
|
|
|
30
31
|
@cached_property
|
|
31
32
|
def supported_product_types_family(self) -> str:
|
|
32
33
|
product = self.supported_product_types[0]
|
|
33
|
-
if product.startswith(
|
|
34
|
-
return
|
|
35
|
-
elif product.startswith(
|
|
36
|
-
return
|
|
37
|
-
elif
|
|
38
|
-
return
|
|
34
|
+
if product.startswith("iBridge"):
|
|
35
|
+
return "iBridge"
|
|
36
|
+
elif product.startswith("iPhone"):
|
|
37
|
+
return "iPhone"
|
|
38
|
+
elif "Mac" in product:
|
|
39
|
+
return "Mac"
|
|
39
40
|
else:
|
|
40
41
|
raise ValueError()
|
|
41
42
|
|
|
42
43
|
@cached_property
|
|
43
44
|
def product_version(self) -> str:
|
|
44
|
-
return self._manifest[
|
|
45
|
+
return self._manifest["ProductVersion"]
|
|
45
46
|
|
|
46
47
|
@cached_property
|
|
47
48
|
def product_build_version(self) -> str:
|
|
48
|
-
return self._manifest[
|
|
49
|
+
return self._manifest["ProductBuildVersion"]
|
|
49
50
|
|
|
50
|
-
def get_build_identity(
|
|
51
|
+
def get_build_identity(
|
|
52
|
+
self, device_class: str, restore_behavior: Optional[str] = None, variant: Optional[str] = None
|
|
53
|
+
) -> BuildIdentity:
|
|
51
54
|
for build_identity in self.build_identities:
|
|
52
|
-
if variant is not None:
|
|
53
|
-
|
|
54
|
-
continue
|
|
55
|
+
if variant is not None and variant not in build_identity.variant:
|
|
56
|
+
continue
|
|
55
57
|
|
|
56
58
|
if build_identity.device_class != device_class:
|
|
57
59
|
continue
|
|
58
60
|
|
|
59
|
-
if restore_behavior is not None:
|
|
60
|
-
|
|
61
|
-
continue
|
|
61
|
+
if restore_behavior is not None and build_identity.restore_behavior != restore_behavior:
|
|
62
|
+
continue
|
|
62
63
|
|
|
63
64
|
return build_identity
|
|
64
|
-
raise NoSuchBuildIdentityError(
|
|
65
|
+
raise NoSuchBuildIdentityError("failed to find the correct BuildIdentity from the BuildManifest")
|
|
65
66
|
|
|
66
67
|
def _parse_build_identities(self) -> None:
|
|
67
68
|
self.build_identities = []
|
|
68
|
-
for build_identity in self._manifest[
|
|
69
|
+
for build_identity in self._manifest["BuildIdentities"]:
|
|
69
70
|
self.build_identities.append(BuildIdentity(self, build_identity))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os.path
|
|
3
|
+
from typing import Optional
|
|
3
4
|
|
|
4
5
|
from cached_property import cached_property
|
|
5
6
|
|
|
@@ -9,27 +10,34 @@ from ipsw_parser.exceptions import IpswException
|
|
|
9
10
|
class TSSResponse(dict):
|
|
10
11
|
@property
|
|
11
12
|
def ap_img4_ticket(self):
|
|
12
|
-
ticket = self.get(
|
|
13
|
+
ticket = self.get("ApImg4Ticket")
|
|
13
14
|
|
|
14
15
|
if ticket is None:
|
|
15
|
-
raise IpswException(
|
|
16
|
+
raise IpswException("TSS response doesn't contain a ApImg4Ticket")
|
|
16
17
|
|
|
17
18
|
return ticket
|
|
18
19
|
|
|
19
20
|
@property
|
|
20
21
|
def bb_ticket(self):
|
|
21
|
-
return self.get(
|
|
22
|
+
return self.get("BBTicket")
|
|
22
23
|
|
|
23
24
|
def get_path_by_entry(self, component: str):
|
|
24
25
|
node = self.get(component)
|
|
25
26
|
if node is not None:
|
|
26
|
-
return node.get(
|
|
27
|
+
return node.get("Path")
|
|
27
28
|
|
|
28
29
|
return None
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
class Component:
|
|
32
|
-
def __init__(
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
build_identity,
|
|
36
|
+
name: str,
|
|
37
|
+
tss: TSSResponse = None,
|
|
38
|
+
data: Optional[bytes] = None,
|
|
39
|
+
path: Optional[str] = None,
|
|
40
|
+
):
|
|
33
41
|
self.logger = logging.getLogger(__name__)
|
|
34
42
|
self._tss = tss
|
|
35
43
|
self.build_identity = build_identity
|
|
@@ -47,19 +55,19 @@ class Component:
|
|
|
47
55
|
path = self._tss.get_path_by_entry(self.name)
|
|
48
56
|
|
|
49
57
|
if path is None:
|
|
50
|
-
self.logger.debug(f
|
|
58
|
+
self.logger.debug(f"NOTE: No path for component {self.name} in TSS, will fetch from build_identity")
|
|
51
59
|
|
|
52
60
|
if path is None:
|
|
53
61
|
path = self.build_identity.get_component_path(self.name)
|
|
54
62
|
|
|
55
63
|
if path is None:
|
|
56
|
-
raise IpswException(f
|
|
64
|
+
raise IpswException(f"Failed to find component path for: {self.name}")
|
|
57
65
|
|
|
58
66
|
return path
|
|
59
67
|
|
|
60
68
|
@cached_property
|
|
61
69
|
def data(self) -> bytes:
|
|
62
70
|
if self._data is None:
|
|
63
|
-
self.logger.debug(f
|
|
71
|
+
self.logger.debug(f"Extracting {os.path.basename(self.path)} ({self.path})")
|
|
64
72
|
return self.build_identity.build_manifest.ipsw.read(self.path)
|
|
65
73
|
return self._data
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import plistlib
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from plumbum import local
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def split_dsc(root: Path) -> None:
|
|
12
|
+
ipsw = local["ipsw"]
|
|
13
|
+
dsc_paths = [
|
|
14
|
+
root / "System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64",
|
|
15
|
+
root / "System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e",
|
|
16
|
+
root / "private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64",
|
|
17
|
+
root / "private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
for dsc in dsc_paths:
|
|
21
|
+
if not dsc.exists():
|
|
22
|
+
continue
|
|
23
|
+
|
|
24
|
+
logger.info(f"splitting DSC: {dsc}")
|
|
25
|
+
ipsw("dyld", "split", dsc, "-o", root)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_device_support_path(product_type: str, product_version: str, product_build_version: str) -> Path:
|
|
29
|
+
"""
|
|
30
|
+
Construct the device support directory path.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
product_type: Product type (e.g., 'iPhone15,2')
|
|
34
|
+
product_version: Product version (e.g., '16.0')
|
|
35
|
+
product_build_version: Product build version (e.g., '20A362')
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Path to the device support directory
|
|
39
|
+
"""
|
|
40
|
+
device_support_path = Path("~/Library/Developer/Xcode/iOS DeviceSupport").expanduser()
|
|
41
|
+
device_support_path /= f"{product_type} {product_version} ({product_build_version})"
|
|
42
|
+
return device_support_path
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def create_device_support_layout(
|
|
46
|
+
product_type: str, product_version: str, product_build_version: str, root_path: Path
|
|
47
|
+
) -> Path:
|
|
48
|
+
"""
|
|
49
|
+
Split DSC and create the "device support" directory layout.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
product_type: Product type (e.g., 'iPhone15,2')
|
|
53
|
+
product_version: Product version (e.g., '16.0')
|
|
54
|
+
product_build_version: Product build version (e.g., '20A362')
|
|
55
|
+
root_path: System root path containing the extracted DSC symbols
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Path to the created device support directory
|
|
59
|
+
"""
|
|
60
|
+
device_support_path = get_device_support_path(product_type, product_version, product_build_version)
|
|
61
|
+
|
|
62
|
+
# Split DSC files
|
|
63
|
+
split_dsc(root_path)
|
|
64
|
+
|
|
65
|
+
# Clean up the cryptex DSC files after splitting
|
|
66
|
+
cryptex_dsc_dir = root_path / "private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld"
|
|
67
|
+
if cryptex_dsc_dir.exists():
|
|
68
|
+
for file in cryptex_dsc_dir.iterdir():
|
|
69
|
+
file.unlink()
|
|
70
|
+
|
|
71
|
+
# Create the device support metadata files
|
|
72
|
+
(device_support_path / "Info.plist").write_bytes(
|
|
73
|
+
plistlib.dumps({
|
|
74
|
+
"DSC Extractor Version": "1228.0.0.0.0",
|
|
75
|
+
"DateCollected": datetime.now(),
|
|
76
|
+
"Version": "16.0",
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
(device_support_path / ".finalized").write_bytes(plistlib.dumps({}))
|
|
80
|
+
(device_support_path / ".processed_dyld_shared_cache_arm64e").touch()
|
|
81
|
+
(device_support_path / ".processing_lock").touch()
|
|
82
|
+
|
|
83
|
+
return device_support_path
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Firmware:
|
|
2
|
+
def __init__(self, firmware_path: str, ipsw):
|
|
3
|
+
self._ipsw = ipsw
|
|
4
|
+
self._firmware_path = firmware_path
|
|
5
|
+
self._manifest_data = self._ipsw.read(self.get_relative_path("manifest"))
|
|
6
|
+
self._firmware_files = {}
|
|
7
|
+
for filename in self._manifest_data.splitlines():
|
|
8
|
+
filename = filename.strip()
|
|
9
|
+
component_name = self.get_component_name(filename)
|
|
10
|
+
self._firmware_files[component_name] = f"{firmware_path}/{filename}"
|
|
11
|
+
|
|
12
|
+
def get_relative_path(self, path: str):
|
|
13
|
+
return f"{self._firmware_path}/{path}"
|
|
14
|
+
|
|
15
|
+
def get_files(self):
|
|
16
|
+
return self._firmware_files
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def get_component_name(filename):
|
|
20
|
+
names = {
|
|
21
|
+
"LLB": "LLB",
|
|
22
|
+
"iBoot": "iBoot",
|
|
23
|
+
"DeviceTree": "DeviceTree",
|
|
24
|
+
"applelogo": "AppleLogo",
|
|
25
|
+
"liquiddetect": "Liquid",
|
|
26
|
+
"lowpowermode": "LowPowerWallet0",
|
|
27
|
+
"recoverymode": "RecoveryMode",
|
|
28
|
+
"batterylow0": "BatteryLow0",
|
|
29
|
+
"batterylow1": "BatteryLow1",
|
|
30
|
+
"glyphcharging": "BatteryCharging",
|
|
31
|
+
"glyphplugin": "BatteryPlugin",
|
|
32
|
+
"batterycharging0": "BatteryCharging0",
|
|
33
|
+
"batterycharging1": "BatteryCharging1",
|
|
34
|
+
"batteryfull": "BatteryFull",
|
|
35
|
+
"needservice": "NeedService",
|
|
36
|
+
"SCAB": "SCAB",
|
|
37
|
+
"sep-firmware": "RestoreSEP",
|
|
38
|
+
}
|
|
39
|
+
return names.get(filename)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import zipfile
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from cached_property import cached_property
|
|
8
|
+
from construct import Const, Default, PaddedString, Struct
|
|
9
|
+
|
|
10
|
+
from ipsw_parser.build_manifest import BuildManifest
|
|
11
|
+
from ipsw_parser.dsc import create_device_support_layout
|
|
12
|
+
from ipsw_parser.firmware import Firmware
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
cpio_odc_header = Struct(
|
|
17
|
+
"c_magic" / Const("070707", PaddedString(6, "utf8")),
|
|
18
|
+
"c_dev"
|
|
19
|
+
/ Default(
|
|
20
|
+
PaddedString(6, "utf8"),
|
|
21
|
+
"0" * 6,
|
|
22
|
+
),
|
|
23
|
+
"c_ino" / PaddedString(6, "utf8"),
|
|
24
|
+
"c_mode" / PaddedString(6, "utf8"),
|
|
25
|
+
"c_uid" / Default(PaddedString(6, "utf8"), "0" * 6),
|
|
26
|
+
"c_gid" / Default(PaddedString(6, "utf8"), "0" * 6),
|
|
27
|
+
"c_nlink" / PaddedString(6, "utf8"),
|
|
28
|
+
"c_rdev" / Default(PaddedString(6, "utf8"), "0" * 6),
|
|
29
|
+
"c_mtime" / Default(PaddedString(11, "utf8"), "0" * 11),
|
|
30
|
+
"c_namesize" / PaddedString(6, "utf8"),
|
|
31
|
+
"c_filesize" / Default(PaddedString(11, "utf8"), "0" * 11),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class IPSW:
|
|
36
|
+
def __init__(self, archive: zipfile.ZipFile):
|
|
37
|
+
self.archive = archive
|
|
38
|
+
self._logger = logging.getLogger(__file__)
|
|
39
|
+
self.build_manifest = BuildManifest(
|
|
40
|
+
self,
|
|
41
|
+
self.archive.read(
|
|
42
|
+
next(f for f in self.archive.namelist() if f.startswith("BuildManifest") and f.endswith(".plist"))
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
@cached_property
|
|
47
|
+
def restore_version(self) -> bytes:
|
|
48
|
+
return self.read("RestoreVersion.plist")
|
|
49
|
+
|
|
50
|
+
@cached_property
|
|
51
|
+
def system_version(self) -> bytes:
|
|
52
|
+
return self.read("SystemVersion.plist")
|
|
53
|
+
|
|
54
|
+
@cached_property
|
|
55
|
+
def filelist(self) -> list[zipfile.ZipInfo]:
|
|
56
|
+
return self.archive.filelist
|
|
57
|
+
|
|
58
|
+
@contextmanager
|
|
59
|
+
def open_path(self, path: str):
|
|
60
|
+
file = self.archive.open(path)
|
|
61
|
+
try:
|
|
62
|
+
yield file
|
|
63
|
+
finally:
|
|
64
|
+
file.close()
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def bootability(self) -> bytes:
|
|
68
|
+
result = b""
|
|
69
|
+
prefix = "BootabilityBundle/Restore/Bootability/"
|
|
70
|
+
inode = 1
|
|
71
|
+
nlink = 1
|
|
72
|
+
|
|
73
|
+
for e in self.filelist:
|
|
74
|
+
if e.filename == "BootabilityBundle/Restore/Firmware/Bootability.dmg.trustcache":
|
|
75
|
+
subpath = "Bootability.trustcache"
|
|
76
|
+
elif not e.filename.startswith(prefix):
|
|
77
|
+
continue
|
|
78
|
+
else:
|
|
79
|
+
subpath = e.filename[len(prefix) :]
|
|
80
|
+
|
|
81
|
+
self._logger.debug(f"BootabilityBundle: adding {subpath}")
|
|
82
|
+
|
|
83
|
+
filename = subpath
|
|
84
|
+
filename = f"{filename}\0".encode()
|
|
85
|
+
mode = e.external_attr >> 16
|
|
86
|
+
result += cpio_odc_header.build({
|
|
87
|
+
"c_ino": f"{inode:06o}",
|
|
88
|
+
"c_nlink": f"{nlink:06o}",
|
|
89
|
+
"c_mode": f"{mode:06o}",
|
|
90
|
+
"c_namesize": f"{len(filename):06o}",
|
|
91
|
+
"c_filesize": f"{e.file_size:011o}",
|
|
92
|
+
})
|
|
93
|
+
inode += 1
|
|
94
|
+
result += filename
|
|
95
|
+
if not e.file_size:
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
with self.open_path(e.filename) as f:
|
|
99
|
+
result += f.read()
|
|
100
|
+
|
|
101
|
+
filename = b"TRAILER!!!\0"
|
|
102
|
+
inode = 0
|
|
103
|
+
mode = 0
|
|
104
|
+
result += (
|
|
105
|
+
cpio_odc_header.build({
|
|
106
|
+
"c_ino": f"{inode:06o}",
|
|
107
|
+
"c_mode": f"{mode:06o}",
|
|
108
|
+
"c_nlink": f"{nlink:06o}",
|
|
109
|
+
"c_namesize": f"{len(filename):06o}",
|
|
110
|
+
})
|
|
111
|
+
+ filename
|
|
112
|
+
)
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
def read(self, path: str) -> bytes:
|
|
116
|
+
return self.archive.read(path)
|
|
117
|
+
|
|
118
|
+
def get_global_manifest(self, macos_variant: str, device_class: str) -> bytes:
|
|
119
|
+
manifest_path = f"Firmware/Manifests/restore/{macos_variant}/apticket.{device_class}.im4m"
|
|
120
|
+
return self.read(manifest_path)
|
|
121
|
+
|
|
122
|
+
def get_firmware(self, firmware_path: str) -> Firmware:
|
|
123
|
+
return Firmware(firmware_path, self)
|
|
124
|
+
|
|
125
|
+
def get_development_files(self) -> list[str]:
|
|
126
|
+
result = []
|
|
127
|
+
for entry in self.archive.namelist():
|
|
128
|
+
for release in ("devel", "kasan", "research"):
|
|
129
|
+
if release in entry.lower():
|
|
130
|
+
result.append(entry)
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
def create_device_support(self, pem_db: Optional[str] = None) -> None:
|
|
134
|
+
device_support_path = Path("~/Library/Developer/Xcode/iOS DeviceSupport").expanduser()
|
|
135
|
+
device_support_path /= (
|
|
136
|
+
f"{self.build_manifest.supported_product_types[0]} "
|
|
137
|
+
f"{self.build_manifest.product_version} ({self.build_manifest.product_build_version})"
|
|
138
|
+
)
|
|
139
|
+
build_identity = self.build_manifest.build_identities[0]
|
|
140
|
+
symbols_path = device_support_path / "Symbols"
|
|
141
|
+
build_identity.extract_dsc(symbols_path, pem_db=pem_db, split=False)
|
|
142
|
+
create_device_support_layout(
|
|
143
|
+
self.build_manifest.supported_product_types[0],
|
|
144
|
+
self.build_manifest.product_version,
|
|
145
|
+
self.build_manifest.product_build_version,
|
|
146
|
+
symbols_path,
|
|
147
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ipsw-parser
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: python3 utility for parsing and extracting data from IPSW
|
|
5
5
|
Author-email: doronz88 <doron88@gmail.com>
|
|
6
6
|
Maintainer-email: doronz88 <doron88@gmail.com>
|
|
@@ -690,6 +690,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
690
690
|
Classifier: Programming Language :: Python :: 3.11
|
|
691
691
|
Classifier: Programming Language :: Python :: 3.12
|
|
692
692
|
Classifier: Programming Language :: Python :: 3.13
|
|
693
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
693
694
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
694
695
|
Requires-Python: >=3.9
|
|
695
696
|
Description-Content-Type: text/markdown
|
|
@@ -20,6 +20,7 @@ classifiers = [
|
|
|
20
20
|
"Programming Language :: Python :: 3.11",
|
|
21
21
|
"Programming Language :: Python :: 3.12",
|
|
22
22
|
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
23
24
|
"Programming Language :: Python :: 3 :: Only",
|
|
24
25
|
]
|
|
25
26
|
dynamic = ["dependencies", "version"]
|
|
@@ -47,3 +48,52 @@ version_file = "ipsw_parser/_version.py"
|
|
|
47
48
|
[build-system]
|
|
48
49
|
requires = ["setuptools>=43.0.0", "setuptools_scm>=8", "wheel"]
|
|
49
50
|
build-backend = "setuptools.build_meta"
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
target-version = "py39"
|
|
54
|
+
line-length = 120
|
|
55
|
+
fix = true
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = [
|
|
59
|
+
# flake8-2020
|
|
60
|
+
"YTT",
|
|
61
|
+
# flake8-bugbear
|
|
62
|
+
"B",
|
|
63
|
+
# flake8-builtins
|
|
64
|
+
"A",
|
|
65
|
+
# flake8-comprehensions
|
|
66
|
+
"C4",
|
|
67
|
+
# flake8-debugger
|
|
68
|
+
"T10",
|
|
69
|
+
# flake8-simplify
|
|
70
|
+
"SIM",
|
|
71
|
+
# isort
|
|
72
|
+
"I",
|
|
73
|
+
# pycodestyle
|
|
74
|
+
"E",
|
|
75
|
+
"W",
|
|
76
|
+
# pyflakes
|
|
77
|
+
"F",
|
|
78
|
+
# pygrep-hooks
|
|
79
|
+
"PGH",
|
|
80
|
+
# pyupgrade
|
|
81
|
+
"UP",
|
|
82
|
+
# ruff
|
|
83
|
+
"RUF",
|
|
84
|
+
# tryceratops
|
|
85
|
+
"TRY",
|
|
86
|
+
]
|
|
87
|
+
ignore = [
|
|
88
|
+
# LineTooLong
|
|
89
|
+
"E501",
|
|
90
|
+
# Custom error classes
|
|
91
|
+
"TRY003",
|
|
92
|
+
# Use `logging.exception` instead of `logging.error`
|
|
93
|
+
"TRY400",
|
|
94
|
+
# Abstract `raise` to an inner function
|
|
95
|
+
"TRY301"
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
[tool.ruff.format]
|
|
99
|
+
preview = true
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
repos:
|
|
2
|
-
- repo: https://github.com/pre-commit/mirrors-isort
|
|
3
|
-
rev: v5.9.3
|
|
4
|
-
hooks:
|
|
5
|
-
- id: isort
|
|
6
|
-
args: [ '-m', 'HANGING_INDENT', '-l', '120','--check-only' ]
|
|
7
|
-
files: \.py$
|
|
8
|
-
|
|
9
|
-
- repo: https://github.com/pycqa/flake8
|
|
10
|
-
rev: "7.0.0"
|
|
11
|
-
hooks:
|
|
12
|
-
- id: flake8
|
|
13
|
-
args: [ '--count', '--select=E9,F63,F7,F82,F401,E741', '--show-source', '--statistics', '--max-complexity=10', '--max-line-length=127' ]
|
|
14
|
-
files: \.py$
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import logging
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Optional
|
|
5
|
-
from zipfile import ZipFile
|
|
6
|
-
|
|
7
|
-
import click
|
|
8
|
-
import coloredlogs
|
|
9
|
-
from remotezip2 import RemoteZip
|
|
10
|
-
|
|
11
|
-
from ipsw_parser.ipsw import IPSW
|
|
12
|
-
|
|
13
|
-
coloredlogs.install(level=logging.DEBUG)
|
|
14
|
-
|
|
15
|
-
logging.getLogger('asyncio').disabled = True
|
|
16
|
-
logging.getLogger('parso.cache').disabled = True
|
|
17
|
-
logging.getLogger('parso.cache.pickle').disabled = True
|
|
18
|
-
logging.getLogger('parso.python.diff').disabled = True
|
|
19
|
-
logging.getLogger('humanfriendly.prompts').disabled = True
|
|
20
|
-
logging.getLogger('blib2to3.pgen2.driver').disabled = True
|
|
21
|
-
logging.getLogger('urllib3.connectionpool').disabled = True
|
|
22
|
-
|
|
23
|
-
logger = logging.getLogger(__name__)
|
|
24
|
-
|
|
25
|
-
PEM_DB_ENV_VAR = 'IPSW_PARSER_PEM_DB'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def handle_ipsw_argument(ctx: click.Context, param: click.Argument, value: str) -> IPSW:
|
|
29
|
-
if value.startswith('http://') or value.startswith('https://'):
|
|
30
|
-
return IPSW(RemoteZip(value))
|
|
31
|
-
return IPSW(ZipFile(Path(value).expanduser()))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ipsw_argument = click.argument('ipsw', callback=handle_ipsw_argument)
|
|
35
|
-
pem_db_option = click.option('--pem-db', envvar=PEM_DB_ENV_VAR,
|
|
36
|
-
help='Path DB file url (can be either a filesystem path or an HTTP URL). '
|
|
37
|
-
'Alternatively, use the IPSW_PARSER_PEM_DB envvar.')
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@click.group()
|
|
41
|
-
def cli() -> None:
|
|
42
|
-
""" CLI utility for extracting info from IPSW files """
|
|
43
|
-
pass
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@cli.command('info')
|
|
47
|
-
@ipsw_argument
|
|
48
|
-
def info(ipsw) -> None:
|
|
49
|
-
""" Parse given .ipsw basic info """
|
|
50
|
-
print(f'SupportedProductTypes: {ipsw.build_manifest.supported_product_types}')
|
|
51
|
-
print(f'ProductVersion: {ipsw.build_manifest.product_version}')
|
|
52
|
-
print(f'ProductBuildVersion: {ipsw.build_manifest.product_build_version}')
|
|
53
|
-
|
|
54
|
-
development_files = ipsw.get_development_files()
|
|
55
|
-
if development_files:
|
|
56
|
-
print('DevelopmentFiles:')
|
|
57
|
-
for file in development_files:
|
|
58
|
-
print(f'- {file}')
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
@cli.command('extract')
|
|
62
|
-
@ipsw_argument
|
|
63
|
-
@click.argument('output', type=click.Path(exists=False))
|
|
64
|
-
@pem_db_option
|
|
65
|
-
def extract(ipsw: IPSW, output: str, pem_db: Optional[str]) -> None:
|
|
66
|
-
""" Extract .ipsw into filesystem layout """
|
|
67
|
-
output = Path(output)
|
|
68
|
-
|
|
69
|
-
if not output.exists():
|
|
70
|
-
output.mkdir(parents=True, exist_ok=True)
|
|
71
|
-
|
|
72
|
-
ipsw.build_manifest.build_identities[0].extract(output, pem_db=pem_db)
|
|
73
|
-
ipsw.archive.extractall(
|
|
74
|
-
path=output, members=[f for f in ipsw.archive.filelist if f.filename.startswith('Firmware')])
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
@cli.command('extract-kernel')
|
|
78
|
-
@ipsw_argument
|
|
79
|
-
@click.argument('output', type=click.Path(exists=False))
|
|
80
|
-
@click.option('--arch', help='Arch name to extract using lipo')
|
|
81
|
-
def extract_kernel(ipsw: IPSW, output: str, arch: Optional[str]) -> None:
|
|
82
|
-
""" Extract kernelcache from given .ipsw into given output filename """
|
|
83
|
-
Path(output).write_bytes(ipsw.build_manifest.build_identities[0].get_kernelcache_payload(arch=arch))
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@cli.command('device-support')
|
|
87
|
-
@ipsw_argument
|
|
88
|
-
@pem_db_option
|
|
89
|
-
def device_support(ipsw: IPSW, pem_db: Optional[str]) -> None:
|
|
90
|
-
""" Create DeviceSupport directory """
|
|
91
|
-
ipsw.create_device_support(pem_db=pem_db)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if __name__ == '__main__':
|
|
95
|
-
cli()
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
class Firmware:
|
|
2
|
-
def __init__(self, firmware_path: str, ipsw):
|
|
3
|
-
self._ipsw = ipsw
|
|
4
|
-
self._firmware_path = firmware_path
|
|
5
|
-
self._manifest_data = self._ipsw.read(self.get_relative_path('manifest'))
|
|
6
|
-
self._firmware_files = {}
|
|
7
|
-
for filename in self._manifest_data.splitlines():
|
|
8
|
-
filename = filename.strip()
|
|
9
|
-
component_name = self.get_component_name(filename)
|
|
10
|
-
self._firmware_files[component_name] = f'{firmware_path}/{filename}'
|
|
11
|
-
|
|
12
|
-
def get_relative_path(self, path: str):
|
|
13
|
-
return f'{self._firmware_path}/{path}'
|
|
14
|
-
|
|
15
|
-
def get_files(self):
|
|
16
|
-
return self._firmware_files
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def get_component_name(filename):
|
|
20
|
-
names = {
|
|
21
|
-
'LLB': 'LLB',
|
|
22
|
-
'iBoot': 'iBoot',
|
|
23
|
-
'DeviceTree': 'DeviceTree',
|
|
24
|
-
'applelogo': 'AppleLogo',
|
|
25
|
-
'liquiddetect': 'Liquid',
|
|
26
|
-
'lowpowermode': 'LowPowerWallet0',
|
|
27
|
-
'recoverymode': 'RecoveryMode',
|
|
28
|
-
'batterylow0': 'BatteryLow0',
|
|
29
|
-
'batterylow1': 'BatteryLow1',
|
|
30
|
-
'glyphcharging': 'BatteryCharging',
|
|
31
|
-
'glyphplugin': 'BatteryPlugin',
|
|
32
|
-
'batterycharging0': 'BatteryCharging0',
|
|
33
|
-
'batterycharging1': 'BatteryCharging1',
|
|
34
|
-
'batteryfull': 'BatteryFull',
|
|
35
|
-
'needservice': 'NeedService',
|
|
36
|
-
'SCAB': 'SCAB',
|
|
37
|
-
'sep-firmware': 'RestoreSEP',
|
|
38
|
-
}
|
|
39
|
-
return names.get(filename)
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import plistlib
|
|
3
|
-
import zipfile
|
|
4
|
-
from contextlib import contextmanager
|
|
5
|
-
from datetime import datetime
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from typing import Optional
|
|
8
|
-
|
|
9
|
-
from cached_property import cached_property
|
|
10
|
-
from construct import Const, Default, PaddedString, Struct
|
|
11
|
-
|
|
12
|
-
from ipsw_parser.build_manifest import BuildManifest
|
|
13
|
-
from ipsw_parser.firmware import Firmware
|
|
14
|
-
|
|
15
|
-
logger = logging.getLogger(__name__)
|
|
16
|
-
|
|
17
|
-
cpio_odc_header = Struct(
|
|
18
|
-
'c_magic' / Const('070707', PaddedString(6, 'utf8')),
|
|
19
|
-
'c_dev' / Default(PaddedString(6, 'utf8'), '0' * 6, ),
|
|
20
|
-
'c_ino' / PaddedString(6, 'utf8'),
|
|
21
|
-
'c_mode' / PaddedString(6, 'utf8'),
|
|
22
|
-
'c_uid' / Default(PaddedString(6, 'utf8'), '0' * 6),
|
|
23
|
-
'c_gid' / Default(PaddedString(6, 'utf8'), '0' * 6),
|
|
24
|
-
'c_nlink' / PaddedString(6, 'utf8'),
|
|
25
|
-
'c_rdev' / Default(PaddedString(6, 'utf8'), '0' * 6),
|
|
26
|
-
'c_mtime' / Default(PaddedString(11, 'utf8'), '0' * 11),
|
|
27
|
-
'c_namesize' / PaddedString(6, 'utf8'),
|
|
28
|
-
'c_filesize' / Default(PaddedString(11, 'utf8'), '0' * 11),
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class IPSW:
|
|
33
|
-
def __init__(self, archive: zipfile.ZipFile):
|
|
34
|
-
self.archive = archive
|
|
35
|
-
self._logger = logging.getLogger(__file__)
|
|
36
|
-
self.build_manifest = BuildManifest(self, self.archive.read(
|
|
37
|
-
next(f for f in self.archive.namelist() if f.startswith('BuildManifest') and f.endswith('.plist'))))
|
|
38
|
-
|
|
39
|
-
@cached_property
|
|
40
|
-
def restore_version(self) -> bytes:
|
|
41
|
-
return self.read('RestoreVersion.plist')
|
|
42
|
-
|
|
43
|
-
@cached_property
|
|
44
|
-
def system_version(self) -> bytes:
|
|
45
|
-
return self.read('SystemVersion.plist')
|
|
46
|
-
|
|
47
|
-
@cached_property
|
|
48
|
-
def filelist(self) -> list[zipfile.ZipInfo]:
|
|
49
|
-
return self.archive.filelist
|
|
50
|
-
|
|
51
|
-
@contextmanager
|
|
52
|
-
def open_path(self, path: str):
|
|
53
|
-
file = self.archive.open(path)
|
|
54
|
-
try:
|
|
55
|
-
yield file
|
|
56
|
-
finally:
|
|
57
|
-
file.close()
|
|
58
|
-
|
|
59
|
-
@property
|
|
60
|
-
def bootability(self) -> bytes:
|
|
61
|
-
result = b''
|
|
62
|
-
prefix = 'BootabilityBundle/Restore/Bootability/'
|
|
63
|
-
inode = 1
|
|
64
|
-
nlink = 1
|
|
65
|
-
|
|
66
|
-
for e in self.filelist:
|
|
67
|
-
if e.filename == 'BootabilityBundle/Restore/Firmware/Bootability.dmg.trustcache':
|
|
68
|
-
subpath = 'Bootability.trustcache'
|
|
69
|
-
elif not e.filename.startswith(prefix):
|
|
70
|
-
continue
|
|
71
|
-
else:
|
|
72
|
-
subpath = e.filename[len(prefix):]
|
|
73
|
-
|
|
74
|
-
self._logger.debug(f'BootabilityBundle: adding {subpath}')
|
|
75
|
-
|
|
76
|
-
filename = subpath
|
|
77
|
-
filename = f'{filename}\0'.encode()
|
|
78
|
-
mode = e.external_attr >> 16
|
|
79
|
-
result += cpio_odc_header.build({
|
|
80
|
-
'c_ino': f'{inode:06o}', 'c_nlink': f'{nlink:06o}', 'c_mode': f'{mode:06o}',
|
|
81
|
-
'c_namesize': f'{len(filename):06o}', 'c_filesize': f'{e.file_size:011o}'})
|
|
82
|
-
inode += 1
|
|
83
|
-
result += filename
|
|
84
|
-
if not e.file_size:
|
|
85
|
-
continue
|
|
86
|
-
|
|
87
|
-
with self.open_path(e.filename) as f:
|
|
88
|
-
result += f.read()
|
|
89
|
-
|
|
90
|
-
filename = b'TRAILER!!!\0'
|
|
91
|
-
inode = 0
|
|
92
|
-
mode = 0
|
|
93
|
-
result += cpio_odc_header.build(
|
|
94
|
-
{'c_ino': f'{inode:06o}', 'c_mode': f'{mode:06o}', 'c_nlink': f'{nlink:06o}',
|
|
95
|
-
'c_namesize': f'{len(filename):06o}'}) + filename
|
|
96
|
-
return result
|
|
97
|
-
|
|
98
|
-
def read(self, path: str) -> bytes:
|
|
99
|
-
return self.archive.read(path)
|
|
100
|
-
|
|
101
|
-
def get_global_manifest(self, macos_variant: str, device_class: str) -> bytes:
|
|
102
|
-
manifest_path = f'Firmware/Manifests/restore/{macos_variant}/apticket.{device_class}.im4m'
|
|
103
|
-
return self.read(manifest_path)
|
|
104
|
-
|
|
105
|
-
def get_firmware(self, firmware_path: str) -> Firmware:
|
|
106
|
-
return Firmware(firmware_path, self)
|
|
107
|
-
|
|
108
|
-
def get_development_files(self) -> list[str]:
|
|
109
|
-
result = []
|
|
110
|
-
for entry in self.archive.namelist():
|
|
111
|
-
for release in ('devel', 'kasan', 'research'):
|
|
112
|
-
if release in entry.lower():
|
|
113
|
-
result.append(entry)
|
|
114
|
-
return result
|
|
115
|
-
|
|
116
|
-
def create_device_support(self, pem_db: Optional[str] = None) -> None:
|
|
117
|
-
device_support_path = Path('~/Library/Developer/Xcode/iOS DeviceSupport').expanduser()
|
|
118
|
-
device_support_path /= (f'{self.build_manifest.supported_product_types[0]} '
|
|
119
|
-
f'{self.build_manifest.product_version} ({self.build_manifest.product_build_version})')
|
|
120
|
-
build_identity = self.build_manifest.build_identities[0]
|
|
121
|
-
symbols_path = device_support_path / 'Symbols'
|
|
122
|
-
build_identity.extract_dsc(symbols_path, pem_db=pem_db)
|
|
123
|
-
for file in (symbols_path / 'private/preboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld').iterdir():
|
|
124
|
-
file.unlink()
|
|
125
|
-
(device_support_path / 'Info.plist').write_bytes(plistlib.dumps({
|
|
126
|
-
'DSC Extractor Version': '1228.0.0.0.0',
|
|
127
|
-
'DateCollected': datetime.now(),
|
|
128
|
-
'Version': '16.0',
|
|
129
|
-
}))
|
|
130
|
-
(device_support_path / '.finalized').write_bytes(plistlib.dumps({}))
|
|
131
|
-
(device_support_path / '.processed_dyld_shared_cache_arm64e').touch()
|
|
132
|
-
(device_support_path / '.processing_lock').touch()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|