ipsw-parser 1.6.0__tar.gz → 1.7.1__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 (36) hide show
  1. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/PKG-INFO +3 -1
  2. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/README.md +2 -0
  3. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/__main__.py +15 -4
  4. ipsw_parser-1.7.1/ipsw_parser/_version.py +24 -0
  5. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/archive.py +35 -5
  6. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/build_identity.py +74 -14
  7. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/build_manifest.py +9 -0
  8. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/component.py +10 -0
  9. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/dsc.py +3 -23
  10. ipsw_parser-1.7.1/ipsw_parser/exceptions.py +10 -0
  11. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/firmware.py +6 -0
  12. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/ipsw.py +14 -0
  13. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/PKG-INFO +3 -1
  14. ipsw_parser-1.6.0/ipsw_parser/_version.py +0 -34
  15. ipsw_parser-1.6.0/ipsw_parser/exceptions.py +0 -6
  16. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.gitattributes +0 -0
  17. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  18. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  19. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.github/workflows/codeql.yml +0 -0
  20. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.github/workflows/python-app.yml +0 -0
  21. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.github/workflows/python-publish.yml +0 -0
  22. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.gitignore +0 -0
  23. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/.pre-commit-config.yaml +0 -0
  24. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/CODE_OF_CONDUCT.md +0 -0
  25. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/LICENSE +0 -0
  26. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser/__init__.py +0 -0
  27. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/SOURCES.txt +0 -0
  28. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/dependency_links.txt +0 -0
  29. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/entry_points.txt +0 -0
  30. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/requires.txt +0 -0
  31. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/ipsw_parser.egg-info/top_level.txt +0 -0
  32. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/pyproject.toml +0 -0
  33. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/pytest.ini +0 -0
  34. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/requirements.txt +0 -0
  35. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/setup.cfg +0 -0
  36. {ipsw_parser-1.6.0 → ipsw_parser-1.7.1}/tests/test_archive_backends.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.6.0
3
+ Version: 1.7.1
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>
@@ -738,5 +738,7 @@ Options:
738
738
  Commands:
739
739
  device-support Create DeviceSupport directory
740
740
  extract Extract .ipsw into filesystem layout
741
+ extract-sandbox-profiles
742
+ Extract decoded sandbox profiles from the kernelcache
741
743
  info Parse given .ipsw basic info
742
744
  ```
@@ -30,5 +30,7 @@ Options:
30
30
  Commands:
31
31
  device-support Create DeviceSupport directory
32
32
  extract Extract .ipsw into filesystem layout
33
+ extract-sandbox-profiles
34
+ Extract decoded sandbox profiles from the kernelcache
33
35
  info Parse given .ipsw basic info
34
36
  ```
@@ -42,7 +42,7 @@ ArchOption = Annotated[Optional[str], typer.Option(help="Arch name to extract us
42
42
 
43
43
  @cli.command("info")
44
44
  def info(ipsw: IpswArgument) -> None:
45
- """Parse given .ipsw basic info"""
45
+ """Print basic metadata for an IPSW."""
46
46
  parsed_ipsw = IPSW.create_from_path(ipsw)
47
47
  print(f"SupportedProductTypes: {parsed_ipsw.build_manifest.supported_product_types}")
48
48
  print(f"ProductVersion: {parsed_ipsw.build_manifest.product_version}")
@@ -57,7 +57,7 @@ def info(ipsw: IpswArgument) -> None:
57
57
 
58
58
  @cli.command("extract")
59
59
  def extract(ipsw: IpswArgument, output: OutputArgument, pem_db: PemDbOption = None) -> None:
60
- """Extract .ipsw into filesystem layout"""
60
+ """Extract an IPSW into the project filesystem layout."""
61
61
  parsed_ipsw = IPSW.create_from_path(ipsw)
62
62
 
63
63
  if not output.exists():
@@ -71,14 +71,25 @@ def extract(ipsw: IpswArgument, output: OutputArgument, pem_db: PemDbOption = No
71
71
 
72
72
  @cli.command("extract-kernel")
73
73
  def extract_kernel(ipsw: IpswArgument, output: OutputArgument, arch: ArchOption = None) -> None:
74
- """Extract kernelcache from given .ipsw into given output filename"""
74
+ """Extract the kernelcache payload into a single output file."""
75
75
  parsed_ipsw = IPSW.create_from_path(ipsw)
76
76
  output.write_bytes(parsed_ipsw.build_manifest.build_identities[0].get_kernelcache_payload(arch=arch))
77
77
 
78
78
 
79
+ @cli.command("extract-sandbox-profiles")
80
+ def extract_sandbox_profiles(ipsw: IpswArgument, output: OutputArgument) -> None:
81
+ """Extract decoded sandbox profiles into the output directory."""
82
+ parsed_ipsw = IPSW.create_from_path(ipsw)
83
+
84
+ if not output.exists():
85
+ output.mkdir(parents=True, exist_ok=True)
86
+
87
+ parsed_ipsw.build_manifest.build_identities[0].extract_sandbox_profiles(output)
88
+
89
+
79
90
  @cli.command("device-support")
80
91
  def device_support(ipsw: IpswArgument, pem_db: PemDbOption = None) -> None:
81
- """Create DeviceSupport directory"""
92
+ """Create an Xcode DeviceSupport directory for an IPSW."""
82
93
  IPSW.create_from_path(ipsw).create_device_support(pem_db=pem_db)
83
94
 
84
95
 
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '1.7.1'
22
+ __version_tuple__ = version_tuple = (1, 7, 1)
23
+
24
+ __commit_id__ = commit_id = 'gc5018741a'
@@ -10,51 +10,77 @@ from zipfile import ZipFile, ZipInfo
10
10
 
11
11
  @dataclass(frozen=True)
12
12
  class ArchiveMember:
13
+ """Metadata describing a single archive entry."""
14
+
13
15
  filename: str
14
16
  file_size: int
15
17
  external_attr: int
16
18
 
17
19
 
18
20
  class Archive(Protocol):
21
+ """Protocol implemented by supported IPSW archive backends."""
22
+
19
23
  @property
20
- def filelist(self) -> list[ArchiveMember]: ...
24
+ def filelist(self) -> list[ArchiveMember]:
25
+ """Return archive members with metadata."""
26
+ ...
21
27
 
22
- def namelist(self) -> list[str]: ...
28
+ def namelist(self) -> list[str]:
29
+ """Return archive member names."""
30
+ ...
23
31
 
24
- def open(self, path: str) -> BinaryIO: ...
32
+ def open(self, path: str) -> BinaryIO:
33
+ """Open an archive member for binary reading."""
34
+ ...
25
35
 
26
- def read(self, path: str) -> bytes: ...
36
+ def read(self, path: str) -> bytes:
37
+ """Read an archive member into memory."""
38
+ ...
27
39
 
28
- def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None: ...
40
+ def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None:
41
+ """Extract the selected archive members into ``path``."""
42
+ ...
29
43
 
30
44
 
31
45
  class ZipArchive:
46
+ """Archive adapter backed by ``zipfile.ZipFile``."""
47
+
32
48
  def __init__(self, archive: ZipFile):
49
+ """Wrap an existing ZIP archive object."""
33
50
  self._archive = archive
34
51
 
35
52
  @property
36
53
  def filelist(self) -> list[ZipInfo]:
54
+ """Return ZIP member metadata."""
37
55
  return self._archive.filelist
38
56
 
39
57
  def namelist(self) -> list[str]:
58
+ """Return ZIP member names."""
40
59
  return self._archive.namelist()
41
60
 
42
61
  def open(self, path: str) -> BinaryIO:
62
+ """Open a ZIP member for binary reading."""
43
63
  return self._archive.open(path)
44
64
 
45
65
  def read(self, path: str) -> bytes:
66
+ """Read a ZIP member into memory."""
46
67
  return self._archive.read(path)
47
68
 
48
69
  def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None:
70
+ """Extract the selected ZIP members into ``path``."""
49
71
  self._archive.extractall(path=path, members=members)
50
72
 
51
73
 
52
74
  class DirectoryArchive:
75
+ """Archive adapter that exposes a directory tree like an IPSW archive."""
76
+
53
77
  def __init__(self, root: Path):
78
+ """Wrap an extracted IPSW directory."""
54
79
  self._root = root
55
80
 
56
81
  @cached_property
57
82
  def filelist(self) -> list[ArchiveMember]:
83
+ """Return filesystem entries as archive-style metadata."""
58
84
  result = []
59
85
  for file_path in sorted(path for path in self._root.rglob("*") if path.is_file()):
60
86
  file_stat = file_path.stat()
@@ -70,15 +96,19 @@ class DirectoryArchive:
70
96
  return result
71
97
 
72
98
  def namelist(self) -> list[str]:
99
+ """Return relative file paths under the archive root."""
73
100
  return [member.filename for member in self.filelist]
74
101
 
75
102
  def open(self, path: str) -> BinaryIO:
103
+ """Open a file relative to the archive root."""
76
104
  return (self._root / path).open("rb")
77
105
 
78
106
  def read(self, path: str) -> bytes:
107
+ """Read a file relative to the archive root."""
79
108
  return (self._root / path).read_bytes()
80
109
 
81
110
  def extractall(self, path: Path, members: Iterable[Union[ArchiveMember, ZipInfo, str]]) -> None:
111
+ """Copy the selected members into ``path``."""
82
112
  for member in members:
83
113
  filename = member if isinstance(member, str) else member.filename
84
114
  source = self._root / filename
@@ -21,7 +21,7 @@ AEA_MAGIC = b"AEA1"
21
21
 
22
22
 
23
23
  def extract_as(archive: Archive, member_name, output_path, chunk_size=64 * 1024):
24
- """Extract a single member from a ZIP archive to a custom output path"""
24
+ """Extract one archive member into a caller-provided path."""
25
25
  os.makedirs(os.path.dirname(output_path), exist_ok=True)
26
26
  with archive.open(member_name) as source, open(output_path, "wb") as target:
27
27
  shutil.copyfileobj(source, target, length=chunk_size)
@@ -65,45 +65,99 @@ def _extract_dmg(dmg: Path, output: Path, sub_path: Optional[Path] = None, pem_d
65
65
  hdiutil("detach", "-force", mnt)
66
66
 
67
67
 
68
+ def _decode_sandbox_profiles(kernel_output: Path, output: Path, profile_type: Optional[str] = None) -> None:
69
+ ipsw = local["ipsw"]
70
+ args = ["sb", "list", kernel_output]
71
+ if profile_type is not None:
72
+ args += ["--type", profile_type]
73
+
74
+ output.mkdir(exist_ok=True, parents=True)
75
+
76
+ for profile_name in ipsw(*args).splitlines():
77
+ profile_path = (output / profile_name).with_suffix(".sb")
78
+ decode_args = ["sb", "dec", kernel_output, profile_name]
79
+ if profile_type is not None:
80
+ decode_args += ["--type", profile_type]
81
+ try:
82
+ profile = ipsw(*decode_args)
83
+ except ProcessExecutionError as e:
84
+ logger.warning(f"failed to decode sandbox profile {profile_name}: {e}")
85
+ continue
86
+ profile_path.write_text(profile)
87
+
88
+
89
+ def _extract_kernelcache(build_identity: "BuildIdentity", output: Path) -> Path:
90
+ kernel_component = build_identity.get_component("KernelCache")
91
+ kernel_path = Path(kernel_component.path)
92
+ kernel_output = output / kernel_path.parts[-1]
93
+ output.mkdir(parents=True, exist_ok=True)
94
+
95
+ logger.info(f"extracting kernel into: {kernel_output}")
96
+ im4p = IM4P(kernel_component.data)
97
+ im4p.payload.decompress()
98
+ kernel_output.write_bytes(im4p.payload.output().data)
99
+ try:
100
+ # In case the kernel is a FAT image, extract the arm64 macho
101
+ local["ipsw"]("macho", "lipo", "-a", "arm64", kernel_output)
102
+ next(iter(kernel_output.parent.glob("*.arm64"))).rename(kernel_output)
103
+ except ProcessExecutionError:
104
+ pass
105
+
106
+ return kernel_output
107
+
108
+
68
109
  class BuildIdentity(UserDict):
110
+ """Dictionary-backed wrapper for a single build identity."""
111
+
69
112
  def __init__(self, build_manifest, data):
113
+ """Wrap a single BuildIdentity entry from the manifest."""
70
114
  super().__init__(data)
71
115
  self.build_manifest = build_manifest
72
116
 
73
117
  @cached_property
74
118
  def device_class(self) -> str:
119
+ """Return the normalized device class for this build identity."""
75
120
  return self["Info"]["DeviceClass"].lower()
76
121
 
77
122
  @cached_property
78
123
  def restore_behavior(self) -> str:
124
+ """Return the restore behavior declared by the build identity."""
79
125
  return self["Info"].get("RestoreBehavior")
80
126
 
81
127
  @cached_property
82
128
  def variant(self):
129
+ """Return the variant string for this build identity."""
83
130
  return self["Info"].get("Variant")
84
131
 
85
132
  @cached_property
86
133
  def macos_variant(self) -> str:
134
+ """Return the macOS restore variant, if present."""
87
135
  return self["Info"].get("MacOSVariant")
88
136
 
89
137
  @cached_property
90
138
  def manifest(self) -> dict:
139
+ """Return the component manifest dictionary."""
91
140
  return self["Manifest"]
92
141
 
93
142
  @cached_property
94
143
  def minimum_system_partition(self):
144
+ """Return the minimum system partition requirement, if present."""
95
145
  return self["Info"].get("MinimumSystemPartition")
96
146
 
97
147
  def get_component_path(self, component: str) -> str:
148
+ """Return the archive path for a named component."""
98
149
  return self.manifest[component]["Info"]["Path"]
99
150
 
100
151
  def has_component(self, name: str) -> bool:
152
+ """Return whether the build identity contains a named component."""
101
153
  return name in self.manifest
102
154
 
103
155
  def get_component(self, name: str, **args) -> Component:
156
+ """Return a component wrapper for a named manifest entry."""
104
157
  return Component(self, name, **args)
105
158
 
106
159
  def extract_dsc(self, output: Path, pem_db: Optional[str] = None, split: bool = True) -> None:
160
+ """Extract the system cryptex DSC payloads into ``output``."""
107
161
  build_identity = self.build_manifest.build_identities[0]
108
162
  if not build_identity.has_component("Cryptex1,SystemOS"):
109
163
  return
@@ -120,6 +174,7 @@ class BuildIdentity(UserDict):
120
174
  split_dsc(output)
121
175
 
122
176
  def get_kernelcache_payload(self, arch: Optional[str] = None) -> bytes:
177
+ """Return the decompressed kernelcache payload, optionally sliced by arch."""
123
178
  im4p = IM4P(self.build_manifest.build_identities[0].get_component("KernelCache").data)
124
179
  im4p.payload.decompress()
125
180
  payload = im4p.payload.output().data
@@ -131,7 +186,16 @@ class BuildIdentity(UserDict):
131
186
  local["ipsw"]("macho", "lipo", "-a", arch, kernel_output)
132
187
  return Path(next(kernel_output.parent.glob(f"*.{arch}"))).read_bytes()
133
188
 
189
+ def extract_sandbox_profiles(self, output: Path) -> None:
190
+ """Decode normal and protobox sandbox profiles into ``output``."""
191
+ output.mkdir(parents=True, exist_ok=True)
192
+ with TemporaryDirectory() as temp_dir:
193
+ kernel_output = _extract_kernelcache(self, Path(temp_dir))
194
+ _decode_sandbox_profiles(kernel_output, output)
195
+ _decode_sandbox_profiles(kernel_output, output / "protobox", profile_type="protobox")
196
+
134
197
  def extract(self, output: Path, pem_db: Optional[str] = None) -> None:
198
+ """Extract the build identity contents into a filesystem layout."""
135
199
  logger.info(f"extracting into: {output}")
136
200
 
137
201
  build_identity = self.build_manifest.build_identities[0]
@@ -143,21 +207,17 @@ class BuildIdentity(UserDict):
143
207
  extract_as(self.build_manifest.ipsw.archive, os_component_path, os_dmg)
144
208
  _extract_dmg(os_dmg, output, pem_db=pem_db)
145
209
 
146
- kernel_component = build_identity.get_component("KernelCache")
147
- kernel_path = Path(kernel_component.path)
148
- kernel_output = output / "System/Library/Caches/com.apple.kernelcaches" / kernel_path.parts[-1]
149
- kernel_output.parent.mkdir(parents=True, exist_ok=True)
210
+ kernel_output = _extract_kernelcache(self, output / "System/Library/Caches/com.apple.kernelcaches")
211
+ sandbox_profiles = output / "sandbox/profiles"
150
212
 
151
- logger.info(f"extracting kernel into: {kernel_output}")
152
- im4p = IM4P(kernel_component.data)
153
- im4p.payload.decompress()
154
- kernel_output.write_bytes(im4p.payload.output().data)
155
213
  try:
156
- # In case the kernel is a FAT image, extract the arm64 macho
157
- local["ipsw"]("macho", "lipo", "-a", "arm64", kernel_output)
158
- next(iter(kernel_output.parent.glob("*.arm64"))).rename(kernel_output)
159
- except ProcessExecutionError:
160
- pass
214
+ _decode_sandbox_profiles(kernel_output, sandbox_profiles)
215
+ except ProcessExecutionError as e:
216
+ logger.error("Failed to extract sandbox profiles: %s", e)
217
+ try:
218
+ _decode_sandbox_profiles(kernel_output, sandbox_profiles / "protobox", profile_type="protobox")
219
+ except ProcessExecutionError as e:
220
+ logger.error("Failed to extract sandbox profiles: %s", e)
161
221
 
162
222
  for cryptex in ("App", "OS"):
163
223
  name = {
@@ -7,13 +7,17 @@ from ipsw_parser.exceptions import NoSuchBuildIdentityError
7
7
 
8
8
 
9
9
  class BuildManifest:
10
+ """Parsed ``BuildManifest.plist`` wrapper with lookup helpers."""
11
+
10
12
  def __init__(self, ipsw, manifest: bytes):
13
+ """Parse a BuildManifest plist for the given IPSW."""
11
14
  self.ipsw = ipsw
12
15
  self._manifest = plistlib.loads(manifest)
13
16
  self._parse_build_identities()
14
17
 
15
18
  @cached_property
16
19
  def build_major(self) -> int:
20
+ """Return the numeric major portion of the build version."""
17
21
  build_major = ""
18
22
  for i in self._manifest["ProductBuildVersion"]:
19
23
  if i.isdigit():
@@ -25,10 +29,12 @@ class BuildManifest:
25
29
 
26
30
  @cached_property
27
31
  def supported_product_types(self) -> list[str]:
32
+ """Return supported product identifiers from the manifest."""
28
33
  return self._manifest["SupportedProductTypes"]
29
34
 
30
35
  @cached_property
31
36
  def supported_product_types_family(self) -> str:
37
+ """Return the broad device family inferred from the first product type."""
32
38
  product = self.supported_product_types[0]
33
39
  if product.startswith("iBridge"):
34
40
  return "iBridge"
@@ -41,15 +47,18 @@ class BuildManifest:
41
47
 
42
48
  @cached_property
43
49
  def product_version(self) -> str:
50
+ """Return the product version from the manifest."""
44
51
  return self._manifest["ProductVersion"]
45
52
 
46
53
  @cached_property
47
54
  def product_build_version(self) -> str:
55
+ """Return the product build version from the manifest."""
48
56
  return self._manifest["ProductBuildVersion"]
49
57
 
50
58
  def get_build_identity(
51
59
  self, device_class: str, restore_behavior: Optional[str] = None, variant: Optional[str] = None
52
60
  ) -> BuildIdentity:
61
+ """Return the first build identity matching the requested filters."""
53
62
  for build_identity in self.build_identities:
54
63
  if variant is not None and variant not in build_identity.variant:
55
64
  continue
@@ -7,8 +7,11 @@ from ipsw_parser.exceptions import IpswException
7
7
 
8
8
 
9
9
  class TSSResponse(dict):
10
+ """Dictionary wrapper for TSS response payloads."""
11
+
10
12
  @property
11
13
  def ap_img4_ticket(self):
14
+ """Return the AP IMG4 ticket from the TSS response."""
12
15
  ticket = self.get("ApImg4Ticket")
13
16
 
14
17
  if ticket is None:
@@ -18,9 +21,11 @@ class TSSResponse(dict):
18
21
 
19
22
  @property
20
23
  def bb_ticket(self):
24
+ """Return the baseband ticket from the TSS response, if present."""
21
25
  return self.get("BBTicket")
22
26
 
23
27
  def get_path_by_entry(self, component: str):
28
+ """Return the path for a component entry in the TSS response."""
24
29
  node = self.get(component)
25
30
  if node is not None:
26
31
  return node.get("Path")
@@ -29,6 +34,8 @@ class TSSResponse(dict):
29
34
 
30
35
 
31
36
  class Component:
37
+ """Resolved view of a build identity component."""
38
+
32
39
  def __init__(
33
40
  self,
34
41
  build_identity,
@@ -37,6 +44,7 @@ class Component:
37
44
  data: Optional[bytes] = None,
38
45
  path: Optional[str] = None,
39
46
  ):
47
+ """Create a component view for a build identity entry."""
40
48
  self.logger = logging.getLogger(__name__)
41
49
  self._tss = tss
42
50
  self.build_identity = build_identity
@@ -46,6 +54,7 @@ class Component:
46
54
 
47
55
  @cached_property
48
56
  def path(self) -> str:
57
+ """Resolve the component path from TSS data or the build manifest."""
49
58
  if self._path:
50
59
  return self._path
51
60
 
@@ -66,6 +75,7 @@ class Component:
66
75
 
67
76
  @cached_property
68
77
  def data(self) -> bytes:
78
+ """Return the component payload bytes."""
69
79
  if self._data is None:
70
80
  self.logger.debug(f"Extracting {os.path.basename(self.path)} ({self.path})")
71
81
  return self.build_identity.build_manifest.ipsw.read(self.path)
@@ -9,6 +9,7 @@ logger = logging.getLogger(__name__)
9
9
 
10
10
 
11
11
  def split_dsc(root: Path) -> None:
12
+ """Split dyld shared caches found under ``root`` using ``ipsw dyld split``."""
12
13
  ipsw = local["ipsw"]
13
14
  dsc_paths = [
14
15
  root / "System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64",
@@ -26,17 +27,7 @@ def split_dsc(root: Path) -> None:
26
27
 
27
28
 
28
29
  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
- """
30
+ """Return the Xcode DeviceSupport path for the given product metadata."""
40
31
  device_support_path = Path("~/Library/Developer/Xcode/iOS DeviceSupport").expanduser()
41
32
  device_support_path /= f"{product_type} {product_version} ({product_build_version})"
42
33
  return device_support_path
@@ -45,18 +36,7 @@ def get_device_support_path(product_type: str, product_version: str, product_bui
45
36
  def create_device_support_layout(
46
37
  product_type: str, product_version: str, product_build_version: str, root_path: Path
47
38
  ) -> 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
- """
39
+ """Create the Xcode DeviceSupport layout for extracted symbol files."""
60
40
  device_support_path = get_device_support_path(product_type, product_version, product_build_version)
61
41
 
62
42
  # Split DSC files
@@ -0,0 +1,10 @@
1
+ class IpswException(Exception):
2
+ """Base exception for IPSW parser failures."""
3
+
4
+ pass
5
+
6
+
7
+ class NoSuchBuildIdentityError(IpswException):
8
+ """Raised when a matching build identity cannot be found."""
9
+
10
+ pass
@@ -1,5 +1,8 @@
1
1
  class Firmware:
2
+ """Helper for firmware manifests and component file mapping."""
3
+
2
4
  def __init__(self, firmware_path: str, ipsw):
5
+ """Index firmware manifest entries under a firmware directory."""
3
6
  self._ipsw = ipsw
4
7
  self._firmware_path = firmware_path
5
8
  self._manifest_data = self._ipsw.read(self.get_relative_path("manifest"))
@@ -10,13 +13,16 @@ class Firmware:
10
13
  self._firmware_files[component_name] = f"{firmware_path}/{filename}"
11
14
 
12
15
  def get_relative_path(self, path: str):
16
+ """Return a firmware-relative archive path."""
13
17
  return f"{self._firmware_path}/{path}"
14
18
 
15
19
  def get_files(self):
20
+ """Return the indexed firmware component mapping."""
16
21
  return self._firmware_files
17
22
 
18
23
  @staticmethod
19
24
  def get_component_name(filename):
25
+ """Map a firmware filename to its logical component name."""
20
26
  names = {
21
27
  "LLB": "LLB",
22
28
  "iBoot": "iBoot",
@@ -35,8 +35,11 @@ cpio_odc_header = Struct(
35
35
 
36
36
 
37
37
  class IPSW:
38
+ """High-level interface for reading and extracting IPSW contents."""
39
+
38
40
  @classmethod
39
41
  def create_from_path(cls, value: str) -> "IPSW":
42
+ """Create an ``IPSW`` from a local path, extracted directory, or URL."""
40
43
  if value.startswith("http://") or value.startswith("https://"):
41
44
  return cls(ZipArchive(RemoteZip(value)))
42
45
 
@@ -47,6 +50,7 @@ class IPSW:
47
50
  return cls(ZipArchive(ZipFile(path)))
48
51
 
49
52
  def __init__(self, archive: Archive):
53
+ """Create an IPSW wrapper around an archive backend."""
50
54
  self.archive = archive
51
55
  self._logger = logging.getLogger(__file__)
52
56
  self.build_manifest = BuildManifest(
@@ -58,18 +62,22 @@ class IPSW:
58
62
 
59
63
  @cached_property
60
64
  def restore_version(self) -> bytes:
65
+ """Return the raw ``RestoreVersion.plist`` payload."""
61
66
  return self.read("RestoreVersion.plist")
62
67
 
63
68
  @cached_property
64
69
  def system_version(self) -> bytes:
70
+ """Return the raw ``SystemVersion.plist`` payload."""
65
71
  return self.read("SystemVersion.plist")
66
72
 
67
73
  @cached_property
68
74
  def filelist(self) -> list[ArchiveMember]:
75
+ """Return archive members for the IPSW."""
69
76
  return self.archive.filelist
70
77
 
71
78
  @contextmanager
72
79
  def open_path(self, path: str):
80
+ """Open an IPSW member and close it automatically on exit."""
73
81
  file = self.archive.open(path)
74
82
  try:
75
83
  yield file
@@ -78,6 +86,7 @@ class IPSW:
78
86
 
79
87
  @property
80
88
  def bootability(self) -> bytes:
89
+ """Build a cpio archive containing bootability bundle payloads."""
81
90
  result = b""
82
91
  prefix = "BootabilityBundle/Restore/Bootability/"
83
92
  inode = 1
@@ -126,16 +135,20 @@ class IPSW:
126
135
  return result
127
136
 
128
137
  def read(self, path: str) -> bytes:
138
+ """Read an IPSW member into memory."""
129
139
  return self.archive.read(path)
130
140
 
131
141
  def get_global_manifest(self, macos_variant: str, device_class: str) -> bytes:
142
+ """Return the restore manifest for a macOS variant and device class."""
132
143
  manifest_path = f"Firmware/Manifests/restore/{macos_variant}/apticket.{device_class}.im4m"
133
144
  return self.read(manifest_path)
134
145
 
135
146
  def get_firmware(self, firmware_path: str) -> Firmware:
147
+ """Return a firmware helper rooted at ``firmware_path``."""
136
148
  return Firmware(firmware_path, self)
137
149
 
138
150
  def get_development_files(self) -> list[str]:
151
+ """Return archive entries associated with development builds."""
139
152
  result = []
140
153
  for entry in self.archive.namelist():
141
154
  for release in ("devel", "kasan", "research"):
@@ -144,6 +157,7 @@ class IPSW:
144
157
  return result
145
158
 
146
159
  def create_device_support(self, pem_db: Optional[str] = None) -> None:
160
+ """Create an Xcode DeviceSupport directory for this IPSW."""
147
161
  device_support_path = Path("~/Library/Developer/Xcode/iOS DeviceSupport").expanduser()
148
162
  device_support_path /= (
149
163
  f"{self.build_manifest.supported_product_types[0]} "
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.6.0
3
+ Version: 1.7.1
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>
@@ -738,5 +738,7 @@ Options:
738
738
  Commands:
739
739
  device-support Create DeviceSupport directory
740
740
  extract Extract .ipsw into filesystem layout
741
+ extract-sandbox-profiles
742
+ Extract decoded sandbox profiles from the kernelcache
741
743
  info Parse given .ipsw basic info
742
744
  ```
@@ -1,34 +0,0 @@
1
- # file generated by setuptools-scm
2
- # don't change, don't track in version control
3
-
4
- __all__ = [
5
- "__version__",
6
- "__version_tuple__",
7
- "version",
8
- "version_tuple",
9
- "__commit_id__",
10
- "commit_id",
11
- ]
12
-
13
- TYPE_CHECKING = False
14
- if TYPE_CHECKING:
15
- from typing import Tuple
16
- from typing import Union
17
-
18
- VERSION_TUPLE = Tuple[Union[int, str], ...]
19
- COMMIT_ID = Union[str, None]
20
- else:
21
- VERSION_TUPLE = object
22
- COMMIT_ID = object
23
-
24
- version: str
25
- __version__: str
26
- __version_tuple__: VERSION_TUPLE
27
- version_tuple: VERSION_TUPLE
28
- commit_id: COMMIT_ID
29
- __commit_id__: COMMIT_ID
30
-
31
- __version__ = version = '1.6.0'
32
- __version_tuple__ = version_tuple = (1, 6, 0)
33
-
34
- __commit_id__ = commit_id = 'g0e931b7f6'
@@ -1,6 +0,0 @@
1
- class IpswException(Exception):
2
- pass
3
-
4
-
5
- class NoSuchBuildIdentityError(IpswException):
6
- pass
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes