From 8fd49dc4c90592ce08bfa8d099231b4990b9eca8 Mon Sep 17 00:00:00 2001 From: msojocs Date: Sat, 1 Jul 2023 10:10:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Machine::Feed=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/wxml.h | 3 ++- src/wxml/dom_lib/machine.cpp | 19 ++++++++------ src/wxml/dom_lib/parser.cpp | 1 + src/wxml/dom_lib/wxml_dom.cpp | 48 ++++++++++++++++++++++++++++++++--- test/wcc.disassembly.cpp | 30 ++++++++++++---------- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/include/wxml.h b/src/include/wxml.h index 771d96a..16c5f91 100644 --- a/src/include/wxml.h +++ b/src/include/wxml.h @@ -189,7 +189,7 @@ namespace WXML ~Machine(); void Reset(void); void InitTransitTable(void); - void Feed(char,std::vector &,std::string &,std::vector &,int); + int Feed(char,std::vector &,std::string &,std::vector &,int); }; @@ -317,6 +317,7 @@ namespace WXML bool operator==(std::string tag); std::string ToCamelStyle(std::string const&); void AddTestAttr(std::string const&, std::stringstream &, char); + bool HasSpAttrPrefix(void); }; diff --git a/src/wxml/dom_lib/machine.cpp b/src/wxml/dom_lib/machine.cpp index de20fd1..61981d0 100644 --- a/src/wxml/dom_lib/machine.cpp +++ b/src/wxml/dom_lib/machine.cpp @@ -295,9 +295,8 @@ namespace WXML this->STT[ (0x5665E0 - 0x00566560)/4] = 3; } } - int dword_567960[1000] = {0}; - void Machine::Feed( + int Machine::Feed( char inputChar, std::vector & a3, std::string &errorMessage, @@ -321,14 +320,15 @@ namespace WXML v46 = this->TT[257 * v45 + inputChar]; if (!v46) { - v46 = dword_567960[257 * v45]; + v46 = this->TT[ (0x567960 - 0x00567560)/4 + 257 * v45]; if(!v46) { std::stringstream ss; ss << "BAD STATE MACHINE! AT INPUT "; ss << this->offset_24 << " " << inputChar; errorMessage = ss.str(); - return; + throw errorMessage; + // return; } } if (v46 < 0) @@ -346,7 +346,7 @@ namespace WXML ss << "unexpected end"; } errorMessage = ss.str(); - return; + throw errorMessage; } this->offset_24 = (uint16_t)v46; if (bittest(&v46, 0x15u)) // 0x15 -> 21 @@ -408,11 +408,12 @@ namespace WXML WXML::DOMLib::Token v49; v49.offset_8 = this->offset_16; v49.offset_12 = this->offset_20; + auto t4 = this->offset_4; this->offset_4 = this->fileLength; this->offset_20 = this->lineLength; this->offset_16 = this->lineCount; - v49.offset_16 = this->offset_4; - v49.offset_20 = this->lineLength + 1 - this->offset_4; + v49.offset_16 = t4; + v49.offset_20 = this->fileLength - t4; int stt = WXML::DOMLib::Machine::STT[v45]; v49.offset_24 = stt; if (stt == 3) @@ -430,12 +431,14 @@ namespace WXML offset_4 = fileLength; offset_20 = lineLength; } - return; + return 0; } catch(const std::exception& e) { std::cerr << e.what() << '\n'; + return -1; } + return 0; } void Machine::Reset() diff --git a/src/wxml/dom_lib/parser.cpp b/src/wxml/dom_lib/parser.cpp index 8a8d110..b21dd83 100644 --- a/src/wxml/dom_lib/parser.cpp +++ b/src/wxml/dom_lib/parser.cpp @@ -210,6 +210,7 @@ namespace WXML int v17 = 0; // TODO v18 = *v16 + v43[4]; char* v18 = &v16[0] + token.offset_16; + // offset_20第一次是3 while(token.offset_20 > v17) { int v19 = *(uint8_t *)(v18 + v17) - 9; diff --git a/src/wxml/dom_lib/wxml_dom.cpp b/src/wxml/dom_lib/wxml_dom.cpp index 219add4..24dcedb 100644 --- a/src/wxml/dom_lib/wxml_dom.cpp +++ b/src/wxml/dom_lib/wxml_dom.cpp @@ -843,7 +843,7 @@ namespace WXML { } if (!hasIf) { - int v7 = a2 - 1; + int v11 = a2 - 1; if(this->offset_48.begin() == this->offset_48.end()) { for (int i = a2 + 1; i < this->offset_48.size(); i++) @@ -857,13 +857,21 @@ namespace WXML { { break; } - // a3[1].find() - // TODO... + if( + a3.end() != std::find(a3.begin(), a3.end(), this->offset_72[i]->offset_0) + || this->offset_72[i]->offset_72.begin() != this->offset_72[i]->offset_72.end() + ) + { + return hasElIf; + } + v11 = i; } } + while (v11 >= a2) + this->offset_72.erase(this->offset_72.begin() + v11--); + return true; } - return true; } bool WXMLDom::operator==(std::string tag) { @@ -891,5 +899,37 @@ namespace WXML { v15 << " with message: " << a5 << "."; return v15.str(); } + + bool WXMLDom::HasSpAttrPrefix() + { + for (auto i = this->offset_48.begin(); i != this->offset_48.end(); i++) + { + auto v3 = i->first.data(); + if (strncmp(v3, "bind", 4u)) + { + + if ( strncmp(v3, "catch", 5u) ) + { + if ( strncmp(v3, "capture-bind", 0xCu) ) + { + if ( strncmp(v3, "capture-catch", 0xDu) ) + { + if ( i->first != "slot" ) + { + if ( strncmp(v3, "wx:", 3u) ) + { + if ( strncmp(v3, "mark:", 5u) ) + continue; + } + } + } + } + } + } + return true; + } + return false; + + } } } \ No newline at end of file diff --git a/test/wcc.disassembly.cpp b/test/wcc.disassembly.cpp index 3c0e66a..8dcb8ab 100644 --- a/test/wcc.disassembly.cpp +++ b/test/wcc.disassembly.cpp @@ -27125,7 +27125,7 @@ LABEL_12: // this v31 = lpuexcpt; - // offset_0 + 1 lineCount + // offset_0 + 1 fileLength v32 = *(_DWORD *)lpuexcpt + 1; // offset_12 + 1 lineLength v33 = *((_DWORD *)lpuexcpt + 3) + 1; @@ -27139,23 +27139,23 @@ LABEL_12: v57 = v59; v61 = v63; v65 = v67; - // offset_16 + // this->offset_16 v35 = *((_DWORD *)v31 + 4); - // offset_0 + // v49.offset_0 v49 = 0; - // offset_8 = this->offset_16 + // v49.offset_8 = this->offset_16 v51 = v35; - // offset_20 + // this->offset_20 v36 = *((_DWORD *)v31 + 5); - // offset_4 + // v49.offset_4 v50 = 0; // token.offset_12 = this->offset_20 v52 = v36; - // this.offset_4 + // v37 = this.offset_4 v37 = *((_DWORD *)v31 + 1); - // this.offset_4 = this.offset_4 + 1 + // this.offset_4 = this.offset_0 + 1 = this->fileLength *((_DWORD *)v31 + 1) = v32; - // this.offset_8 + // this.offset_8(lineCount) v38 = *((_DWORD *)v31 + 2); // this.offset_20 = this.offset_12(lineLength) *((_DWORD *)v31 + 5) = v33; @@ -27172,9 +27172,9 @@ LABEL_12: v56 = 0; v64 = 0; v60 = -1; - // offset_16 = this->offset_4 + // token.offset_16 = this->offset_4 v53 = v37; - // offset_20 = - this->offset_4 + // v49.offset_20 = (this->offset_0 + 1)fileLength - this->offset_4 v54 = v34 - v37; if ( v39 == 3 ) v40 = a5; @@ -52736,10 +52736,12 @@ char __thiscall WXML::DOMLib::WXMLDom::IfHasItsElse(_DWORD *this, signed int a2, std::string::_M_dispose(v23); if ( !v18 ) break; - v12 = a3[1]; + v12 = a3[1]; // a3.offset_4 if ( v12 != std::find<__gnu_cxx::__normal_iterator>,std::string>( - *a3, - v12, + *a3, // start + v12, // end + // this->offset_(18 * 4) -> this->offset_72 + // this->offset_72[i] *(_DWORD *)(this[18] + v10)) || *(_DWORD *)(*(_DWORD *)(this[18] + v10) + 76) != *(_DWORD *)(*(_DWORD *)(this[18] + v10) + 72) ) {