From c1c1e1e7976dfc9318961d41322402dd902abfc2 Mon Sep 17 00:00:00 2001 From: msojocs Date: Mon, 10 Jul 2023 15:41:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 43 +++++++++++++++++++++++++++++++++ src/include/wxml.h | 4 +-- src/wxml/dom_lib/parser.cpp | 3 --- src/wxml/dom_lib/wxml_dom.cpp | 14 ++++------- src/wxml/expr_lib/parser.cpp | 20 ++++++++++++--- src/wxml/expr_lib/token.cpp | 4 +-- src/wxml/expr_lib/tokenizer.cpp | 23 +++++++++++------- test/wcc.disassembly.cpp | 11 +++++---- 8 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6971901 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,43 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/wcc", + "args": [ + "\"--config-path\"", + "\"/mnt/d/Work/disassembly/wcc-exec/wcc/cmd1.txt\"" + ], + "stopAtEntry": false, + "cwd": "/mnt/d/Work/WeChatProjects/miniprogram-demo/miniprogram", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "sourceFileMap":{ + "${workspaceRoot}": { + "editorPath": "${workspaceRoot}", + "useForBreakpoints": true + } + } + } + + ] +} \ No newline at end of file diff --git a/src/include/wxml.h b/src/include/wxml.h index 7ea6d0a..8153426 100644 --- a/src/include/wxml.h +++ b/src/include/wxml.h @@ -547,9 +547,9 @@ namespace WXML private: /* data */ public: - int offset_0; + int offset_0 = 0; std::string offset_4; - std::string offset_12; + std::string offset_16; Token(/* args */); ~Token(); std::string GetLiteral(void); diff --git a/src/wxml/dom_lib/parser.cpp b/src/wxml/dom_lib/parser.cpp index 9607e94..7e73445 100644 --- a/src/wxml/dom_lib/parser.cpp +++ b/src/wxml/dom_lib/parser.cpp @@ -5,9 +5,6 @@ namespace WXML { namespace DOMLib { - - const char *szWXIFControlAttrs[4] = { "wx-if", "wx:if", "wx:elif", "wx:else" }; // weak - Parser::Parser(/* args */) { this->offset_104.offset_24 = 4; diff --git a/src/wxml/dom_lib/wxml_dom.cpp b/src/wxml/dom_lib/wxml_dom.cpp index 6bfbf0c..a0c73cc 100644 --- a/src/wxml/dom_lib/wxml_dom.cpp +++ b/src/wxml/dom_lib/wxml_dom.cpp @@ -386,11 +386,10 @@ namespace WXML { if (forItems == cur->offset_48.end() && cur->offset_0 != "block") { const char **v38 = WXML::DOMLib::szWXIFControlAttrs; - while (*v38) + for (size_t j = 0; j < 4; j++) { - std::string v101 = *v38; + std::string v101 = v38[j]; auto v9 = cur->offset_48.find(v101); - ++v38; if (v9 != cur->offset_48.end()) { std::shared_ptr v98(new WXML::DOMLib::WXMLDom()); @@ -651,17 +650,14 @@ namespace WXML { { goto LABEL_56; } - while (true) + for (size_t i = 0; i < 4; i++) { - if (!*v98) - break; - auto v97 = cur->offset_48.find(*v98); + auto v97 = cur->offset_48.find(v98[i]); if (v97 != cur->offset_48.end()) { - v153 = *v98; + v153 = v98[i]; break; } - ++v98; } if(cur->offset_48[v153].offset_56 == -3) { diff --git a/src/wxml/expr_lib/parser.cpp b/src/wxml/expr_lib/parser.cpp index 3bf5353..c669c7b 100644 --- a/src/wxml/expr_lib/parser.cpp +++ b/src/wxml/expr_lib/parser.cpp @@ -5,6 +5,19 @@ namespace WXML namespace EXPRLib { + int off_55F220() + { + return 1; + } + int off_55F20C() + { + return 3; + } + int off_55F1E4() + { + return 2; + } + Parser::Parser(/* args */) { } @@ -48,9 +61,11 @@ namespace WXML // WXML::EXPRLib::Parser::Parse - 15 std::shared_ptr v68(new WXML::EXPRLib::Base()); + v68->offset_0 = off_55F220; v68->offset_4 = "$"; this->offset_0.push_back(v68); std::shared_ptr v70(new WXML::EXPRLib::Base()); + v70->offset_0 = off_55F1E4; if (a7) { v70->offset_4 = WXML::EXPRLib::TransitTable::GetAttrListNTType(); @@ -66,14 +81,13 @@ namespace WXML { auto v72 = *cur; - WXML::EXPRLib::Token v84 = v72->offset_8[v49]; // ??? + WXML::EXPRLib::Token v84 = v74[v49]; // ??? int v15 = v72->offset_0(); // WXML::EXPRLib::Parser::Parse - 20-1 if (v15 == 1) { - std::string tokenName = v84.GetTokenName(); - if (v72->offset_4 != tokenName || v49 >= 5) + if (v72->offset_4 != tokenName || v49 >= v74.size()) { a6 = "error at token `"; a6 += v84.GetLiteral(); diff --git a/src/wxml/expr_lib/token.cpp b/src/wxml/expr_lib/token.cpp index 254f141..86d223a 100644 --- a/src/wxml/expr_lib/token.cpp +++ b/src/wxml/expr_lib/token.cpp @@ -48,9 +48,9 @@ namespace WXML if (this->offset_0 != 5) { result = ""; - if (this->offset_12.size()) + if (this->offset_16.size()) { - return this->offset_12; + return this->offset_16; } } } diff --git a/src/wxml/expr_lib/tokenizer.cpp b/src/wxml/expr_lib/tokenizer.cpp index f43a76e..0eb1e12 100644 --- a/src/wxml/expr_lib/tokenizer.cpp +++ b/src/wxml/expr_lib/tokenizer.cpp @@ -182,8 +182,9 @@ namespace WXML { int v21 = 18899; WXML::EXPRLib::Tokenizer::InitTransitTable(); int v24 = 1; - int v29; - for (int v28 = 0; v28 < this->offset_0.size();) + int v29 = 0; + int v28 = 0; + while (v28 <= this->offset_0.size()) { if (!--v21) { @@ -199,7 +200,7 @@ namespace WXML { int t = WXML::EXPRLib::Tokenizer::TT[257 * v24 + v3]; if (!t) { - t = WXML::EXPRLib::Tokenizer::TT[257 * v24]; + t = WXML::EXPRLib::Tokenizer::TT[(0x6689A0 - 0x006685A0) / 4 + 257 * v24]; if (!t) { std::stringstream v39; @@ -214,6 +215,7 @@ namespace WXML { v39 << "unexpected `" << v3 << "` at pos" << v28; a3 = v39.str(); } + v24 = (uint16_t)t; if ((t & 0x30000) != 0) { int v8 = 1; @@ -229,14 +231,16 @@ namespace WXML { if (v29 <= v27) { WXML::EXPRLib::Token v39; - char* KEYWORDS[] = {}; + v39.offset_0 = v8; + const char* KEYWORDS[4] = { "true", "false", "undefined", "null"}; if (v8) { - char **v31 = KEYWORDS; + const char **v31 = KEYWORDS; std::string v26 = this->offset_0.substr(v29, v27 + 1); - while (*v31) + + for (int i = 0; i < 4; i++) { - if (!strcmp(v26.data(), *v31++)) + if (!strcmp(v26.data(), v31[i])) { v39.offset_0 = 4; break; @@ -246,13 +250,14 @@ namespace WXML { } else { - a2.push_back(v39); + v39.offset_4 = this->offset_0.substr(v29, v27 + 1 - v29); } + a2.push_back(v39); v29 = v27 + 1; } } v28 += (t & 0x400000) == 0; - if (t &0x800000 != 0) + if (((uint)t & 0x800000) != 0) v29 = v28; } return 0; diff --git a/test/wcc.disassembly.cpp b/test/wcc.disassembly.cpp index 93d03ae..8a278a7 100644 --- a/test/wcc.disassembly.cpp +++ b/test/wcc.disassembly.cpp @@ -7682,9 +7682,9 @@ void (__cdecl *off_55F0D4)(__cxxabiv1::__class_type_info *__hidden this) = &__cx void (__cdecl *off_55F114)(__cxxabiv1::__si_class_type_info *__hidden this) = &__cxxabiv1::__si_class_type_info::~__si_class_type_info; // weak void (__cdecl *off_55F140)(__cxxabiv1::__vmi_class_type_info *__hidden this) = &__cxxabiv1::__vmi_class_type_info::~__vmi_class_type_info; // weak void (__cdecl *off_55F16C)(_anonymous_namespace_::io_error_category *__hidden this) = &`anonymous namespace'::io_error_category::~io_error_category; // weak -void (__cdecl *off_55F1E4)(WXML::EXPRLib::NonTerminal *__hidden this) = &WXML::EXPRLib::NonTerminal::~NonTerminal; // weak -void (__cdecl *off_55F20C)(WXML::EXPRLib::Action *__hidden this) = &WXML::EXPRLib::Action::~Action; // weak -void (__cdecl *off_55F220)(WXML::EXPRLib::Terminal *__hidden this) = &WXML::EXPRLib::Terminal::~Terminal; // weak +void (__cdecl *off_55F1E4)(WXML::EXPRLib::NonTerminal *__hidden this) = &WXML::EXPRLib::NonTerminal::~NonTerminal; // weak return 2 +void (__cdecl *off_55F20C)(WXML::EXPRLib::Action *__hidden this) = &WXML::EXPRLib::Action::~Action; // weak return 3 +void (__cdecl *off_55F220)(WXML::EXPRLib::Terminal *__hidden this) = &WXML::EXPRLib::Terminal::~Terminal; // weak // return 1 int (*off_55F234[2])() = { &__gnu_cxx::stdio_filebuf::~stdio_filebuf, @@ -29713,6 +29713,7 @@ int __thiscall WXML::EXPRLib::Tokenizer::GetTokens(int *this, _DWORD *a2, unsign } else { + // v25 -> *this v10 = (char *)(v29 + v25); do { @@ -29724,7 +29725,7 @@ int __thiscall WXML::EXPRLib::Tokenizer::GetTokens(int *this, _DWORD *a2, unsign *((_BYTE *)v40 + v27 + 1 - v29) = 0; } v32 = a2[1]; - if ( v32 == a2[2] ) + if ( v32 == a2[2] ) // begin == end { std::vector::_M_realloc_insert( a2, @@ -29750,7 +29751,7 @@ int __thiscall WXML::EXPRLib::Tokenizer::GetTokens(int *this, _DWORD *a2, unsign std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count(&v42); } } - // v19 临时存储,其它弟妹没用到 + // v19 临时存储,其它地方没用到 v19 = v29; v28 += ((unsigned int)lpuexcpt & 0x400000) == 0; if ( ((unsigned int)lpuexcpt & 0x800000) != 0 )