From 61c24ebcbbb84169e8af6e410ca247293322c9a4 Mon Sep 17 00:00:00 2001 From: Ange Albertini Date: Thu, 28 May 2026 13:09:53 +0000 Subject: [PATCH] RelativeVirtualAddress deprecation warning --- capa/features/address.py | 9 +++++++++ tests/test_engine.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/capa/features/address.py b/capa/features/address.py index ea152c87..1aacf226 100644 --- a/capa/features/address.py +++ b/capa/features/address.py @@ -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})" diff --git a/tests/test_engine.py b/tests/test_engine.py index 1d4ba1f2..c8f57b5e 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -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