Skip to content

Commit ab06b4b

Browse files
committed
Improving typing annotations
1 parent 0d37928 commit ab06b4b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

qiling/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
filter = None,
4646
stop: QL_STOP = QL_STOP.NONE,
4747
*,
48-
endian: QL_ENDIAN = None,
48+
endian: Optional[QL_ENDIAN] = None,
4949
thumb: bool = False,
5050
libcache: bool = False
5151
):
@@ -414,8 +414,8 @@ def debug_stop(self) -> bool:
414414
return self._debug_stop
415415

416416
@debug_stop.setter
417-
def debug_stop(self, ds):
418-
self._debug_stop = ds
417+
def debug_stop(self, enabled: bool):
418+
self._debug_stop = enabled
419419

420420
@property
421421
def debugger(self) -> bool:

qiling/os/memory.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def del_mapinfo(self, mem_s: int, mem_e: int):
127127

128128
self.map_info = tmp_map_info
129129

130-
def change_mapinfo(self, mem_s: int, mem_e: int, mem_p: int = None, mem_info: str = None):
131-
tmp_map_info: MapInfoEntry = None
130+
def change_mapinfo(self, mem_s: int, mem_e: int, mem_p: Optional[int] = None, mem_info: Optional[str] = None):
131+
tmp_map_info: Optional[MapInfoEntry] = None
132132
info_idx: int = None
133133

134134
for idx, map_info in enumerate(self.map_info):
@@ -215,7 +215,7 @@ def get_lib_base(self, filename: str) -> Optional[int]:
215215

216216
return next((lbound for lbound, info in stripped if os.path.basename(info) == filename), None)
217217

218-
def align(self, value: int, alignment: int = None) -> int:
218+
def align(self, value: int, alignment: Optional[int] = None) -> int:
219219
"""Align a value down to the specified alignment boundary. If `value` is already
220220
aligned, the same value is returned. Commonly used to determine the base address
221221
of the enclosing page.
@@ -237,7 +237,7 @@ def align(self, value: int, alignment: int = None) -> int:
237237
# round down to nearest alignment
238238
return value & ~(alignment - 1)
239239

240-
def align_up(self, value: int, alignment: int = None) -> int:
240+
def align_up(self, value: int, alignment: Optional[int] = None) -> int:
241241
"""Align a value up to the specified alignment boundary. If `value` is already
242242
aligned, the same value is returned. Commonly used to determine the end address
243243
of the enlosing page.
@@ -310,13 +310,13 @@ def read(self, addr: int, size: int) -> bytearray:
310310

311311
return self.ql.uc.mem_read(addr, size)
312312

313-
def read_ptr(self, addr: int, size: int=None) -> int:
313+
def read_ptr(self, addr: int, size: int = 0) -> int:
314314
"""Read an integer value from a memory address.
315315
Bytes read will be unpacked using emulated architecture properties.
316316
317317
Args:
318318
addr: memory address to read
319-
size: pointer size (in bytes): either 1, 2, 4, 8, or None for arch native size
319+
size: pointer size (in bytes): either 1, 2, 4, 8, or 0 for arch native size
320320
321321
Returns: integer value stored at the specified memory address
322322
"""
@@ -346,14 +346,14 @@ def write(self, addr: int, data: bytes) -> None:
346346

347347
self.ql.uc.mem_write(addr, data)
348348

349-
def write_ptr(self, addr: int, value: int, size: int=None) -> None:
349+
def write_ptr(self, addr: int, value: int, size: int = 0) -> None:
350350
"""Write an integer value to a memory address.
351351
Bytes written will be packed using emulated architecture properties.
352352
353353
Args:
354354
addr: target memory address
355355
value: integer value to write
356-
size: pointer size (in bytes): either 1, 2, 4, 8, or None for arch native size
356+
size: pointer size (in bytes): either 1, 2, 4, 8, or 0 for arch native size
357357
"""
358358

359359
if not size:
@@ -371,7 +371,7 @@ def write_ptr(self, addr: int, value: int, size: int=None) -> None:
371371

372372
self.write(addr, __pack(value))
373373

374-
def search(self, needle: Union[bytes, Pattern[bytes]], begin: int = None, end: int = None) -> Sequence[int]:
374+
def search(self, needle: Union[bytes, Pattern[bytes]], begin: Optional[int] = None, end: Optional[int] = None) -> Sequence[int]:
375375
"""Search for a sequence of bytes in memory.
376376
377377
Args:
@@ -422,7 +422,7 @@ def unmap(self, addr: int, size: int) -> None:
422422
if (addr, addr + size) in self.mmio_cbs:
423423
del self.mmio_cbs[(addr, addr+size)]
424424

425-
def unmap_all(self):
425+
def unmap_all(self) -> None:
426426
"""Reclaim the entire memory space.
427427
"""
428428

@@ -483,7 +483,7 @@ def is_mapped(self, addr: int, size: int) -> bool:
483483

484484
return any((lbound <= begin < end <= ubound) for lbound, ubound in self.__mapped_regions())
485485

486-
def find_free_space(self, size: int, minaddr: int = None, maxaddr: int = None, align: int = None) -> int:
486+
def find_free_space(self, size: int, minaddr: Optional[int] = None, maxaddr: Optional[int] = None, align: Optional[int] = None) -> int:
487487
"""Locate an unallocated memory that is large enough to contain a range in size of
488488
`size` and based at `minaddr`.
489489
@@ -528,7 +528,7 @@ def find_free_space(self, size: int, minaddr: int = None, maxaddr: int = None, a
528528

529529
raise QlOutOfMemory('Out Of Memory')
530530

531-
def map_anywhere(self, size: int, minaddr: int = None, maxaddr: int = None, align: int = None, perms: int = UC_PROT_ALL, info: str = None) -> int:
531+
def map_anywhere(self, size: int, minaddr: Optional[int] = None, maxaddr: Optional[int] = None, align: Optional[int] = None, perms: int = UC_PROT_ALL, info: Optional[str] = None) -> int:
532532
"""Map a region anywhere in memory.
533533
534534
Args:
@@ -563,7 +563,7 @@ def protect(self, addr: int, size: int, perms):
563563
self.change_mapinfo(aligned_address, aligned_address + aligned_size, mem_p = perms)
564564

565565

566-
def map(self, addr: int, size: int, perms: int = UC_PROT_ALL, info: str = None):
566+
def map(self, addr: int, size: int, perms: int = UC_PROT_ALL, info: Optional[str] = None):
567567
"""Map a new memory range.
568568
569569
Args:
@@ -742,7 +742,7 @@ def clear(self):
742742
self.current_alloc = 0
743743
self.current_use = 0
744744

745-
def _find(self, addr: int, inuse: bool = None) -> Optional[Chunk]:
745+
def _find(self, addr: int, inuse: Optional[bool] = None) -> Optional[Chunk]:
746746
"""Find a chunk starting at a specified address.
747747
748748
Args:

0 commit comments

Comments
 (0)