// Read 8 bytes from given native address QWord DOS4GWBinaryFile::readNative8(ADDRESS nat) { int raw[2]; #ifdef WORDS_BIGENDIAN // This tests the host machine // Source and host are different endianness raw[1] = readNative4(nat); raw[0] = readNative4(nat+4); #else // Source and host are same endianness raw[0] = readNative4(nat); raw[1] = readNative4(nat+4); #endif return *(QWord*)raw; }
// Read 8 bytes as a float double DOS4GWBinaryFile::readNativeFloat8(ADDRESS nat) { int raw[2]; #ifdef WORDS_BIGENDIAN // This tests the host machine // Source and host are different endianness raw[1] = readNative4(nat); raw[0] = readNative4(nat+4); #else // Source and host are same endianness raw[0] = readNative4(nat); raw[1] = readNative4(nat+4); #endif //return reinterpret_cast<double>(*raw); // Note: cast, not convert!! return *(double*)raw; }
// Read 4 bytes as a float float MachOBinaryFile::readNativeFloat4(ADDRESS nat) { int raw = readNative4(nat); // Ugh! gcc says that reinterpreting from int to float is invalid!! //return reinterpret_cast<float>(raw); // Note: cast, not convert!! return *(float*)&raw; // Note: cast, not convert }
bool BinaryImage::readNativeFloat4(Address addr, float &value) const { const BinarySection *sect = getSectionByAddr(addr); if (sect == nullptr || sect->getHostAddr() == HostAddress::INVALID) { LOG_WARN("Invalid read at address %1: Address is not mapped to a section", addr.toString()); return false; } else if (addr + 4 > sect->getSourceAddr() + sect->getSize()) { LOG_WARN("Invalid read at address %1: Read extends past section boundary", addr); return false; } DWord raw = readNative4(addr); value = *reinterpret_cast<float *>(&raw); // Note: cast, not convert return true; }