ipsw-parser 1.4.4__tar.gz → 1.6.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.6.0}/.github/workflows/python-app.yml +5 -1
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/.github/workflows/python-publish.yml +2 -2
- ipsw_parser-1.6.0/.pre-commit-config.yaml +9 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/PKG-INFO +3 -3
- ipsw_parser-1.6.0/ipsw_parser/__main__.py +86 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/_version.py +16 -3
- ipsw_parser-1.6.0/ipsw_parser/archive.py +87 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/build_identity.py +55 -73
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/build_manifest.py +22 -22
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/component.py +17 -10
- ipsw_parser-1.6.0/ipsw_parser/dsc.py +83 -0
- ipsw_parser-1.6.0/ipsw_parser/firmware.py +39 -0
- ipsw_parser-1.6.0/ipsw_parser/ipsw.py +160 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/PKG-INFO +3 -3
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/SOURCES.txt +4 -1
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/requires.txt +1 -2
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/pyproject.toml +50 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/requirements.txt +2 -3
- ipsw_parser-1.6.0/tests/test_archive_backends.py +70 -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.6.0}/.gitattributes +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/.github/workflows/codeql.yml +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/.gitignore +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/CODE_OF_CONDUCT.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/LICENSE +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/README.md +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/__init__.py +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser/exceptions.py +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/dependency_links.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/entry_points.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/top_level.txt +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/pytest.ini +0 -0
- {ipsw_parser-1.4.4 → ipsw_parser-1.6.0}/setup.cfg +0 -0
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
|
|
14
14
|
strategy:
|
|
15
15
|
matrix:
|
|
16
|
-
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
|
|
16
|
+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ]
|
|
17
17
|
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
@@ -35,3 +35,7 @@ jobs:
|
|
|
35
35
|
- name: Test show usage
|
|
36
36
|
run: |
|
|
37
37
|
python -m ipsw_parser --help
|
|
38
|
+
- name: Run tests
|
|
39
|
+
run: |
|
|
40
|
+
python -m pip install pytest
|
|
41
|
+
python -m pytest
|
|
@@ -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.6.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,18 +690,18 @@ 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
|
|
696
697
|
License-File: LICENSE
|
|
697
698
|
Requires-Dist: construct>=2.9.29
|
|
698
|
-
Requires-Dist: click
|
|
699
699
|
Requires-Dist: coloredlogs
|
|
700
|
-
Requires-Dist: cached_property
|
|
701
700
|
Requires-Dist: plumbum
|
|
702
701
|
Requires-Dist: pyimg4>=0.8.8
|
|
703
702
|
Requires-Dist: requests
|
|
704
703
|
Requires-Dist: remotezip2
|
|
704
|
+
Requires-Dist: typer
|
|
705
705
|
Provides-Extra: test
|
|
706
706
|
Requires-Dist: pytest; extra == "test"
|
|
707
707
|
Dynamic: license-file
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Annotated, Optional
|
|
5
|
+
|
|
6
|
+
import coloredlogs
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from ipsw_parser.ipsw import IPSW
|
|
10
|
+
|
|
11
|
+
coloredlogs.install(level=logging.DEBUG)
|
|
12
|
+
|
|
13
|
+
logging.getLogger("asyncio").disabled = True
|
|
14
|
+
logging.getLogger("parso.cache").disabled = True
|
|
15
|
+
logging.getLogger("parso.cache.pickle").disabled = True
|
|
16
|
+
logging.getLogger("parso.python.diff").disabled = True
|
|
17
|
+
logging.getLogger("humanfriendly.prompts").disabled = True
|
|
18
|
+
logging.getLogger("blib2to3.pgen2.driver").disabled = True
|
|
19
|
+
logging.getLogger("urllib3.connectionpool").disabled = True
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
PEM_DB_ENV_VAR = "IPSW_PARSER_PEM_DB"
|
|
24
|
+
|
|
25
|
+
cli = typer.Typer(
|
|
26
|
+
help="CLI utility for extracting info from IPSW files",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
IpswArgument = Annotated[str, typer.Argument(help="Path to an IPSW zip, extracted IPSW directory, or HTTP URL.")]
|
|
30
|
+
OutputArgument = Annotated[Path, typer.Argument(help="Output path.", exists=False)]
|
|
31
|
+
PemDbOption = Annotated[
|
|
32
|
+
Optional[str],
|
|
33
|
+
typer.Option(
|
|
34
|
+
"--pem-db",
|
|
35
|
+
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
|
+
ArchOption = Annotated[Optional[str], typer.Option(help="Arch name to extract using lipo")]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@cli.command("info")
|
|
44
|
+
def info(ipsw: IpswArgument) -> None:
|
|
45
|
+
"""Parse given .ipsw basic info"""
|
|
46
|
+
parsed_ipsw = IPSW.create_from_path(ipsw)
|
|
47
|
+
print(f"SupportedProductTypes: {parsed_ipsw.build_manifest.supported_product_types}")
|
|
48
|
+
print(f"ProductVersion: {parsed_ipsw.build_manifest.product_version}")
|
|
49
|
+
print(f"ProductBuildVersion: {parsed_ipsw.build_manifest.product_build_version}")
|
|
50
|
+
|
|
51
|
+
development_files = parsed_ipsw.get_development_files()
|
|
52
|
+
if development_files:
|
|
53
|
+
print("DevelopmentFiles:")
|
|
54
|
+
for file in development_files:
|
|
55
|
+
print(f"- {file}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@cli.command("extract")
|
|
59
|
+
def extract(ipsw: IpswArgument, output: OutputArgument, pem_db: PemDbOption = None) -> None:
|
|
60
|
+
"""Extract .ipsw into filesystem layout"""
|
|
61
|
+
parsed_ipsw = IPSW.create_from_path(ipsw)
|
|
62
|
+
|
|
63
|
+
if not output.exists():
|
|
64
|
+
output.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
|
|
66
|
+
parsed_ipsw.build_manifest.build_identities[0].extract(output, pem_db=pem_db)
|
|
67
|
+
parsed_ipsw.archive.extractall(
|
|
68
|
+
path=output, members=[f for f in parsed_ipsw.archive.filelist if f.filename.startswith("Firmware")]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@cli.command("extract-kernel")
|
|
73
|
+
def extract_kernel(ipsw: IpswArgument, output: OutputArgument, arch: ArchOption = None) -> None:
|
|
74
|
+
"""Extract kernelcache from given .ipsw into given output filename"""
|
|
75
|
+
parsed_ipsw = IPSW.create_from_path(ipsw)
|
|
76
|
+
output.write_bytes(parsed_ipsw.build_manifest.build_identities[0].get_kernelcache_payload(arch=arch))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@cli.command("device-support")
|
|
80
|
+
def device_support(ipsw: IpswArgument, pem_db: PemDbOption = None) -> None:
|
|
81
|
+
"""Create DeviceSupport directory"""
|
|
82
|
+
IPSW.create_from_path(ipsw).create_device_support(pem_db=pem_db)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == "__main__":
|
|
86
|
+
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.6.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 6, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g0e931b7f6'
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import stat
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from functools import cached_property
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import BinaryIO, Protocol, Union
|
|
8
|
+
from zipfile import ZipFile, ZipInfo
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class ArchiveMember:
|
|
13
|
+
filename: str
|
|
14
|
+
file_size: int
|
|
15
|
+
external_attr: int
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Archive(Protocol):
|
|
19
|
+
@property
|
|
20
|
+
def filelist(self) -> list[ArchiveMember]: ...
|
|
21
|
+
|
|
22
|
+
def namelist(self) -> list[str]: ...
|
|
23
|
+
|
|
24
|
+
def open(self, path: str) -> BinaryIO: ...
|
|
25
|
+
|
|
26
|
+
def read(self, path: str) -> bytes: ...
|
|
27
|
+
|
|
28
|
+
def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None: ...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ZipArchive:
|
|
32
|
+
def __init__(self, archive: ZipFile):
|
|
33
|
+
self._archive = archive
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def filelist(self) -> list[ZipInfo]:
|
|
37
|
+
return self._archive.filelist
|
|
38
|
+
|
|
39
|
+
def namelist(self) -> list[str]:
|
|
40
|
+
return self._archive.namelist()
|
|
41
|
+
|
|
42
|
+
def open(self, path: str) -> BinaryIO:
|
|
43
|
+
return self._archive.open(path)
|
|
44
|
+
|
|
45
|
+
def read(self, path: str) -> bytes:
|
|
46
|
+
return self._archive.read(path)
|
|
47
|
+
|
|
48
|
+
def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None:
|
|
49
|
+
self._archive.extractall(path=path, members=members)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class DirectoryArchive:
|
|
53
|
+
def __init__(self, root: Path):
|
|
54
|
+
self._root = root
|
|
55
|
+
|
|
56
|
+
@cached_property
|
|
57
|
+
def filelist(self) -> list[ArchiveMember]:
|
|
58
|
+
result = []
|
|
59
|
+
for file_path in sorted(path for path in self._root.rglob("*") if path.is_file()):
|
|
60
|
+
file_stat = file_path.stat()
|
|
61
|
+
relative_path = file_path.relative_to(self._root).as_posix()
|
|
62
|
+
mode = stat.S_IFREG | stat.S_IMODE(file_stat.st_mode)
|
|
63
|
+
result.append(
|
|
64
|
+
ArchiveMember(
|
|
65
|
+
filename=relative_path,
|
|
66
|
+
file_size=file_stat.st_size,
|
|
67
|
+
external_attr=mode << 16,
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
def namelist(self) -> list[str]:
|
|
73
|
+
return [member.filename for member in self.filelist]
|
|
74
|
+
|
|
75
|
+
def open(self, path: str) -> BinaryIO:
|
|
76
|
+
return (self._root / path).open("rb")
|
|
77
|
+
|
|
78
|
+
def read(self, path: str) -> bytes:
|
|
79
|
+
return (self._root / path).read_bytes()
|
|
80
|
+
|
|
81
|
+
def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None:
|
|
82
|
+
for member in members:
|
|
83
|
+
filename = member if isinstance(member, str) else member.filename
|
|
84
|
+
source = self._root / filename
|
|
85
|
+
destination = path / filename
|
|
86
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
87
|
+
shutil.copyfile(source, destination)
|
|
@@ -2,85 +2,67 @@ import logging
|
|
|
2
2
|
import os
|
|
3
3
|
import shutil
|
|
4
4
|
from collections import UserDict
|
|
5
|
+
from functools import cached_property
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from tempfile import TemporaryDirectory
|
|
7
8
|
from typing import Optional
|
|
8
|
-
from zipfile import ZipFile
|
|
9
9
|
|
|
10
10
|
import requests
|
|
11
|
-
from cached_property import cached_property
|
|
12
11
|
from plumbum import ProcessExecutionError, local
|
|
13
12
|
from pyimg4 import IM4P
|
|
14
13
|
|
|
14
|
+
from ipsw_parser.archive import Archive
|
|
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
|
-
def extract_as(
|
|
23
|
+
def extract_as(archive: Archive, 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
|
|
26
|
+
with archive.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,6 +1,6 @@
|
|
|
1
1
|
import plistlib
|
|
2
|
-
|
|
3
|
-
from
|
|
2
|
+
from functools import cached_property
|
|
3
|
+
from typing import Optional
|
|
4
4
|
|
|
5
5
|
from ipsw_parser.build_identity import BuildIdentity
|
|
6
6
|
from ipsw_parser.exceptions import NoSuchBuildIdentityError
|
|
@@ -14,8 +14,8 @@ class BuildManifest:
|
|
|
14
14
|
|
|
15
15
|
@cached_property
|
|
16
16
|
def build_major(self) -> int:
|
|
17
|
-
build_major =
|
|
18
|
-
for i in self._manifest[
|
|
17
|
+
build_major = ""
|
|
18
|
+
for i in self._manifest["ProductBuildVersion"]:
|
|
19
19
|
if i.isdigit():
|
|
20
20
|
build_major += i
|
|
21
21
|
else:
|
|
@@ -25,45 +25,45 @@ class BuildManifest:
|
|
|
25
25
|
|
|
26
26
|
@cached_property
|
|
27
27
|
def supported_product_types(self) -> list[str]:
|
|
28
|
-
return self._manifest[
|
|
28
|
+
return self._manifest["SupportedProductTypes"]
|
|
29
29
|
|
|
30
30
|
@cached_property
|
|
31
31
|
def supported_product_types_family(self) -> str:
|
|
32
32
|
product = self.supported_product_types[0]
|
|
33
|
-
if product.startswith(
|
|
34
|
-
return
|
|
35
|
-
elif product.startswith(
|
|
36
|
-
return
|
|
37
|
-
elif
|
|
38
|
-
return
|
|
33
|
+
if product.startswith("iBridge"):
|
|
34
|
+
return "iBridge"
|
|
35
|
+
elif product.startswith("iPhone"):
|
|
36
|
+
return "iPhone"
|
|
37
|
+
elif "Mac" in product:
|
|
38
|
+
return "Mac"
|
|
39
39
|
else:
|
|
40
40
|
raise ValueError()
|
|
41
41
|
|
|
42
42
|
@cached_property
|
|
43
43
|
def product_version(self) -> str:
|
|
44
|
-
return self._manifest[
|
|
44
|
+
return self._manifest["ProductVersion"]
|
|
45
45
|
|
|
46
46
|
@cached_property
|
|
47
47
|
def product_build_version(self) -> str:
|
|
48
|
-
return self._manifest[
|
|
48
|
+
return self._manifest["ProductBuildVersion"]
|
|
49
49
|
|
|
50
|
-
def get_build_identity(
|
|
50
|
+
def get_build_identity(
|
|
51
|
+
self, device_class: str, restore_behavior: Optional[str] = None, variant: Optional[str] = None
|
|
52
|
+
) -> BuildIdentity:
|
|
51
53
|
for build_identity in self.build_identities:
|
|
52
|
-
if variant is not None:
|
|
53
|
-
|
|
54
|
-
continue
|
|
54
|
+
if variant is not None and variant not in build_identity.variant:
|
|
55
|
+
continue
|
|
55
56
|
|
|
56
57
|
if build_identity.device_class != device_class:
|
|
57
58
|
continue
|
|
58
59
|
|
|
59
|
-
if restore_behavior is not None:
|
|
60
|
-
|
|
61
|
-
continue
|
|
60
|
+
if restore_behavior is not None and build_identity.restore_behavior != restore_behavior:
|
|
61
|
+
continue
|
|
62
62
|
|
|
63
63
|
return build_identity
|
|
64
|
-
raise NoSuchBuildIdentityError(
|
|
64
|
+
raise NoSuchBuildIdentityError("failed to find the correct BuildIdentity from the BuildManifest")
|
|
65
65
|
|
|
66
66
|
def _parse_build_identities(self) -> None:
|
|
67
67
|
self.build_identities = []
|
|
68
|
-
for build_identity in self._manifest[
|
|
68
|
+
for build_identity in self._manifest["BuildIdentities"]:
|
|
69
69
|
self.build_identities.append(BuildIdentity(self, build_identity))
|