fix: 修复结构体分析器等小问题;

This commit is contained in:
寂静的羽夏 2025-02-13 21:29:02 +08:00
parent a5a796861c
commit 293cc69a24
10 changed files with 180 additions and 73 deletions

View File

@ -224,17 +224,17 @@
<message>
<location filename="../../src/dialog/crashreport.ui" line="14"/>
<source>CrashReport</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/crashreport.ui" line="65"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:700;&quot;&gt;Opps! The software has crashed! Please send the information below to the dev:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:700;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
<location filename="../../src/dialog/crashreport.cpp" line="36"/>
<source>CopyToClipBoard</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>
@ -5366,12 +5366,12 @@ Do you wish to keep up to date by reloading the file?</source>
</message>
<message>
<location filename="../../src/class/wingangelapi.cpp" line="1989"/>
<location filename="../../src/class/wingangelapi.cpp" line="2069"/>
<location filename="../../src/class/wingangelapi.cpp" line="2074"/>
<source>Get Exception While ScriptCall: (%1) %2</source>
<translation>%1%2</translation>
</message>
<message>
<location filename="../../src/class/wingangelapi.cpp" line="2010"/>
<location filename="../../src/class/wingangelapi.cpp" line="2015"/>
<source>InvalidRetType: need </source>
<translation> </translation>
</message>
@ -5379,44 +5379,49 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>WingCStruct</name>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="226"/>
<location filename="../../src/class/wingcstruct.cpp" line="260"/>
<source>WingCStruct</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="229"/>
<location filename="../../src/class/wingcstruct.cpp" line="263"/>
<source>Providing basic support for analyzing file structures</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="847"/>
<location filename="../../src/class/wingcstruct.cpp" line="859"/>
<location filename="../../src/class/wingcstruct.cpp" line="872"/>
<location filename="../../src/class/wingcstruct.cpp" line="881"/>
<location filename="../../src/class/wingcstruct.cpp" line="893"/>
<location filename="../../src/class/wingcstruct.cpp" line="901"/>
<location filename="../../src/class/wingcstruct.cpp" line="908"/>
<location filename="../../src/class/wingcstruct.cpp" line="920"/>
<location filename="../../src/class/wingcstruct.cpp" line="932"/>
<location filename="../../src/class/wingcstruct.cpp" line="957"/>
<location filename="../../src/class/wingcstruct.cpp" line="977"/>
<location filename="../../src/class/wingcstruct.cpp" line="997"/>
<location filename="../../src/class/wingcstruct.cpp" line="1018"/>
<location filename="../../src/class/wingcstruct.cpp" line="1030"/>
<location filename="../../src/class/wingcstruct.cpp" line="891"/>
<location filename="../../src/class/wingcstruct.cpp" line="903"/>
<location filename="../../src/class/wingcstruct.cpp" line="916"/>
<location filename="../../src/class/wingcstruct.cpp" line="925"/>
<location filename="../../src/class/wingcstruct.cpp" line="937"/>
<location filename="../../src/class/wingcstruct.cpp" line="945"/>
<location filename="../../src/class/wingcstruct.cpp" line="952"/>
<location filename="../../src/class/wingcstruct.cpp" line="964"/>
<location filename="../../src/class/wingcstruct.cpp" line="976"/>
<location filename="../../src/class/wingcstruct.cpp" line="983"/>
<location filename="../../src/class/wingcstruct.cpp" line="995"/>
<location filename="../../src/class/wingcstruct.cpp" line="1007"/>
<location filename="../../src/class/wingcstruct.cpp" line="1032"/>
<location filename="../../src/class/wingcstruct.cpp" line="1052"/>
<location filename="../../src/class/wingcstruct.cpp" line="1072"/>
<location filename="../../src/class/wingcstruct.cpp" line="1093"/>
<location filename="../../src/class/wingcstruct.cpp" line="1105"/>
<source>InvalidParamsCount</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="851"/>
<location filename="../../src/class/wingcstruct.cpp" line="863"/>
<location filename="../../src/class/wingcstruct.cpp" line="885"/>
<location filename="../../src/class/wingcstruct.cpp" line="912"/>
<location filename="../../src/class/wingcstruct.cpp" line="924"/>
<location filename="../../src/class/wingcstruct.cpp" line="944"/>
<location filename="../../src/class/wingcstruct.cpp" line="966"/>
<location filename="../../src/class/wingcstruct.cpp" line="986"/>
<location filename="../../src/class/wingcstruct.cpp" line="1006"/>
<location filename="../../src/class/wingcstruct.cpp" line="1036"/>
<location filename="../../src/class/wingcstruct.cpp" line="895"/>
<location filename="../../src/class/wingcstruct.cpp" line="907"/>
<location filename="../../src/class/wingcstruct.cpp" line="929"/>
<location filename="../../src/class/wingcstruct.cpp" line="956"/>
<location filename="../../src/class/wingcstruct.cpp" line="968"/>
<location filename="../../src/class/wingcstruct.cpp" line="987"/>
<location filename="../../src/class/wingcstruct.cpp" line="999"/>
<location filename="../../src/class/wingcstruct.cpp" line="1019"/>
<location filename="../../src/class/wingcstruct.cpp" line="1041"/>
<location filename="../../src/class/wingcstruct.cpp" line="1061"/>
<location filename="../../src/class/wingcstruct.cpp" line="1081"/>
<location filename="../../src/class/wingcstruct.cpp" line="1111"/>
<source>InvalidParam</source>
<translation></translation>
</message>

View File

@ -224,17 +224,17 @@
<message>
<location filename="../../src/dialog/crashreport.ui" line="14"/>
<source>CrashReport</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../src/dialog/crashreport.ui" line="65"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:700;&quot;&gt;Opps! The software has crashed! Please send the information below to the dev:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:700;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
<location filename="../../src/dialog/crashreport.cpp" line="36"/>
<source>CopyToClipBoard</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>
@ -5366,12 +5366,12 @@ Do you wish to keep up to date by reloading the file?</source>
</message>
<message>
<location filename="../../src/class/wingangelapi.cpp" line="1989"/>
<location filename="../../src/class/wingangelapi.cpp" line="2069"/>
<location filename="../../src/class/wingangelapi.cpp" line="2074"/>
<source>Get Exception While ScriptCall: (%1) %2</source>
<translation>調%1%2</translation>
</message>
<message>
<location filename="../../src/class/wingangelapi.cpp" line="2010"/>
<location filename="../../src/class/wingangelapi.cpp" line="2015"/>
<source>InvalidRetType: need </source>
<translation> </translation>
</message>
@ -5379,44 +5379,49 @@ Do you wish to keep up to date by reloading the file?</source>
<context>
<name>WingCStruct</name>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="226"/>
<location filename="../../src/class/wingcstruct.cpp" line="260"/>
<source>WingCStruct</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="229"/>
<location filename="../../src/class/wingcstruct.cpp" line="263"/>
<source>Providing basic support for analyzing file structures</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="847"/>
<location filename="../../src/class/wingcstruct.cpp" line="859"/>
<location filename="../../src/class/wingcstruct.cpp" line="872"/>
<location filename="../../src/class/wingcstruct.cpp" line="881"/>
<location filename="../../src/class/wingcstruct.cpp" line="893"/>
<location filename="../../src/class/wingcstruct.cpp" line="901"/>
<location filename="../../src/class/wingcstruct.cpp" line="908"/>
<location filename="../../src/class/wingcstruct.cpp" line="920"/>
<location filename="../../src/class/wingcstruct.cpp" line="932"/>
<location filename="../../src/class/wingcstruct.cpp" line="957"/>
<location filename="../../src/class/wingcstruct.cpp" line="977"/>
<location filename="../../src/class/wingcstruct.cpp" line="997"/>
<location filename="../../src/class/wingcstruct.cpp" line="1018"/>
<location filename="../../src/class/wingcstruct.cpp" line="1030"/>
<location filename="../../src/class/wingcstruct.cpp" line="891"/>
<location filename="../../src/class/wingcstruct.cpp" line="903"/>
<location filename="../../src/class/wingcstruct.cpp" line="916"/>
<location filename="../../src/class/wingcstruct.cpp" line="925"/>
<location filename="../../src/class/wingcstruct.cpp" line="937"/>
<location filename="../../src/class/wingcstruct.cpp" line="945"/>
<location filename="../../src/class/wingcstruct.cpp" line="952"/>
<location filename="../../src/class/wingcstruct.cpp" line="964"/>
<location filename="../../src/class/wingcstruct.cpp" line="976"/>
<location filename="../../src/class/wingcstruct.cpp" line="983"/>
<location filename="../../src/class/wingcstruct.cpp" line="995"/>
<location filename="../../src/class/wingcstruct.cpp" line="1007"/>
<location filename="../../src/class/wingcstruct.cpp" line="1032"/>
<location filename="../../src/class/wingcstruct.cpp" line="1052"/>
<location filename="../../src/class/wingcstruct.cpp" line="1072"/>
<location filename="../../src/class/wingcstruct.cpp" line="1093"/>
<location filename="../../src/class/wingcstruct.cpp" line="1105"/>
<source>InvalidParamsCount</source>
<translation></translation>
</message>
<message>
<location filename="../../src/class/wingcstruct.cpp" line="851"/>
<location filename="../../src/class/wingcstruct.cpp" line="863"/>
<location filename="../../src/class/wingcstruct.cpp" line="885"/>
<location filename="../../src/class/wingcstruct.cpp" line="912"/>
<location filename="../../src/class/wingcstruct.cpp" line="924"/>
<location filename="../../src/class/wingcstruct.cpp" line="944"/>
<location filename="../../src/class/wingcstruct.cpp" line="966"/>
<location filename="../../src/class/wingcstruct.cpp" line="986"/>
<location filename="../../src/class/wingcstruct.cpp" line="1006"/>
<location filename="../../src/class/wingcstruct.cpp" line="1036"/>
<location filename="../../src/class/wingcstruct.cpp" line="895"/>
<location filename="../../src/class/wingcstruct.cpp" line="907"/>
<location filename="../../src/class/wingcstruct.cpp" line="929"/>
<location filename="../../src/class/wingcstruct.cpp" line="956"/>
<location filename="../../src/class/wingcstruct.cpp" line="968"/>
<location filename="../../src/class/wingcstruct.cpp" line="987"/>
<location filename="../../src/class/wingcstruct.cpp" line="999"/>
<location filename="../../src/class/wingcstruct.cpp" line="1019"/>
<location filename="../../src/class/wingcstruct.cpp" line="1041"/>
<location filename="../../src/class/wingcstruct.cpp" line="1061"/>
<location filename="../../src/class/wingcstruct.cpp" line="1081"/>
<location filename="../../src/class/wingcstruct.cpp" line="1111"/>
<source>InvalidParam</source>
<translation></translation>
</message>

View File

@ -9,6 +9,8 @@
#include <cpptrace/cpptrace.hpp>
#include <csignal>
#ifdef Q_OS_WIN
#include <Windows.h>
@ -21,14 +23,11 @@ LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS *) {
}
#else
#include <csignal>
#include <execinfo.h>
#include <unistd.h>
#endif
void signalHandler(int) { CrashHandler::reportCrashAndExit(); }
#endif
CrashHandler &CrashHandler::instance() {
static CrashHandler ins;
return ins;
@ -37,6 +36,11 @@ CrashHandler &CrashHandler::instance() {
void CrashHandler::init() {
#ifdef Q_OS_WIN
::SetUnhandledExceptionFilter(ExceptionFilter);
std::signal(SIGABRT, signalHandler);
std::signal(SIGSEGV, signalHandler);
std::signal(SIGILL, signalHandler);
std::signal(SIGABRT, signalHandler);
std::signal(SIGFPE, signalHandler);
#else
::signal(SIGSEGV, signalHandler);
::signal(SIGILL, signalHandler);
@ -126,8 +130,10 @@ void CrashHandler::reportCrashAndExit() {
r.setInfomation(buffer);
r.exec();
#ifdef Q_OS_LINUX
// because abort() will also trigger it
#ifdef Q_OS_WIN
std::signal(SIGABRT, nullptr);
#else
::signal(SIGABRT, nullptr);
#endif

View File

@ -643,7 +643,7 @@ bool CTypeParser::isNumericToken(const QString &token, long &number) const {
}
bool ret = true;
number = token.toLong(&ret);
number = token.toInt(&ret, 0);
if (!ret) {
// the token is not a number, then check whether it can be translated
@ -698,7 +698,7 @@ CTypeParser::unionDefs() const {
return union_defs_;
}
const QHash<QString, long> &CTypeParser::constDefs() const {
const QHash<QString, int> &CTypeParser::constDefs() const {
return const_defs_;
}

View File

@ -121,7 +121,7 @@ public:
QPair<QMetaType::Type, qsizetype> type(const QString &t) const;
const QHash<QString, long> &constDefs() const;
const QHash<QString, int> &constDefs() const;
const QHash<QString, QList<VariableDeclaration>> &unionDefs() const;
@ -230,7 +230,7 @@ private:
/// key - constant/macro name
/// value - an integer (all types of number are cast to long type for
/// convenience)
QHash<QString, long> const_defs_;
QHash<QString, int> const_defs_;
};
#endif // _TYPE_PARSER_H_

View File

@ -1995,6 +1995,11 @@ void WingAngelAPI::script_call(asIScriptGeneric *gen) {
auto rettype = fns.ret;
auto r = PluginSystem::type2AngelScriptString(rettype, false, true);
if (r == QStringLiteral("int")) {
r = QStringLiteral("int32");
} else if (r == QStringLiteral("uint")) {
r = QStringLiteral("uint32");
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto type =

View File

@ -120,6 +120,38 @@ WingCStruct::WingCStruct() : WingHex::IWingPlugin() {
_scriptInfo.insert(QStringLiteral("existStruct"), info);
}
{
WingHex::IWingPlugin::ScriptFnInfo info;
info.fn = std::bind(
QOverload<const QVariantList &>::of(&WingCStruct::constDefines),
this, std::placeholders::_1);
info.ret = MetaType(MetaType::String | MetaType::Array);
_scriptInfo.insert(QStringLiteral("constDefines"), info);
}
{
WingHex::IWingPlugin::ScriptFnInfo info;
info.fn = std::bind(
QOverload<const QVariantList &>::of(&WingCStruct::existDefineValue),
this, std::placeholders::_1);
info.ret = MetaType::Bool;
info.params.append(qMakePair(MetaType::String, QStringLiteral("type")));
_scriptInfo.insert(QStringLiteral("existDefineValue"), info);
}
{
WingHex::IWingPlugin::ScriptFnInfo info;
info.fn = std::bind(
QOverload<const QVariantList &>::of(&WingCStruct::defineValue),
this, std::placeholders::_1);
info.ret = MetaType::Int;
info.params.append(qMakePair(MetaType::String, QStringLiteral("type")));
_scriptInfo.insert(QStringLiteral("defineValue"), info);
}
{
WingHex::IWingPlugin::ScriptFnInfo info;
info.fn = std::bind(
@ -215,12 +247,14 @@ int WingCStruct::sdkVersion() const { return WingHex::SDKVERSION; }
const QString WingCStruct::signature() const { return WingHex::WINGSUMMER; }
bool WingCStruct::init(const std::unique_ptr<QSettings> &set) {
Q_UNUSED(set);
resetEnv();
return true;
}
void WingCStruct::unload(std::unique_ptr<QSettings> &set) {
// nothing
Q_UNUSED(set);
}
const QString WingCStruct::pluginName() const { return tr("WingCStruct"); }
@ -353,6 +387,16 @@ bool WingCStruct::existStruct(const QString &type) {
return _parser.structDefs().contains(type);
}
QStringList WingCStruct::constDefines() { return _parser.constDefs().keys(); }
bool WingCStruct::existDefineValue(const QString &type) {
return _parser.constDefs().contains(type);
}
int WingCStruct::defineValue(const QString &type) {
return _parser.constDefs().value(type, 0);
}
bool WingCStruct::metadata(qsizetype offset, const QString &type,
const QColor &fg, const QColor &bg,
const QString &comment) {
@ -927,6 +971,37 @@ QVariant WingCStruct::existStruct(const QVariantList &params) {
return existStruct(type);
}
QVariant WingCStruct::constDefines(const QVariantList &params) {
if (!params.isEmpty()) {
return getScriptCallError(-1, tr("InvalidParamsCount"));
}
return constDefines();
}
QVariant WingCStruct::existDefineValue(const QVariantList &params) {
if (params.size() != 1) {
return getScriptCallError(-1, tr("InvalidParamsCount"));
}
auto type_v = params.at(0);
if (!type_v.canConvert<QString>()) {
return getScriptCallError(-2, tr("InvalidParam"));
}
auto type = type_v.toString();
return existDefineValue(type);
}
QVariant WingCStruct::defineValue(const QVariantList &params) {
if (params.size() != 1) {
return getScriptCallError(-1, tr("InvalidParamsCount"));
}
auto type_v = params.at(0);
if (!type_v.canConvert<QString>()) {
return getScriptCallError(-2, tr("InvalidParam"));
}
auto type = type_v.toString();
return defineValue(type);
}
QVariant WingCStruct::metadata(const QVariantList &params) {
if (params.size() != 5) {
return getScriptCallError(-1, tr("InvalidParamsCount"));

View File

@ -70,6 +70,11 @@ private:
WING_SERVICE qsizetype sizeofStruct(const QString &type);
WING_SERVICE bool existStruct(const QString &type);
// defines
WING_SERVICE QStringList constDefines();
WING_SERVICE bool existDefineValue(const QString &type);
WING_SERVICE int defineValue(const QString &type);
// metadata
WING_SERVICE bool metadata(qsizetype offset, const QString &type,
const QColor &fg, const QColor &bg,
@ -115,6 +120,11 @@ private:
QVariant sizeofStruct(const QVariantList &params);
QVariant existStruct(const QVariantList &params);
// defines
QVariant constDefines(const QVariantList &params);
QVariant existDefineValue(const QVariantList &params);
QVariant defineValue(const QVariantList &params);
QVariant metadata(const QVariantList &params);
QVariant foreground(const QVariantList &params);
QVariant background(const QVariantList &params);

View File

@ -10,6 +10,7 @@ The following components are all third-party components used by the software. Th
* [QtSingleApplication](https://github.com/qtproject/qt-solutions/tree/master/qtsingleapplication) (BSD-3-Clause)
* [QWindowKit](https://github.com/stdware/qwindowkit) (Apache v2.0)
* [AngelScript](https://github.com/codecat/angelscript-mirror) (zlib license)
* [cpptrace](https://github.com/jeremy-rifkin/cpptrace) (MIT)
* [QConsoleWidget](https://github.com/gapost/qconsolewidget) (MIT, **FORK** -> AGPL-3.0)
* [QColorPicker](https://github.com/arsdever/qcolorpicker) (MIT)
* [QtJsonModel](https://github.com/dridk/QJsonmodel) (MIT)

View File

@ -487,7 +487,7 @@ bool PluginSystem::dispatchEvent(IWingPlugin::RegisteredEvent event,
}
} break;
case WingHex::IWingPlugin::RegisteredEvent::ScriptPragma: {
Q_ASSERT(params.size() == 4);
Q_ASSERT(params.size() == 3);
auto section = params.at(0).toString();
auto plgID = params.at(1).toString();
auto &es = _evplgs[event];
@ -501,7 +501,7 @@ bool PluginSystem::dispatchEvent(IWingPlugin::RegisteredEvent event,
if (!_pragmaedPlg.contains(plg)) {
plg->eventOnScriptPragmaInit();
}
return plg->eventOnScriptPragma(section, params.at(3).toStringList());
return plg->eventOnScriptPragma(section, params.at(2).toStringList());
} break;
case WingHex::IWingPlugin::RegisteredEvent::ScriptPragmaInit: {
Q_ASSERT(false);