ipsw-parser 1.5.0__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.
Files changed (35) hide show
  1. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.github/workflows/python-app.yml +4 -0
  2. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/PKG-INFO +2 -3
  3. ipsw_parser-1.6.0/ipsw_parser/__main__.py +86 -0
  4. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/_version.py +3 -3
  5. ipsw_parser-1.6.0/ipsw_parser/archive.py +87 -0
  6. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/build_identity.py +4 -4
  7. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/build_manifest.py +1 -2
  8. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/component.py +1 -2
  9. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/ipsw.py +17 -4
  10. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/PKG-INFO +2 -3
  11. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/SOURCES.txt +3 -1
  12. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/requires.txt +1 -2
  13. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/requirements.txt +2 -3
  14. ipsw_parser-1.6.0/tests/test_archive_backends.py +70 -0
  15. ipsw_parser-1.5.0/ipsw_parser/__main__.py +0 -99
  16. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.gitattributes +0 -0
  17. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  18. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  19. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.github/workflows/codeql.yml +0 -0
  20. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.github/workflows/python-publish.yml +0 -0
  21. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.gitignore +0 -0
  22. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/.pre-commit-config.yaml +0 -0
  23. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/CODE_OF_CONDUCT.md +0 -0
  24. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/LICENSE +0 -0
  25. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/README.md +0 -0
  26. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/__init__.py +0 -0
  27. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/dsc.py +0 -0
  28. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/exceptions.py +0 -0
  29. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser/firmware.py +0 -0
  30. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/dependency_links.txt +0 -0
  31. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/entry_points.txt +0 -0
  32. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/ipsw_parser.egg-info/top_level.txt +0 -0
  33. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/pyproject.toml +0 -0
  34. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/pytest.ini +0 -0
  35. {ipsw_parser-1.5.0 → ipsw_parser-1.6.0}/setup.cfg +0 -0
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.5.0
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>
@@ -696,13 +696,12 @@ Requires-Python: >=3.9
696
696
  Description-Content-Type: text/markdown
697
697
  License-File: LICENSE
698
698
  Requires-Dist: construct>=2.9.29
699
- Requires-Dist: click
700
699
  Requires-Dist: coloredlogs
701
- Requires-Dist: cached_property
702
700
  Requires-Dist: plumbum
703
701
  Requires-Dist: pyimg4>=0.8.8
704
702
  Requires-Dist: requests
705
703
  Requires-Dist: remotezip2
704
+ Requires-Dist: typer
706
705
  Provides-Extra: test
707
706
  Requires-Dist: pytest; extra == "test"
708
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()
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '1.5.0'
32
- __version_tuple__ = version_tuple = (1, 5, 0)
31
+ __version__ = version = '1.6.0'
32
+ __version_tuple__ = version_tuple = (1, 6, 0)
33
33
 
34
- __commit_id__ = commit_id = 'gd02ef0cd1'
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,16 +2,16 @@ 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
16
  from ipsw_parser.dsc import split_dsc
17
17
 
@@ -20,10 +20,10 @@ logger = logging.getLogger(__name__)
20
20
  AEA_MAGIC = b"AEA1"
21
21
 
22
22
 
23
- def extract_as(zipf: ZipFile, member_name, output_path, chunk_size=64 * 1024):
23
+ def extract_as(archive: Archive, member_name, output_path, chunk_size=64 * 1024):
24
24
  """Extract a single member from a ZIP archive to a custom output path"""
25
25
  os.makedirs(os.path.dirname(output_path), exist_ok=True)
26
- with zipf.open(member_name) as source, open(output_path, "wb") as target:
26
+ with archive.open(member_name) as source, open(output_path, "wb") as target:
27
27
  shutil.copyfileobj(source, target, length=chunk_size)
28
28
 
29
29
 
@@ -1,8 +1,7 @@
1
1
  import plistlib
2
+ from functools import cached_property
2
3
  from typing import Optional
3
4
 
4
- from cached_property import cached_property
5
-
6
5
  from ipsw_parser.build_identity import BuildIdentity
7
6
  from ipsw_parser.exceptions import NoSuchBuildIdentityError
8
7
 
@@ -1,9 +1,8 @@
1
1
  import logging
2
2
  import os.path
3
+ from functools import cached_property
3
4
  from typing import Optional
4
5
 
5
- from cached_property import cached_property
6
-
7
6
  from ipsw_parser.exceptions import IpswException
8
7
 
9
8
 
@@ -1,12 +1,14 @@
1
1
  import logging
2
- import zipfile
3
2
  from contextlib import contextmanager
3
+ from functools import cached_property
4
4
  from pathlib import Path
5
5
  from typing import Optional
6
+ from zipfile import ZipFile
6
7
 
7
- from cached_property import cached_property
8
8
  from construct import Const, Default, PaddedString, Struct
9
+ from remotezip2 import RemoteZip
9
10
 
11
+ from ipsw_parser.archive import Archive, ArchiveMember, DirectoryArchive, ZipArchive
10
12
  from ipsw_parser.build_manifest import BuildManifest
11
13
  from ipsw_parser.dsc import create_device_support_layout
12
14
  from ipsw_parser.firmware import Firmware
@@ -33,7 +35,18 @@ cpio_odc_header = Struct(
33
35
 
34
36
 
35
37
  class IPSW:
36
- def __init__(self, archive: zipfile.ZipFile):
38
+ @classmethod
39
+ def create_from_path(cls, value: str) -> "IPSW":
40
+ if value.startswith("http://") or value.startswith("https://"):
41
+ return cls(ZipArchive(RemoteZip(value)))
42
+
43
+ path = Path(value).expanduser()
44
+ if path.is_dir():
45
+ return cls(DirectoryArchive(path))
46
+
47
+ return cls(ZipArchive(ZipFile(path)))
48
+
49
+ def __init__(self, archive: Archive):
37
50
  self.archive = archive
38
51
  self._logger = logging.getLogger(__file__)
39
52
  self.build_manifest = BuildManifest(
@@ -52,7 +65,7 @@ class IPSW:
52
65
  return self.read("SystemVersion.plist")
53
66
 
54
67
  @cached_property
55
- def filelist(self) -> list[zipfile.ZipInfo]:
68
+ def filelist(self) -> list[ArchiveMember]:
56
69
  return self.archive.filelist
57
70
 
58
71
  @contextmanager
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.5.0
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>
@@ -696,13 +696,12 @@ Requires-Python: >=3.9
696
696
  Description-Content-Type: text/markdown
697
697
  License-File: LICENSE
698
698
  Requires-Dist: construct>=2.9.29
699
- Requires-Dist: click
700
699
  Requires-Dist: coloredlogs
701
- Requires-Dist: cached_property
702
700
  Requires-Dist: plumbum
703
701
  Requires-Dist: pyimg4>=0.8.8
704
702
  Requires-Dist: requests
705
703
  Requires-Dist: remotezip2
704
+ Requires-Dist: typer
706
705
  Provides-Extra: test
707
706
  Requires-Dist: pytest; extra == "test"
708
707
  Dynamic: license-file
@@ -15,6 +15,7 @@ requirements.txt
15
15
  ipsw_parser/__init__.py
16
16
  ipsw_parser/__main__.py
17
17
  ipsw_parser/_version.py
18
+ ipsw_parser/archive.py
18
19
  ipsw_parser/build_identity.py
19
20
  ipsw_parser/build_manifest.py
20
21
  ipsw_parser/component.py
@@ -27,4 +28,5 @@ ipsw_parser.egg-info/SOURCES.txt
27
28
  ipsw_parser.egg-info/dependency_links.txt
28
29
  ipsw_parser.egg-info/entry_points.txt
29
30
  ipsw_parser.egg-info/requires.txt
30
- ipsw_parser.egg-info/top_level.txt
31
+ ipsw_parser.egg-info/top_level.txt
32
+ tests/test_archive_backends.py
@@ -1,11 +1,10 @@
1
1
  construct>=2.9.29
2
- click
3
2
  coloredlogs
4
- cached_property
5
3
  plumbum
6
4
  pyimg4>=0.8.8
7
5
  requests
8
6
  remotezip2
7
+ typer
9
8
 
10
9
  [test]
11
10
  pytest
@@ -1,8 +1,7 @@
1
1
  construct>=2.9.29
2
- click
3
2
  coloredlogs
4
- cached_property
5
3
  plumbum
6
4
  pyimg4>=0.8.8
7
5
  requests
8
- remotezip2
6
+ remotezip2
7
+ typer
@@ -0,0 +1,70 @@
1
+ import plistlib
2
+ from pathlib import Path
3
+ from zipfile import ZipFile
4
+
5
+ from ipsw_parser.archive import DirectoryArchive, ZipArchive
6
+ from ipsw_parser.ipsw import IPSW
7
+
8
+
9
+ def _build_manifest() -> bytes:
10
+ return plistlib.dumps({
11
+ "SupportedProductTypes": ["iPhone1,1"],
12
+ "ProductVersion": "1.0",
13
+ "ProductBuildVersion": "1A1",
14
+ "BuildIdentities": [],
15
+ })
16
+
17
+
18
+ def _write_ipsw_layout(root: Path) -> None:
19
+ (root / "BuildManifest.plist").write_bytes(_build_manifest())
20
+ (root / "RestoreVersion.plist").write_bytes(b"restore-version")
21
+ (root / "SystemVersion.plist").write_bytes(b"system-version")
22
+ firmware = root / "Firmware"
23
+ firmware.mkdir()
24
+ (firmware / "devel-file.bin").write_bytes(b"dev")
25
+ release = root / "Release"
26
+ release.mkdir()
27
+ (release / "normal-file.bin").write_bytes(b"release")
28
+
29
+
30
+ def test_directory_archive_supports_ipsw_loading(tmp_path: Path) -> None:
31
+ _write_ipsw_layout(tmp_path)
32
+
33
+ ipsw = IPSW(DirectoryArchive(tmp_path))
34
+
35
+ assert ipsw.build_manifest.product_version == "1.0"
36
+ assert ipsw.restore_version == b"restore-version"
37
+ assert ipsw.system_version == b"system-version"
38
+ assert ipsw.get_development_files() == ["Firmware/devel-file.bin"]
39
+
40
+
41
+ def test_zip_archive_supports_same_ipsw_behavior(tmp_path: Path) -> None:
42
+ source = tmp_path / "source"
43
+ source.mkdir()
44
+ _write_ipsw_layout(source)
45
+
46
+ archive_path = tmp_path / "sample.ipsw"
47
+ with ZipFile(archive_path, "w") as archive:
48
+ for file_path in sorted(path for path in source.rglob("*") if path.is_file()):
49
+ archive.write(file_path, arcname=file_path.relative_to(source).as_posix())
50
+
51
+ with ZipFile(archive_path) as archive:
52
+ ipsw = IPSW(ZipArchive(archive))
53
+
54
+ assert ipsw.build_manifest.product_build_version == "1A1"
55
+ assert ipsw.restore_version == b"restore-version"
56
+ assert ipsw.get_development_files() == ["Firmware/devel-file.bin"]
57
+
58
+
59
+ def test_directory_extractall_copies_requested_members(tmp_path: Path) -> None:
60
+ source = tmp_path / "source"
61
+ source.mkdir()
62
+ _write_ipsw_layout(source)
63
+ archive = DirectoryArchive(source)
64
+
65
+ output = tmp_path / "output"
66
+ members = [member for member in archive.filelist if member.filename.startswith("Firmware")]
67
+ archive.extractall(output, members)
68
+
69
+ assert (output / "Firmware" / "devel-file.bin").read_bytes() == b"dev"
70
+ assert not (output / "Release" / "normal-file.bin").exists()
@@ -1,99 +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(
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()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes