|
3 | 3 | """
|
4 | 4 |
|
5 | 5 | from __future__ import annotations
|
6 |
| -from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Iterable, Iterator, Optional, Sequence, Tuple, Type, TypeVar, Union |
| 6 | +from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Iterable, Iterator, Optional, Sequence, Tuple, Type, TypeVar, Union, ParamSpec |
7 | 7 |
|
8 | 8 | import ctypes
|
9 | 9 | import functools
|
10 | 10 | import weakref
|
| 11 | +import warnings |
11 | 12 |
|
12 | 13 | from unicorn import unicorn_const as uc
|
13 | 14 | from .arch.types import uc_err, uc_engine, uc_context, uc_hook_h, UcReg, VT
|
@@ -631,6 +632,29 @@ class Uc(RegStateManager):
|
631 | 632 | """Unicorn Engine class.
|
632 | 633 | """
|
633 | 634 |
|
| 635 | + # Code snippet modified from: |
| 636 | + # https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically |
| 637 | + |
| 638 | + |
| 639 | + @staticmethod |
| 640 | + def __deprecated(msg: str): |
| 641 | + __rT = TypeVar('rT') # return type |
| 642 | + __pT = ParamSpec('pT') # parameters type |
| 643 | + def __deprecated_inner(func: Callable[__pT, __rT]) -> Callable[__pT, __rT]: |
| 644 | + """Use this decorator to mark functions as deprecated. |
| 645 | + Every time the decorated function runs, it will emit |
| 646 | + a "deprecation" warning.""" |
| 647 | + @functools.wraps(func) |
| 648 | + def new_func(*args: Uc.__pT.args, **kwargs: Uc.__pT.kwargs): |
| 649 | + warnings.simplefilter('always', DeprecationWarning) # turn off filter |
| 650 | + warnings.warn("Call to a deprecated function {}. {}".format(func.__name__, msg), |
| 651 | + category=DeprecationWarning, |
| 652 | + stacklevel=2) |
| 653 | + warnings.simplefilter('default', DeprecationWarning) # reset filter |
| 654 | + return func(*args, **kwargs) |
| 655 | + return new_func |
| 656 | + return __deprecated_inner |
| 657 | + |
634 | 658 | @staticmethod
|
635 | 659 | def __is_compliant() -> bool:
|
636 | 660 | """Checks whether Unicorn binding version complies with Unicorn library.
|
@@ -1435,6 +1459,15 @@ def ctl_flush_tb(self) -> None:
|
1435 | 1459 |
|
1436 | 1460 | self.__ctl_w(uc.UC_CTL_TB_FLUSH)
|
1437 | 1461 |
|
| 1462 | + @__deprecated("You should use ctl_set_tlb_mode instead.") |
| 1463 | + def ctl_tlb_mode(self, mode: int) -> None: |
| 1464 | + """Deprecated, please use ctl_set_tlb_mode instead. |
| 1465 | + |
| 1466 | + Args: |
| 1467 | + mode: tlb mode to use (see UC_TLB_* constants) |
| 1468 | + """ |
| 1469 | + self.ctl_set_tlb_mode(mode) |
| 1470 | + |
1438 | 1471 | def ctl_set_tlb_mode(self, mode: int) -> None:
|
1439 | 1472 | """Set TLB mode.
|
1440 | 1473 |
|
|
0 commit comments