Skip to content

Commit

Permalink
Merge pull request #18 from doronz88/feature/aea_support
Browse files Browse the repository at this point in the history
build_identity: Handle `AEA` decryption
  • Loading branch information
doronz88 authored Jun 18, 2024
2 parents 20ac06f + 0f9be35 commit d799dac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@ jobs:
strategy:
matrix:
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
os: [ macos-latest ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Lint with flake8
- name: Install dependencies
run: |
python -m pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82,F401,E741 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Verify sorted imports
brew install blacktop/tap/ipsw
python3 -m pip install --upgrade pip
python3 -m pip install pre-commit
- name: Run pre-commit hooks
run: |
python -m pip install isort
isort . -m HANGING_INDENT -l 120 --check-only
pre-commit run --all-files
- name: Test install
run: |
python -m pip install --upgrade pip
python -m pip install -U .
- name: Test show usage
run: |
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.9.3
hooks:
- id: isort
args: [ '-m', 'HANGING_INDENT', '-l', '120','--check-only' ]
files: \.py$

- repo: https://github.com/pycqa/flake8
rev: "7.0.0"
hooks:
- id: flake8
args: [ '--count', '--select=E9,F63,F7,F82,F401,E741', '--show-source', '--statistics', '--max-complexity=10', '--max-line-length=127' ]
files: \.py$
21 changes: 10 additions & 11 deletions ipsw_parser/build_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@
from typing import List, Mapping

from cached_property import cached_property
from plumbum import CommandNotFound, local
from plumbum import local

from ipsw_parser.component import Component

logger = logging.getLogger(__name__)
ipsw = local['ipsw']


def _extract_dmg(buf: bytes, output: Path) -> None:
hdiutil = local['hdiutil']

# darwin system statistically have problems cleaning up after detaching the mountpoint
with TemporaryDirectory() as temp_dir:
temp_dir = Path(temp_dir)

mnt = temp_dir / 'mnt'
mnt.mkdir()

dmg = temp_dir / 'image.dmg'
dmg.write_bytes(buf)

if buf.startswith(b'AEA1'):
logger.debug('Found Apple Encrypted Archive. Decrypting...')
dmg_aea = Path(str(dmg) + '.aea')
dmg_aea.write_bytes(buf)
ipsw('fw', 'aea', dmg_aea, '-o', temp_dir)
else:
dmg.write_bytes(buf)

hdiutil('attach', '-mountpoint', mnt, dmg)

Expand Down Expand Up @@ -139,12 +144,6 @@ def extract(self, output: Path) -> None:
logger.info(f'extracting {name} into: {cryptex_path}')
_extract_dmg(build_identity.get_component(name).data, cryptex_path)

try:
ipsw = local['ipsw']
except CommandNotFound:
logger.warning('skipping DSC split since no blacktop/ipsw could not be found in path')
return

dsc_paths = [output / 'System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64',
output / 'System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e',
output / 'System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64',
Expand Down

0 comments on commit d799dac

Please sign in to comment.