From c236293185b0ddf89bc7d2c554608b7c29f8f75f Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Fri, 8 Apr 2022 18:41:19 -0600 Subject: [PATCH] features: insn: number: allow floats, too --- capa/features/insn.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/capa/features/insn.py b/capa/features/insn.py index bb8924ee..37c09359 100644 --- a/capa/features/insn.py +++ b/capa/features/insn.py @@ -6,6 +6,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. import abc +from typing import Union import capa.render.utils from capa.features.common import Feature @@ -17,11 +18,16 @@ class API(Feature): class Number(Feature): - def __init__(self, value: int, description=None): + def __init__(self, value: Union[int, float], description=None): super(Number, self).__init__(value, description=description) def get_value_str(self): - return capa.render.utils.hex(self.value) + if isinstance(self.value, int): + return capa.render.utils.hex(self.value) + elif isinstance(self.value, float): + return str(self.value) + else: + raise ValueError("invalid value type") # max recognized structure size (and therefore, offset size)