Page cover

IEEE 745 - Formula Implementation

Converting hex values in IDA to their raw representations.

I do not ever expect any modern day reverse engineer to do anything on paper as far as using algorithms. The primary reason is going to be due to precision and time. Not all reverse engineers have a few minutes to write something down on paper just to get something wrong on the off-day. So, I decided to automate this conversion by building a converter in Python3 that is super easy to run.

This is for 4.0 and 0x40800000 (In development)

Python Implementation

class IEEE_754Converter:
    def __init__(self, hex_str):
        self.hex_int = int(hex_str, 16)
        self.sign = (self.hex_int >> 31) & 0x1
        self.exponent = (self.hex_int >> 23) & 0xFF
        self.significand = self.hex_int & 0x7FFFFF
        self.bias = 127  # this is worth changing in the future

    def RecoveryFunc_RestoreOgValueFromHex(self):
        if self.exponent == 0:
            exponent_v = 1 - self.bias  # handle cases for denormalized number(s)
            significand_v = self.significand / (2 ** 23)
        elif self.exponent == 0xFF:
            exponent_v = float('inf')  # we might have a unique case here
            significand_v = 0
        else:
            exponent_v = self.exponent - self.bias
            significand_v = 1 + self.significand / (2 ** 23)

        sign = (-1) ** self.sign
        return sign * significand_v * (2 ** exponent_v)

def main():
    while True:
        hn = input("Enter value> ")
        print("--------- Conversion ------ ")
        print("Original Value |> ", IEEE_754Converter(hn).RecoveryFunc_RestoreOgValueFromHex())

main()

Last updated