mirror of
https://github.com/mandiant/capa.git
synced 2026-06-12 11:01:31 -07:00
RelativeVirtualAddress deprecation warning
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import abc
|
||||
import warnings
|
||||
|
||||
|
||||
class Address(abc.ABC):
|
||||
@@ -131,6 +132,14 @@ class DynamicCallAddress(Address):
|
||||
class RelativeVirtualAddress(int, Address):
|
||||
"""a memory address relative to a base address"""
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"RelativeVirtualAddress is deprecated",
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return super().__new__(cls, *args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return f"relative(0x{self:x})"
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
import capa.features.address
|
||||
@@ -23,6 +25,7 @@ from capa.features.address import (
|
||||
DynamicCallAddress,
|
||||
DNTokenOffsetAddress,
|
||||
AbsoluteVirtualAddress,
|
||||
RelativeVirtualAddress,
|
||||
)
|
||||
|
||||
ADDR1 = capa.features.address.AbsoluteVirtualAddress(0x401001)
|
||||
@@ -55,6 +58,13 @@ def test_no_address_hash():
|
||||
assert d[addr_zero] == "zero"
|
||||
|
||||
|
||||
def test_relative_address():
|
||||
with pytest.raises(DeprecationWarning):
|
||||
warnings.filterwarnings("error", category=DeprecationWarning)
|
||||
_ = RelativeVirtualAddress(0)
|
||||
warnings.resetwarnings()
|
||||
|
||||
|
||||
def test_dn_token_offset_address_cross_type_eq():
|
||||
addr = DNTokenOffsetAddress(0x1000, 0x10)
|
||||
assert (addr == AbsoluteVirtualAddress(0x1010)) is False
|
||||
|
||||
Reference in New Issue
Block a user