From 9d1e2c80370be7da100f0c5afc0259d9af553a30 Mon Sep 17 00:00:00 2001 From: rihi <19492038+rihi@users.noreply.github.com> Date: Thu, 21 Sep 2023 13:28:29 +0200 Subject: [PATCH] Use normalize_int in cexpressiongenerator.py --- decompiler/backend/cexpressiongenerator.py | 24 ++-------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/decompiler/backend/cexpressiongenerator.py b/decompiler/backend/cexpressiongenerator.py index 09bcfac65..6ff59150a 100644 --- a/decompiler/backend/cexpressiongenerator.py +++ b/decompiler/backend/cexpressiongenerator.py @@ -1,5 +1,4 @@ import logging -from ctypes import c_byte, c_int, c_long, c_short, c_ubyte, c_uint, c_ulong, c_ushort from itertools import chain, repeat from decompiler.structures import pseudo as expressions @@ -8,6 +7,7 @@ from decompiler.structures.pseudo import operations as operations from decompiler.structures.pseudo.operations import MemberAccess from decompiler.structures.visitors.interfaces import DataflowObjectVisitorInterface +from decompiler.util.integer_util import normalize_int class CExpressionGenerator(DataflowObjectVisitorInterface): @@ -80,20 +80,6 @@ class CExpressionGenerator(DataflowObjectVisitorInterface): # OperationType.adc: "adc", } - SIGNED_FORMATS = { - 8: lambda x: c_byte(x).value, - 16: lambda x: c_short(x).value, - 32: lambda x: c_int(x).value, - 64: lambda x: c_long(x).value, - } - - UNSIGNED_FORMATS = { - 8: lambda x: c_ubyte(x).value, - 16: lambda x: c_ushort(x).value, - 32: lambda x: c_uint(x).value, - 64: lambda x: c_ulong(x).value, - } - """ Precedence used for correctly generating brackets. Higher precedence is more tightly binding. @@ -298,13 +284,7 @@ def _get_integer_literal_value(self, literal: expressions.Constant) -> int: Return the right integer value for the given type, assuming that the re-compilation host has the same sizes as the decompilation host. """ - if literal.type.is_signed: - if handler := self.SIGNED_FORMATS.get(literal.type.size, None): - return handler(literal.value) - elif literal.value < 0: - if handler := self.UNSIGNED_FORMATS.get(literal.type.size, None): - return handler(literal.value) - return literal.value + return normalize_int(literal.value, literal.type.size, literal.type.is_signed) @staticmethod def _interpret_integer_literal_type(value: int) -> Integer: