ipsw-parser 1.4.2__tar.gz → 1.4.4__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 (31) hide show
  1. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/PKG-INFO +1 -1
  2. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/_version.py +2 -2
  3. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/build_identity.py +36 -12
  4. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/PKG-INFO +1 -1
  5. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.gitattributes +0 -0
  6. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  7. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  8. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.github/workflows/codeql.yml +0 -0
  9. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.github/workflows/python-app.yml +0 -0
  10. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.github/workflows/python-publish.yml +0 -0
  11. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.gitignore +0 -0
  12. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/.pre-commit-config.yaml +0 -0
  13. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/CODE_OF_CONDUCT.md +0 -0
  14. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/LICENSE +0 -0
  15. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/README.md +0 -0
  16. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/__init__.py +0 -0
  17. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/__main__.py +0 -0
  18. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/build_manifest.py +0 -0
  19. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/component.py +0 -0
  20. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/exceptions.py +0 -0
  21. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/firmware.py +0 -0
  22. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser/ipsw.py +0 -0
  23. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/SOURCES.txt +0 -0
  24. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/dependency_links.txt +0 -0
  25. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/entry_points.txt +0 -0
  26. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/requires.txt +0 -0
  27. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/ipsw_parser.egg-info/top_level.txt +0 -0
  28. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/pyproject.toml +0 -0
  29. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/pytest.ini +0 -0
  30. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/requirements.txt +0 -0
  31. {ipsw_parser-1.4.2 → ipsw_parser-1.4.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.4.2
3
+ Version: 1.4.4
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>
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '1.4.2'
21
- __version_tuple__ = version_tuple = (1, 4, 2)
20
+ __version__ = version = '1.4.4'
21
+ __version_tuple__ = version_tuple = (1, 4, 4)
@@ -1,9 +1,11 @@
1
1
  import logging
2
+ import os
2
3
  import shutil
3
4
  from collections import UserDict
4
5
  from pathlib import Path
5
6
  from tempfile import TemporaryDirectory
6
7
  from typing import Optional
8
+ from zipfile import ZipFile
7
9
 
8
10
  import requests
9
11
  from cached_property import cached_property
@@ -14,8 +16,17 @@ from ipsw_parser.component import Component
14
16
 
15
17
  logger = logging.getLogger(__name__)
16
18
 
19
+ AEA_MAGIC = b'AEA1'
17
20
 
18
- def _extract_dmg(buf: bytes, output: Path, sub_path: Optional[Path] = None, pem_db: Optional[str] = None) -> None:
21
+
22
+ def extract_as(zipf: ZipFile, member_name, output_path, chunk_size=64 * 1024):
23
+ """Extract a single member from a ZIP archive to a custom output path"""
24
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
25
+ with zipf.open(member_name) as source, open(output_path, 'wb') as target:
26
+ shutil.copyfileobj(source, target, length=chunk_size)
27
+
28
+
29
+ def _extract_dmg(dmg: Path, output: Path, sub_path: Optional[Path] = None, pem_db: Optional[str] = None) -> None:
19
30
  ipsw = local['ipsw']
20
31
  hdiutil = local['hdiutil']
21
32
  # darwin system statistically have problems cleaning up after detaching the mountpoint
@@ -23,13 +34,15 @@ def _extract_dmg(buf: bytes, output: Path, sub_path: Optional[Path] = None, pem_
23
34
  temp_dir = Path(temp_dir)
24
35
  mnt = temp_dir / 'mnt'
25
36
  mnt.mkdir()
26
- dmg = temp_dir / 'image.dmg'
27
37
 
28
- if buf.startswith(b'AEA1'):
38
+ with dmg.open('rb') as f:
39
+ magic = f.read(len(AEA_MAGIC))
40
+ if magic == AEA_MAGIC:
29
41
  logger.debug('Found Apple Encrypted Archive. Decrypting...')
30
- dmg_aea = Path(str(dmg) + '.aea')
31
- dmg_aea.write_bytes(buf)
32
- args = ['fw', 'aea', dmg_aea, '-o', temp_dir]
42
+ aea_dmg = str(dmg.absolute()) + '.aea'
43
+ dmg.rename(aea_dmg)
44
+ dmg = temp_dir / Path(aea_dmg).name.rsplit('.', 1)[0]
45
+ args = ['fw', 'aea', aea_dmg, '-o', temp_dir]
33
46
  if pem_db is not None:
34
47
  if '://' in pem_db:
35
48
  # create a local file containing it
@@ -38,8 +51,6 @@ def _extract_dmg(buf: bytes, output: Path, sub_path: Optional[Path] = None, pem_
38
51
  pem_db = temp_pem_db
39
52
  args += ['--pem-db', pem_db]
40
53
  ipsw(args)
41
- else:
42
- dmg.write_bytes(buf)
43
54
 
44
55
  hdiutil('attach', '-mountpoint', mnt, dmg)
45
56
 
@@ -118,8 +129,12 @@ class BuildIdentity(UserDict):
118
129
  device_support_symbols_path = output / 'private/preboot/Cryptexes/OS/System'
119
130
  device_support_symbols_path.mkdir(parents=True, exist_ok=True)
120
131
 
121
- _extract_dmg(build_identity.get_component('Cryptex1,SystemOS').data, device_support_symbols_path,
122
- sub_path=Path('System'), pem_db=pem_db)
132
+ with TemporaryDirectory() as temp_dir:
133
+ system_os = Path(temp_dir) / 'system_os.dmg'
134
+ system_os_component_path = build_identity.get_component_path('Cryptex1,SystemOS')
135
+ extract_as(self.build_manifest.ipsw.archive, system_os_component_path, system_os)
136
+ _extract_dmg(system_os, device_support_symbols_path,
137
+ sub_path=Path('System'), pem_db=pem_db)
123
138
  _split_dsc(output)
124
139
 
125
140
  def get_kernelcache_payload(self, arch: Optional[str] = None) -> bytes:
@@ -140,11 +155,16 @@ class BuildIdentity(UserDict):
140
155
  build_identity = self.build_manifest.build_identities[0]
141
156
 
142
157
  logger.info(f'extracting OS into: {output}')
143
- _extract_dmg(build_identity.get_component('OS').data, output, pem_db=pem_db)
158
+ with TemporaryDirectory() as temp_dir:
159
+ os_dmg = Path(temp_dir) / 'os.dmg'
160
+ os_component_path = build_identity.get_component_path('OS')
161
+ extract_as(self.build_manifest.ipsw.archive, os_component_path, os_dmg)
162
+ _extract_dmg(os_dmg, output, pem_db=pem_db)
144
163
 
145
164
  kernel_component = build_identity.get_component('KernelCache')
146
165
  kernel_path = Path(kernel_component.path)
147
166
  kernel_output = output / 'System/Library/Caches/com.apple.kernelcaches' / kernel_path.parts[-1]
167
+ kernel_output.parent.mkdir(parents=True, exist_ok=True)
148
168
 
149
169
  logger.info(f'extracting kernel into: {kernel_output}')
150
170
  im4p = IM4P(kernel_component.data)
@@ -170,6 +190,10 @@ class BuildIdentity(UserDict):
170
190
  cryptex_path.mkdir(parents=True, exist_ok=True)
171
191
 
172
192
  logger.info(f'extracting {name} into: {cryptex_path}')
173
- _extract_dmg(build_identity.get_component(name).data, cryptex_path, pem_db=pem_db)
193
+ with TemporaryDirectory() as temp_dir:
194
+ temp_component = (Path(temp_dir) / name).with_suffix('.dmg')
195
+ component_path = build_identity.get_component_path(name)
196
+ extract_as(self.build_manifest.ipsw.archive, component_path, temp_component)
197
+ _extract_dmg(temp_component, cryptex_path, pem_db=pem_db)
174
198
 
175
199
  _split_dsc(output)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipsw-parser
3
- Version: 1.4.2
3
+ Version: 1.4.4
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>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes