Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Commit 2d252d4

Browse files
authored
Merge pull request #30 from KritantaDev/master
Backport to python 3.8.0
2 parents 8471c9b + 661ed5c commit 2d252d4

File tree

10 files changed

+66
-65
lines changed

10 files changed

+66
-65
lines changed

bin/dyldex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import mmap
88
import os
99
import sys
1010
from io import BufferedReader
11-
12-
try:
13-
assert sys.version_info >= (3, 9, 5)
14-
except AssertionError:
15-
print("Python 3.9.5 or greater is required", file=sys.stderr)
16-
exit(1)
17-
11+
from typing import List
1812
try:
1913
progressbar.streams
2014
except AttributeError:
@@ -123,7 +117,7 @@ def _extractImage(
123117
statusBar.update(unit="Extractor", status="Done")
124118

125119

126-
def _filterImages(imagePaths: list[str], filterTerm: str):
120+
def _filterImages(imagePaths: List[str], filterTerm: str):
127121
filteredPaths = []
128122
filterTerm = filterTerm.lower()
129123

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
description='Extract Binaries from Apple\'s Dyld Shared Cache',
66
long_description='file: README.md',
77
long_description_content_type='text/markdown',
8-
python_requires='>=3.9.5',
8+
python_requires='>=3.8',
99
author='arandomdev',
1010
url='https://github.com/arandomdev/dyldextractor',
1111
install_requires=['progressbar2', 'capstone==4.0.2'],

src/DyldExtractor/converter/objc_fixer.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import struct
22
import ctypes
3+
from typing import List, Set, Dict, Tuple
34
import capstone as cp
45

56
from DyldExtractor.extraction_context import ExtractionContext
@@ -289,7 +290,7 @@ def _findAddInstr(
289290

290291
return None
291292

292-
def _getOpcodes(self, opStr: str) -> list[str]:
293+
def _getOpcodes(self, opStr: str) -> List[str]:
293294
return [
294295
opcode.strip()
295296
for opcode
@@ -416,7 +417,7 @@ def run(self) -> None:
416417
pass
417418
pass
418419

419-
def _disasmText(self) -> tuple[int, str, tuple[str]]:
420+
def _disasmText(self) -> Tuple[int, str, Tuple[str]]:
420421
"""Disassemble and save the __text section."""
421422

422423
self._statusBar.update(status="Disassembling Text (will appear frozen)")
@@ -478,8 +479,8 @@ def _findAddInstructions(
478479
self,
479480
startIdx: int,
480481
adrpReg: str,
481-
_processed: set[int] = None
482-
) -> set[int]:
482+
_processed: Set[int] = None
483+
) -> Set[int]:
483484
"""Find ADD instructions given an ADRP register.
484485
485486
This will recursively follow branches and stop
@@ -626,28 +627,28 @@ def run(self):
626627

627628
# caches that map the original definition address
628629
# to its new processed address.
629-
self._categoryCache: dict[int, int] = {}
630-
self._classCache: dict[int, int] = {}
631-
self._classDataCache: dict[int, int] = {}
632-
self._ivarListCache: dict[int, int] = {}
633-
self._protocolListCache: dict[int, int] = {}
634-
self._protocolCache: dict[int, int] = {}
635-
self._propertyListCache: dict[int, int] = {}
636-
self._methodListCache: dict[int, int] = {}
637-
self._stringCache: dict[int, int] = {}
638-
self._intCache: dict[int, int] = {}
630+
self._categoryCache: Dict[int, int] = {}
631+
self._classCache: Dict[int, int] = {}
632+
self._classDataCache: Dict[int, int] = {}
633+
self._ivarListCache: Dict[int, int] = {}
634+
self._protocolListCache: Dict[int, int] = {}
635+
self._protocolCache: Dict[int, int] = {}
636+
self._propertyListCache: Dict[int, int] = {}
637+
self._methodListCache: Dict[int, int] = {}
638+
self._stringCache: Dict[int, int] = {}
639+
self._intCache: Dict[int, int] = {}
639640

640641
# connects a selrefs old target to its pointer address
641-
self._selRefCache: dict[int, int] = {}
642+
self._selRefCache: Dict[int, int] = {}
642643

643644
# A list of class pointers that are being processed.
644-
self._classesProcessing: list[int] = []
645+
self._classesProcessing: List[int] = []
645646

646647
# A list of pointers that need to be updated at the end
647648
# The first int is the address to the pointer that needs
648649
# to be changed. The second int is the address of the
649650
# target class
650-
self._futureClasses: list[tuple[int, int]] = []
651+
self._futureClasses: List[Tuple[int, int]] = []
651652

652653
self._processSections()
653654
self._finalizeFutureClasses()
@@ -858,7 +859,7 @@ def _processCategory(self, categoryAddr: int) -> int:
858859
self._categoryCache[categoryAddr] = newCategoryAddr
859860
return newCategoryAddr
860861

861-
def _processClass(self, classAddr: int) -> tuple[int, bool]:
862+
def _processClass(self, classAddr: int) -> Tuple[int, bool]:
862863
"""Process a class definition.
863864
864865
Args:

src/DyldExtractor/converter/slide_info.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Type,
44
TypeVar,
55
Union,
6+
Tuple,
7+
List
68
)
79

810
from DyldExtractor.extraction_context import ExtractionContext
@@ -65,7 +67,7 @@ def run(self) -> None:
6567

6668
def _rebaseSegment(
6769
self,
68-
pageStarts: tuple[int],
70+
pageStarts: Tuple[int],
6971
segment: segment_command_64
7072
) -> None:
7173
"""Process all slide info for a segment"""
@@ -170,7 +172,7 @@ def run(self) -> None:
170172

171173
def _rebaseSegment(
172174
self,
173-
pageStarts: tuple[int],
175+
pageStarts: Tuple[int],
174176
segment: segment_command_64
175177
) -> None:
176178
# check if the segment is included in the mapping
@@ -230,7 +232,7 @@ def _rebasePage(self, pageOffset, delta) -> None:
230232

231233
def _getMappingSlidePairs(
232234
extractionCtx: ExtractionContext
233-
) -> list[tuple[Union[dyld_cache_mapping_info, dyld_cache_slide_info2]]]:
235+
) -> List[Tuple[Union[dyld_cache_mapping_info, dyld_cache_slide_info2]]]:
234236
dyldCtx = extractionCtx.dyldCtx
235237
logger = extractionCtx.logger
236238

src/DyldExtractor/converter/stub_fixer.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dataclasses
22
import enum
33
import struct
4-
from typing import Iterator
4+
from typing import Iterator, List, Tuple, Dict
55

66
from DyldExtractor.extraction_context import ExtractionContext
77
from DyldExtractor.file_context import FileContext
@@ -61,7 +61,7 @@ def __init__(self, extractionCtx: ExtractionContext) -> None:
6161
self._enumerateSymbols()
6262
pass
6363

64-
def symbolizeAddr(self, addr: int) -> list[bytes]:
64+
def symbolizeAddr(self, addr: int) -> List[bytes]:
6565
"""Get the name of a function at the address.
6666
6767
Args:
@@ -79,8 +79,8 @@ def symbolizeAddr(self, addr: int) -> list[bytes]:
7979
def _enumerateExports(self) -> None:
8080
# process the dependencies iteratively,
8181
# skipping ones already processed
82-
depsQueue: list[_DependencyInfo] = []
83-
depsProcessed: list[bytes] = []
82+
depsQueue: List[_DependencyInfo] = []
83+
depsProcessed: List[bytes] = []
8484

8585
# load commands for all dependencies
8686
DEP_LCS = (
@@ -179,7 +179,7 @@ def _getDepInfo(self, dylib: dylib_command) -> _DependencyInfo:
179179
def _readDepExports(
180180
self,
181181
depInfo: _DependencyInfo
182-
) -> list[dyld_trie.ExportInfo]:
182+
) -> List[dyld_trie.ExportInfo]:
183183
exportOff = None
184184
exportSize = None
185185

@@ -215,7 +215,7 @@ def _readDepExports(
215215
def _cacheDepExports(
216216
self,
217217
depInfo: _DependencyInfo,
218-
exports: list[dyld_trie.ExportInfo]
218+
exports: List[dyld_trie.ExportInfo]
219219
) -> None:
220220
for export in exports:
221221
if not export.address:
@@ -331,7 +331,7 @@ def getResolverTarget(address):
331331
)
332332

333333
# A cache of resolved stub chains
334-
self._resolveCache: dict[int, int] = {}
334+
self._resolveCache: Dict[int, int] = {}
335335
pass
336336

337337
def generateStubNormal(self, stubAddress: int, ldrAddress: int) -> bytes:
@@ -421,7 +421,7 @@ def resolveStubChain(self, address: int) -> int:
421421
self._resolveCache[address] = target
422422
return target
423423

424-
def resolveStub(self, address: int) -> tuple[int, _StubFormat]:
424+
def resolveStub(self, address: int) -> Tuple[int, _StubFormat]:
425425
"""Get the stub and its format.
426426
427427
Args:
@@ -464,7 +464,7 @@ def getStubHelperData(self, address: int) -> int:
464464

465465
return data
466466

467-
def getResolverData(self, address: int) -> tuple[int, int]:
467+
def getResolverData(self, address: int) -> Tuple[int, int]:
468468
"""Get the data of a resolver.
469469
470470
This is a stub helper that branches to a function
@@ -1015,17 +1015,17 @@ def run(self):
10151015
self._fixIndirectSymbols(symbolPtrs, stubMap)
10161016
pass
10171017

1018-
def _enumerateSymbolPointers(self) -> dict[bytes, tuple[int]]:
1018+
def _enumerateSymbolPointers(self) -> Dict[bytes, Tuple[int]]:
10191019
"""Generate a mapping between a pointer's symbol and its address.
10201020
"""
10211021

10221022
# read all the bind records as they're a source of symbolic info
1023-
bindRecords: dict[int, _BindRecord] = {}
1023+
bindRecords: Dict[int, _BindRecord] = {}
10241024
dyldInfo: dyld_info_command = self._machoCtx.getLoadCommand(
10251025
(LoadCommands.LC_DYLD_INFO, LoadCommands.LC_DYLD_INFO_ONLY)
10261026
)
10271027
if dyldInfo:
1028-
records: list[_BindRecord] = []
1028+
records: List[_BindRecord] = []
10291029
try:
10301030
if dyldInfo.weak_bind_size:
10311031
# usually contains records for c++ symbols like "new"
@@ -1067,7 +1067,7 @@ def _enumerateSymbolPointers(self) -> dict[bytes, tuple[int]]:
10671067
pass
10681068

10691069
# enumerate all symbol pointers
1070-
symbolPtrs: dict[bytes, list[int]] = {}
1070+
symbolPtrs: Dict[bytes, List[int]] = {}
10711071

10721072
def _addToMap(ptrSymbol: bytes, ptrAddr: int, section: section_64):
10731073
if ptrSymbol in symbolPtrs:
@@ -1210,12 +1210,12 @@ def _fixStubHelpers(self) -> None:
12101210

12111211
def _fixStubs(
12121212
self,
1213-
symbolPtrs: dict[bytes, tuple[int]]
1214-
) -> dict[bytes, tuple[int]]:
1213+
symbolPtrs: Dict[bytes, Tuple[int]]
1214+
) -> Dict[bytes, Tuple[int]]:
12151215
"""Relink stubs to their symbol pointers
12161216
"""
12171217

1218-
stubMap: dict[bytes, list[int]] = {}
1218+
stubMap: Dict[bytes, List[int]] = {}
12191219

12201220
def _addToMap(stubName: bytes, stubAddr: int):
12211221
if stubName in stubMap:
@@ -1360,7 +1360,7 @@ def _addToMap(stubName: bytes, stubAddr: int):
13601360

13611361
return stubMap
13621362

1363-
def _fixCallsites(self, stubMap: dict[bytes, tuple[int]]) -> None:
1363+
def _fixCallsites(self, stubMap: Dict[bytes, Tuple[int]]) -> None:
13641364
if (
13651365
b"__TEXT" not in self._machoCtx.segments
13661366
or b"__text" not in self._machoCtx.segments[b"__TEXT"].sects
@@ -1443,8 +1443,8 @@ def _fixCallsites(self, stubMap: dict[bytes, tuple[int]]) -> None:
14431443

14441444
def _fixIndirectSymbols(
14451445
self,
1446-
symbolPtrs: dict[bytes, tuple[int]],
1447-
stubMap: dict[bytes, tuple[int]]
1446+
symbolPtrs: Dict[bytes, Tuple[int]],
1447+
stubMap: Dict[bytes, Tuple[int]]
14481448
) -> None:
14491449
"""Fix indirect symbols.
14501450

src/DyldExtractor/dyld/dyld_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from mmap import mmap
2+
from typing import List
23

34
from DyldExtractor.file_context import FileContext
45
from DyldExtractor.dyld.dyld_structs import (
@@ -11,8 +12,8 @@
1112
class DyldContext(FileContext):
1213

1314
header: dyld_cache_header
14-
mappings: list[dyld_cache_mapping_info]
15-
images: list[dyld_cache_image_info]
15+
mappings: List[dyld_cache_mapping_info]
16+
images: List[dyld_cache_image_info]
1617

1718
def __init__(self, file: mmap) -> None:
1819
"""A wrapper around a dyld file.

src/DyldExtractor/dyld/dyld_trie.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
from DyldExtractor import leb128
66

7+
from typing import Tuple, List
8+
79
from DyldExtractor.macho.macho_constants import *
810

911

10-
def _readString(file: mmap, readHead: int) -> tuple[bytes, int]:
12+
def _readString(file: mmap, readHead: int) -> Tuple[bytes, int]:
1113
"""Read a null terminated string.
1214
1315
Returns:
@@ -55,7 +57,7 @@ class ExportReaderError(Exception):
5557

5658
class _ExportTrieReader(object):
5759

58-
exports: list[ExportInfo]
60+
exports: List[ExportInfo]
5961

6062
def __init__(
6163
self,
@@ -121,7 +123,7 @@ def ReadExports(
121123
file: mmap,
122124
exportOff: int,
123125
exportSize: int
124-
) -> list[ExportInfo]:
126+
) -> List[ExportInfo]:
125127
"""Read an export trie.
126128
127129
Args:

src/DyldExtractor/leb128.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from typing import Tuple
12

2-
3-
def decodeUleb128(buffer: bytes, readHead: int) -> tuple[int, int]:
3+
def decodeUleb128(buffer: bytes, readHead: int) -> Tuple[int, int]:
44
"""Read a Uleb128 value.
55
66
Args:
@@ -58,7 +58,7 @@ def encodeUleb128(value: int) -> bytes:
5858
return bytes(data)
5959

6060

61-
def decodeSleb128(buffer: bytes, readHead: int) -> tuple[int, int]:
61+
def decodeSleb128(buffer: bytes, readHead: int) -> Tuple[int, int]:
6262
"""Read a 64bit Sleb128 value.
6363
6464
Args:

src/DyldExtractor/macho/macho_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import struct
22
from mmap import mmap
33

4-
from typing import Union
4+
from typing import Union, List, Dict, Tuple
55

66
from DyldExtractor.file_context import FileContext
77

@@ -18,10 +18,10 @@
1818

1919
class MachOContext(FileContext):
2020

21-
loadCommands: list[load_command]
21+
loadCommands: List[load_command]
2222

23-
segments: dict[bytes, SegmentContext]
24-
segmentsI: list[SegmentContext]
23+
segments: Dict[bytes, SegmentContext]
24+
segmentsI: List[SegmentContext]
2525

2626
def __init__(
2727
self,
@@ -51,9 +51,9 @@ def __init__(
5151

5252
def getLoadCommand(
5353
self,
54-
cmdFilter: tuple[LoadCommands],
54+
cmdFilter: Tuple[LoadCommands],
5555
multiple: bool = False
56-
) -> Union[load_command, tuple[load_command]]:
56+
) -> Union[load_command, Tuple[load_command]]:
5757
"""Retreive a load command with its command ID
5858
5959
Args:

0 commit comments

Comments
 (0)