diff --git a/src/include/wxss.h b/src/include/wxss.h index 56ed95f..b2ae942 100644 --- a/src/include/wxss.h +++ b/src/include/wxss.h @@ -164,7 +164,7 @@ namespace WXSS void GetHostRule(std::string &); int ShowTree(std::string &); int GetCompiled(std::string const&, std::string&); - void GetJSCompiled(std::string const&, std::string&); + int GetJSCompiled(std::string const&, std::string&); int GetWellFormattedJSCompiled(std::string const&, std::string&); void GenExpr(std::shared_ptr, std::stringstream &, std::string &); int GetPageCss(std::string const&, std::string&, uint); diff --git a/src/wxss/x_compiler.cpp b/src/wxss/x_compiler.cpp index a967878..b20695d 100644 --- a/src/wxss/x_compiler.cpp +++ b/src/wxss/x_compiler.cpp @@ -146,28 +146,177 @@ namespace WXSS std::string v3 = WXML::Rewrite::ToStringCode2(a1); WXML::GetStrForMakingCSS(v3, a2); a1 = ""; + return; } - void XCompiler::GetHostRule(std::string &) + void XCompiler::GetHostRule(std::string & a2) { - throw "not implement"; + std::string v6; + for (auto i = this->offset_32.rbegin(); i != this->offset_32.rend(); i++) + { + i->second->GetHostRule(v6); + } + std::stringstream v9; + v9 << "setCssToHead(["; + this->DealRPX(v6, v9); + v9 << "])"; + a2 = v9.str(); + return ; } - int XCompiler::ShowTree(std::string &) + int XCompiler::ShowTree(std::string & a2) { - throw "not implement"; + for (auto i = this->offset_32.rbegin(); i != this->offset_32.rend(); i++) + { + std::string v7 = "\n/* " + i->first; + v7.append(" */\n"); + a2 += v7; + std::stringstream v8; + i->second->Print2Stream(0, v8); + a2 = v8.str(); + } + return 0; } int XCompiler::GetCompiled(std::string const&, std::string&) { throw "not implement"; } - void XCompiler::GetJSCompiled(std::string const&, std::string&) + int XCompiler::GetJSCompiled(std::string const& a2, std::string& a3) { - throw "not implement"; + std::string v5; + int ret = this->GetCompiled(a2, v5); + if (!ret) + { + a3 = WXML::Rewrite::ToStringCode2(v5); + } + return ret; } - int XCompiler::GetWellFormattedJSCompiled(std::string const&, std::string&) + int XCompiler::GetWellFormattedJSCompiled(std::string const& a2, std::string& a3) { - throw "not implement"; + std::string v5; + int ret = this->GetJSCompiled(a2, v5); + if (!ret) + { + std::stringstream v8; + v8 << "var BASE_DEVICE_WIDTH = 750;\n" + "var isIOS=navigator.userAgent.match(\"iPhone\");\n" + "var deviceWidth = window.screen.width || 375;\n" + "var deviceDPR = window.devicePixelRatio || 2;\n" + "var checkDeviceWidth = window.__checkDeviceWidth__ || function() {\n" + "var newDeviceWidth = window.screen.width || 375\n" + "var newDeviceDPR = window.devicePixelRatio || 2\n" + "var newDeviceHeight = window.screen.height || 375\n" + "if (window.screen.orientation && /^landscape/.test(window.screen.orientation.type || '')) newDeviceWidth = newDevi" + "ceHeight\n" + "if (newDeviceWidth !== deviceWidth || newDeviceDPR !== deviceDPR) {\n" + "deviceWidth = newDeviceWidth\n" + "deviceDPR = newDeviceDPR\n" + "}\n" + "}\n" + "checkDeviceWidth()\n" + "var eps = 1e-4;\n" + "var transformRPX = window.__transformRpx__ || function(number, newDeviceWidth) {\n" + "if ( number === 0 ) return 0;\n" + "number = number / BASE_DEVICE_WIDTH * ( newDeviceWidth || deviceWidth );\n" + "number = Math.floor(number + eps);\n" + "if (number === 0) {\n" + "if (deviceDPR === 1 || !isIOS) {\n" + "return 1;\n" + "} else {\n" + "return 0.5;\n" + "}\n" + "}\n" + "return number;\n" + "}\n" + "window.__rpxRecalculatingFuncs__ = window.__rpxRecalculatingFuncs__ || [];\n" + "var __COMMON_STYLESHEETS__ = __COMMON_STYLESHEETS__||{}\n" + "%s\n" + "var setCssToHead = function(file, _xcInvalid, info) {\n" + "var Ca = {};\n" + "var css_id;\n" + "var info = info || {};\n" + "var _C = __COMMON_STYLESHEETS__\n" + "function makeup(file, opt) {\n" + "var _n = typeof(file) === \"string\";\n" + "if ( _n && Ca.hasOwnProperty(file)) return \"\";\n" + "if ( _n ) Ca[file] = 1;\n" + "var ex = _n ? _C[file] : file;\n" + "var res=\"\";\n" + "for (var i = ex.length - 1; i >= 0; i--) {\n" + "var content = ex[i];\n" + "if (typeof(content) === \"object\")\n" + "{\n" + "var op = content[0];\n" + "if ( op == 0 )\n" + "res = transformRPX(content[1], opt.deviceWidth) + \"px\" + res;\n" + "else if ( op == 1)\n" + "res = opt.suffix + res;\n" + "else if ( op == 2 )\n" + "res = makeup(content[1], opt) + res;\n" + "}\n" + "else\n" + "res = content + res\n" + "}\n" + "return res;\n" + "}\n" + "var styleSheetManager = window.__styleSheetManager2__\n" + "var rewritor = function(suffix, opt, style){\n" + "opt = opt || {};\n" + "suffix = suffix || \"\";\n" + "opt.suffix = suffix;\n" + "if ( opt.allowIllegalSelector != undefined && _xcInvalid != undefined )\n" + "{\n" + "if ( opt.allowIllegalSelector )\n" + "console.warn( \"For developer:\" + _xcInvalid );\n" + "else\n" + "{\n" + "console.error( _xcInvalid );\n" + "}\n" + "}\n" + "Ca={};\n" + "css = makeup(file, opt);\n" + "if (styleSheetManager) {\n" + "var key = (info.path || Math.random()) + ':' + suffix\n" + "if (!style) {\n" + "styleSheetManager.addItem(key, info.path);\n" + "window.__rpxRecalculatingFuncs__.push(function(size){\n" + "opt.deviceWidth = size.width;\n" + "rewritor(suffix, opt, true);\n" + "});\n" + "}\n" + "styleSheetManager.setCss(key, css);\n" + "return;\n" + "}\n" + "if ( !style )\n" + "{\n" + "var head = document.head || document.getElementsByTagName('head')[0];\n" + "style = document.createElement('style');\n" + "style.type = 'text/css';\n" + "style.setAttribute( \"wxss:path\", info.path );\n" + "head.appendChild(style);\n" + "window.__rpxRecalculatingFuncs__.push(function(size){\n" + "opt.deviceWidth = size.width;\n" + "rewritor(suffix, opt, style);\n" + "});\n" + "}\n" + "if (style.styleSheet) {\n" + "style.styleSheet.cssText = css;\n" + "} else {\n" + "if ( style.childNodes.length == 0 )\n" + "style.appendChild(document.createTextNode(css));\n" + "else\n" + "style.childNodes[0].nodeValue = css;\n" + "}\n" + "}\n" + "return rewritor;\n" + "}\n" + "setCssToHead(["; + WXML::GetStrForMakingCSS(v5, v8); + v8 << "])( typeof __wxAppSuffixCode__ == \"undefined\"? undefined : __wxAppSuffixCode__ );"; + a3 = v8.str(); + } + + return ret; } - void XCompiler::GenExpr(std::shared_ptr, std::stringstream &, std::string &) + void XCompiler::GenExpr(std::shared_ptr a2, std::stringstream & a3, std::string & a4) { throw "not implement"; } diff --git a/test/wcsc.disassembly.cpp b/test/wcsc.disassembly.cpp index 0b36acc..d467cb3 100644 --- a/test/wcsc.disassembly.cpp +++ b/test/wcsc.disassembly.cpp @@ -7694,12 +7694,15 @@ int __thiscall WXSS::XCompiler::GetHostRule(_DWORD *this, _DWORD *a2) char v10[4]; // [esp+88h] [ebp-D0h] BYREF char v11[204]; // [esp+8Ch] [ebp-CCh] BYREF - v6[1] = 0; + v6[1] = 0; // std::string v6[0] = &v7; v7 = 0; + + // this[11] -> this->offset_44 for ( i = (struct _Unwind_Exception *)this[11]; ; i = (struct _Unwind_Exception *)std::_Rb_tree_increment((int)lpuexcpt) ) { lpuexcpt = i; + // this->offset_36 if ( i == (struct _Unwind_Exception *)(this + 9) ) break; WXSS::CSSTreeLib::CSSSyntaxTree::GetHostRule(*((_DWORD *)i + 10), (WXSS::Token *)v6); @@ -7928,9 +7931,10 @@ struct _Unwind_Exception *__thiscall WXSS::XCompiler::GetWellFormattedJSCompiled char v9[4]; // [esp+88h] [ebp-D0h] BYREF char v10[204]; // [esp+8Ch] [ebp-CCh] BYREF - v5[1] = 0; v5[0] = &v6; + v5[1] = 0; v6 = 0; + lpuexcpt = WXSS::XCompiler::GetJSCompiled(this, a2, v5); if ( !lpuexcpt ) {