PROJECT+GUI: replaced float128 with ldconvert (closes issue #1241)
This commit is contained in:
parent
4c1fd6ca09
commit
82cff792cb
|
@ -47,6 +47,7 @@ copy bin\x32\asmjit.dll %RELEASEDIR%\bin_base\x32\
|
|||
copy bin\x32\yara.dll %RELEASEDIR%\bin_base\x32\
|
||||
copy bin\x32\snowman.dll %RELEASEDIR%\bin_base\x32\
|
||||
copy bin\x32\keystone.dll %RELEASEDIR%\bin_base\x32\
|
||||
copy bin\x32\ldconvert.dll %RELEASEDIR%\bin_base\x32\
|
||||
copy bin\x64\x64_bridge.dll %RELEASEDIR%\bin_base\x64\
|
||||
copy bin\x64\x64_dbg.dll %RELEASEDIR%\bin_base\x64\
|
||||
copy bin\x64\capstone.dll %RELEASEDIR%\bin_base\x64\
|
||||
|
@ -62,6 +63,7 @@ copy bin\x64\asmjit.dll %RELEASEDIR%\bin_base\x64\
|
|||
copy bin\x64\yara.dll %RELEASEDIR%\bin_base\x64\
|
||||
copy bin\x64\snowman.dll %RELEASEDIR%\bin_base\x64\
|
||||
copy bin\x64\keystone.dll %RELEASEDIR%\bin_base\x64\
|
||||
copy bin\x64\ldconvert.dll %RELEASEDIR%\bin_base\x64\
|
||||
|
||||
echo help
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
//Converts a long double to string.
|
||||
//This function uses sprintf with the highest supported precision.
|
||||
//pld: Pointer to an 80-bit (10 byte) long double.
|
||||
//str: Buffer with at least 32 bytes of space.
|
||||
extern "C" __declspec(dllimport) void ld2str(const void* pld, char* str);
|
||||
|
||||
//Converts a string to a long double.
|
||||
//This function uses http://en.cppreference.com/w/c/string/byte/strtof
|
||||
//str: The string to convert.
|
||||
//pld: Pointer to an 80-bit (10 byte) long double.
|
||||
extern "C" __declspec(dllimport) bool str2ld(const char* str, void* pld);
|
||||
|
||||
//Converts a long double to a double.
|
||||
//pld: Pointer to an 80-bit (10 byte) long double.
|
||||
//pd: Pointer to a 64-bit (8 byte) double.
|
||||
extern "C" __declspec(dllexport) void ld2d(const void* pld, void* pd);
|
||||
|
||||
//Converts a double to a long double.
|
||||
//pd: Pointer to a 64-bit (8 byte) double.
|
||||
//pld: Pointer to an 80-bit (10 byte) long double.
|
||||
extern "C" __declspec(dllexport) void d2ld(const void* pd, void* pld);
|
Binary file not shown.
Binary file not shown.
|
@ -1,173 +1,15 @@
|
|||
#include <stdint.h>
|
||||
#include "main.h"
|
||||
#include "StringUtil.h"
|
||||
#include "float128.h"
|
||||
#include "MiscUtil.h"
|
||||
#include "ldconvert.h"
|
||||
|
||||
dd_real pow2_fast(int exponent, int* exp10)
|
||||
{
|
||||
// Significantly more precise than using std::XXX math functions
|
||||
const static dd_real dd_loge10 = dd_real("2.30258509299404568401799145468436420760110148862");
|
||||
const static dd_real dd_loge2 = dd_real("0.69314718055994530941723212145817656807550013436");
|
||||
const static dd_real dd_sqrt10 = dd_real("3.16227766016837933199889354443271853371955513932");
|
||||
|
||||
// http://stackoverflow.com/questions/635183/fast-exponentiation-when-only-first-k-digits-are-required
|
||||
dd_real integerPart;
|
||||
dd_real identityCalc = std::abs(exponent) * (dd_loge2 / dd_loge10);
|
||||
dd_real identityFrac = std::modf(identityCalc, &integerPart);
|
||||
|
||||
dd_real fraction = std::exp((identityFrac - 0.5) * dd_loge10) * dd_sqrt10;
|
||||
|
||||
// Fraction is returned; calculate the power of 10 here
|
||||
if(exp10)
|
||||
*exp10 = std::floor(identityCalc).toInt();
|
||||
|
||||
// Check for a reciprocal
|
||||
if(exponent < 0)
|
||||
{
|
||||
// Use 10 to shift the exponent into 'exp10' only
|
||||
//
|
||||
// (1 / 2**3824) == 7.26e-1152 --> (10 / 2**3824) == 7.26e-1151
|
||||
fraction = dd_real(10) / fraction;
|
||||
|
||||
if(exp10)
|
||||
*exp10 = (-1 - *exp10);
|
||||
}
|
||||
|
||||
return fraction;
|
||||
}
|
||||
|
||||
QString ToLongDoubleString(void* buffer)
|
||||
{
|
||||
// Assumes that "buffer" is 10 bytes at the minimum
|
||||
//
|
||||
// 80-bit floating point precision
|
||||
// https://en.wikipedia.org/wiki/Extended_precision#IEEE_754_extended_precision_formats
|
||||
const uint16_t SIGNBIT = (1 << 15);
|
||||
const uint16_t EXP_BIAS = (1 << 14) - 1; // 2^(n-1) - 1 = 16383
|
||||
const uint64_t HIGHBIT = (uint64_t)1 << 63;
|
||||
const uint64_t QUIETBIT = (uint64_t)1 << 62;
|
||||
|
||||
// Don't swap endianness (data is represented in swapped endianness already)
|
||||
uint8_t bytes[10];
|
||||
|
||||
for(size_t k = 0; k < 10; k++)
|
||||
bytes[k] = ((uint8_t*)buffer)[k];
|
||||
|
||||
// Extract exponent and mantissa
|
||||
uint16_t exponent = *(uint16_t*)&bytes[8];
|
||||
uint64_t mantissa = *(uint64_t*)&bytes[0];
|
||||
|
||||
// Extract sign
|
||||
bool sign = (exponent & SIGNBIT) != 0;
|
||||
exponent &= ~SIGNBIT;
|
||||
|
||||
switch(exponent)
|
||||
{
|
||||
// If exponent zero
|
||||
case 0:
|
||||
{
|
||||
if((mantissa & HIGHBIT) == 0)
|
||||
{
|
||||
if((mantissa & QUIETBIT) == 0)
|
||||
return (sign) ? "-0.000000000000000000" : "0.000000000000000000";
|
||||
}
|
||||
|
||||
// Everything else psuedo denormal
|
||||
// (-1)^s * m * 2^-16382
|
||||
}
|
||||
break;
|
||||
|
||||
// If exponent all ones
|
||||
case 0x7FFF:
|
||||
{
|
||||
// if (bit 63 is zero)
|
||||
if((mantissa & HIGHBIT) == 0)
|
||||
{
|
||||
// if (bits 61-0 are zero) infinity;
|
||||
if((mantissa & (QUIETBIT - 1)) == 0)
|
||||
return (sign) ? "-INF" : "INF";
|
||||
|
||||
// else psuedo_nan;
|
||||
return "NAN";
|
||||
}
|
||||
|
||||
// Bit 63 is 1 at this point
|
||||
//
|
||||
// if (bit 62 is not set)
|
||||
if((mantissa & QUIETBIT) == 0)
|
||||
{
|
||||
// if (bits 61-0 are zero) infinity;
|
||||
if((mantissa & (QUIETBIT - 1)) == 0)
|
||||
return (sign) ? "-INF" : "INF";
|
||||
|
||||
// else signalling_nan;
|
||||
return "NAN";
|
||||
}
|
||||
|
||||
// else quiet_nan;
|
||||
return "NAN";
|
||||
}
|
||||
break;
|
||||
|
||||
// Default: exponent has maximum ranges
|
||||
default:
|
||||
{
|
||||
// e+4932
|
||||
//if((exponent - EXP_BIAS) > 4932)
|
||||
// return "INF";
|
||||
|
||||
// e-4931
|
||||
//if((exponent - EXP_BIAS) < -4931)
|
||||
// return "-INF";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert both numbers to 128 bit types
|
||||
dd_real dd_mantissa(mantissa);
|
||||
dd_real dd_divisor((uint64_t)1 << 63);
|
||||
|
||||
// Calculate significand (m) and exponent (e)
|
||||
//
|
||||
// (-1)^s * (m / 2^63) * 2^(e - 16383)
|
||||
dd_real significand = dd_mantissa / dd_divisor;
|
||||
|
||||
int exp10 = 0;
|
||||
dd_real exp = pow2_fast(exponent - EXP_BIAS, &exp10);
|
||||
|
||||
significand *= exp;
|
||||
|
||||
// The above multiplication can introduce an extra tens place, so remove it
|
||||
// (10.204) -> (1.0204) exp10++;
|
||||
if(std::floor(std::log10(significand)).toInt() > 0)
|
||||
{
|
||||
significand /= dd_real(10);
|
||||
exp10 += 1;
|
||||
}
|
||||
|
||||
// Signed-ness
|
||||
if(sign)
|
||||
significand *= -1;
|
||||
|
||||
// Print result (20 maximum digits)
|
||||
if(exp10 <= 10 && exp10 >= -4)
|
||||
{
|
||||
// -10000000000.0000000
|
||||
// 10000000000.00000000
|
||||
significand *= pown(10, exp10);
|
||||
|
||||
return QString::fromStdString(significand.to_string(18 - exp10 - (int)sign, 0, std::ios_base::fixed));
|
||||
}
|
||||
else
|
||||
{
|
||||
// -1.00000000000000000e+11
|
||||
// 1.000000000000000000e+11
|
||||
QString expStr = QString().sprintf("e%+d", exp10);
|
||||
QString sigStr = QString::fromStdString(significand.to_string(23 - expStr.length() - (int)sign, 0, std::ios_base::fixed));
|
||||
|
||||
return sigStr + expStr;
|
||||
}
|
||||
char str[32];
|
||||
ld2str(buffer, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
QString GetDataTypeString(void* buffer, duint size, ENCODETYPE type)
|
||||
|
|
|
@ -66,7 +66,7 @@ INCLUDEPATH += \
|
|||
Src/Global \
|
||||
Src/Utils \
|
||||
Src/ThirdPartyLibs/snowman \
|
||||
Src/ThirdPartyLibs/float128 \
|
||||
Src/ThirdPartyLibs/ldconvert \
|
||||
../capstone_wrapper
|
||||
|
||||
# Resources, sources, headers, and forms
|
||||
|
@ -147,7 +147,6 @@ SOURCES += \
|
|||
Src/Gui/NotepadView.cpp \
|
||||
Src/Gui/CPUMultiDump.cpp \
|
||||
Src/Gui/AssembleDialog.cpp \
|
||||
Src/ThirdPartyLibs/float128/float128.cpp \
|
||||
Src/Utils/StringUtil.cpp \
|
||||
Src/Gui/SEHChainView.cpp \
|
||||
Src/Gui/EditBreakpointDialog.cpp \
|
||||
|
@ -259,7 +258,6 @@ HEADERS += \
|
|||
Src/Utils/MenuBuilder.h \
|
||||
Src/Gui/CPUMultiDump.h \
|
||||
Src/Gui/AssembleDialog.h \
|
||||
Src/ThirdPartyLibs/float128/float128.h \
|
||||
Src/Gui/SEHChainView.h \
|
||||
Src/Gui/EditBreakpointDialog.h \
|
||||
Src/Gui/CPUArgumentWidget.h \
|
||||
|
@ -340,11 +338,13 @@ LIBS += -luser32 -ladvapi32 -lwinmm
|
|||
LIBS += -L"$$PWD/../capstone_wrapper/capstone" -lcapstone_x86
|
||||
LIBS += -L"$$PWD/../capstone_wrapper/bin/x32$${DIR_SUFFIX}" -lcapstone_wrapper
|
||||
LIBS += -L"$$PWD/Src/ThirdPartyLibs/snowman" -lsnowman_x86
|
||||
LIBS += -L"$$PWD/Src/ThirdPartyLibs/ldconvert" -lldconvert_x86
|
||||
LIBS += -L"$${X64_BIN_DIR}" -lx32bridge
|
||||
} else {
|
||||
# Windows x64 (64bit) specific build
|
||||
LIBS += -L"$$PWD/../capstone_wrapper/capstone" -lcapstone_x64
|
||||
LIBS += -L"$$PWD/../capstone_wrapper/bin/x64$${DIR_SUFFIX}" -lcapstone_wrapper
|
||||
LIBS += -L"$$PWD/Src/ThirdPartyLibs/snowman" -lsnowman_x64
|
||||
LIBS += -L"$$PWD/Src/ThirdPartyLibs/ldconvert" -lldconvert_x64
|
||||
LIBS += -L"$${X64_BIN_DIR}" -lx64bridge
|
||||
}
|
||||
|
|
|
@ -174,7 +174,6 @@ SOURCES += \
|
|||
gui/Src/BasicView/StdTable.cpp \
|
||||
gui/Src/Memory/MemoryPage.cpp \
|
||||
gui/Src/QEntropyView/QEntropyView.cpp \
|
||||
gui/Src/ThirdPartyLibs/float128/float128.cpp \
|
||||
dbg/analysis/advancedanalysis.cpp \
|
||||
dbg/analysis/analysis.cpp \
|
||||
dbg/analysis/analysis_nukem.cpp \
|
||||
|
@ -403,7 +402,6 @@ HEADERS += \
|
|||
gui/Src/Memory/MemoryPage.h \
|
||||
gui/Src/QEntropyView/Entropy.h \
|
||||
gui/Src/QEntropyView/QEntropyView.h \
|
||||
gui/Src/ThirdPartyLibs/float128/float128.h \
|
||||
gui/Src/ThirdPartyLibs/snowman/SnowmanView.h \
|
||||
dbg/analysis/advancedanalysis.h \
|
||||
dbg/analysis/analysis.h \
|
||||
|
|
Loading…
Reference in New Issue