diff --git a/src/abr.h b/src/abr.h index aee157d..fb1f603 100644 --- a/src/abr.h +++ b/src/abr.h @@ -40,12 +40,12 @@ public: uint16_t ru16() { return m_swap ? swap(read()) : read(); } uint32_t ru32() { return m_swap ? swap(read()) : read(); } uint64_t ru64() { return m_swap ? swap(read()) : read(); } - int8_t ri8() { return read(); } - int16_t ri16() { return m_swap ? swap(read()) : read(); } - int32_t ri32() { return m_swap ? swap(read()) : read(); } - int64_t ri64() { return m_swap ? swap(read()) : read(); } - float rflt() { return read(); } - double rdbl() { return read(); } + int8_t ri8() { return read(); } + int16_t ri16() { return m_swap ? swap(read()) : read(); } + int32_t ri32() { return m_swap ? swap(read()) : read(); } + int64_t ri64() { return m_swap ? swap(read()) : read(); } + float rflt() { return m_swap ? swap(read()) : read(); } + double rdbl() { return m_swap ? swap(read()) : read(); } std::string pick(size_t chars) { return { (char*)m_cur, chars }; } std::string rstring() { @@ -92,12 +92,22 @@ protected: template T swap(T x) { #if _MSC_VER >= 1400 + if (sizeof(T) == 2) - return _byteswap_ushort(x); + { + auto y = _byteswap_ushort(*reinterpret_cast(&x)); + return *reinterpret_cast(&y); + } else if (sizeof(T) == 4) - return _byteswap_ulong(x); + { + auto y = _byteswap_ulong(*reinterpret_cast(&x)); + return *reinterpret_cast(&y); + } else if (sizeof(T) == 8) - return _byteswap_uint64(x); + { + auto y = _byteswap_uint64(*reinterpret_cast(&x)); + return *reinterpret_cast(&y); + } #else auto p = reinterpret_cast(&x); if (sizeof(T) == 2) @@ -179,7 +189,10 @@ class ABR : public BinaryStream }; struct Enum : public Type { - + std::string type; + std::string value; + virtual std::string str(int indent, const std::string& prefix) const override + { return std::string(indent, '-') + prefix + fmt::format("enum {}: {}", type, value); } }; struct EnumRef : public Type { }; struct Offset : public Type { };