diff --git a/src/include/night.h b/src/include/night.h index 0d0a699..c882a02 100644 --- a/src/include/night.h +++ b/src/include/night.h @@ -44,6 +44,8 @@ namespace night extern std::string nsv_; extern std::string nst_; + extern std::string NS_BUILTIN_SPACE; + int compile_ns(std::string const&,std::string const&,std::string const&,uint,std::string&,bool); void compile_ns_with_sourcemap(std::string const&,std::string const&,std::string const&,std::string const&,uint,std::string&,std::string&); void readfile(char const*, std::string &); @@ -61,11 +63,11 @@ namespace night std::string offset_108; std::string offset_132; std::string offset_156; - night::ns_node * offset_180; - night::ns_node * offset_184; - night::ns_node * offset_192; - std::vector* offset_196; - std::vector* offset_228; + night::ns_node * offset_180 = nullptr; + night::ns_node * offset_184 = nullptr; + night::ns_node * offset_192 = nullptr; + std::vector* offset_196 = nullptr; + std::vector* offset_228 = nullptr; ns_node(/* args */); ~ns_node(); std::string debug_no_space(void); @@ -78,7 +80,15 @@ namespace night public: struct GodsSon { std::string offset_0; - std::vector* offset_24; + union + { + /* data */ + std::vector* offset_24_vec = nullptr; + night::ns_node * offset_24_node; + }; + + // std::vector* offset_24; + }; std::vector offset_0; NSGod(/* args */); @@ -101,12 +111,12 @@ namespace night NSStream(/* args */); NSStream(std::string const&,std::string const&,uint); ~NSStream(); - void eof(void); - void eof_2(void); + bool eof(void); + bool eof_2(void); void err(std::string const&,int,int,bool); - void next(void); - void peek(void); - void peek_2(void); + char next(void); + char peek(void); + char peek_2(void); }; class NSToken @@ -114,8 +124,11 @@ namespace night private: /* data */ public: + NSGod offset_0; NSStream offset_4; // 不是int - night::ns_node* offset_8; + night::ns_node* offset_8 = nullptr; + std::vector offset_12; + NSToken(/* args */); ~NSToken(); bool eof(void); @@ -129,17 +142,17 @@ namespace night void read_comment_method_2(void); night::ns_node* read_next(void); void read_number(std::string const&); - void read_string(char, std::string const&); + night::ns_node * read_string(char, std::string const&); void read_var(std::string const&); std::string read_while(bool (*)(char,void *),void *); void rw_cb_number(char,void *); void skip_comment(std::string &); - void tk_is_comment2(char,void *); - void tk_is_not_line_break(char,void *); - void tk_is_valid_op_str(char,void *); - void tk_is_var(char,void *); + static bool tk_is_comment2(char,void *); + static bool tk_is_not_line_break(char,void *); + bool tk_is_valid_op_str(char,void *); + bool tk_is_var(char,void *); void tk_is_var_start(char,void *); - void tk_is_whitespace(char,void *); + static bool tk_is_whitespace(char,void *); }; class NSASTParse @@ -147,8 +160,8 @@ namespace night private: /* data */ std::string offset_0; - night::NSGod * offset_24; - night::NSToken * offset_28; + night::NSGod * offset_24 = nullptr; + night::NSToken * offset_28 = nullptr; int offset_36; int offset_40; std::string offset_44; @@ -230,10 +243,10 @@ namespace night { private: /* data */ - night::NSASTParse * offset_24; - std::vector * offset_28; public: std::string offset_0; + night::NSASTParse * offset_24 = nullptr; + std::vector * offset_28 = nullptr; std::vector offset_36; int offset_48; NSCompileJs(/* args */); @@ -262,7 +275,7 @@ namespace night namespace str { - void get_token(std::string const&, int); + std::string get_token(std::string const&, int); bool path_combine( std::string const&, std::string const&, diff --git a/src/night/night.cpp b/src/night/night.cpp index eebe71b..1171e20 100644 --- a/src/night/night.cpp +++ b/src/night/night.cpp @@ -37,6 +37,7 @@ namespace night std::string NS_BUILTIN_OP_SELF = "~!"; std::string NS_BUILTIN_ALL_OP = " = ? + - * / % ++ -- + - ~ ! << >> >>> & ^ | < > <= >= == != === !== *= /= %= += -= <<= >>= >>>= &= ^= |= && || "; std::string NS_BUILTIN_PUNC = ".,;(){}[]:"; + std::string NS_BUILTIN_SPACE = " \t\r\n"; std::string std_v_n = "new std::vector"; std::string std_v_v_n = "new std::vector*>"; @@ -60,6 +61,7 @@ namespace night NSCompileJs cjs; std::string v19; std::vector v18; + cjs.offset_24 = &v39; std::string v21 = cjs.compile_once(v19, &v18, a6); v17.hamlet(); if (v21.length()) diff --git a/src/night/ns_god/ns_god.cpp b/src/night/ns_god/ns_god.cpp index 53602c5..7b49c8c 100644 --- a/src/night/ns_god/ns_god.cpp +++ b/src/night/ns_god/ns_god.cpp @@ -14,21 +14,30 @@ namespace night { night::NSGod::GodsSon* node = new night::NSGod::GodsSon(); + node->offset_0.assign(a2); if (night::std_v_n == a2) { - + node->offset_24_vec = new std::vector(); } if (night::std_v_v_n == a2) { - + node->offset_24_vec = new std::vector(); } this->offset_0.push_back(node); - return node->offset_24; + return node->offset_24_vec; } - night::ns_node* NSGod::gen_son(std::string) + night::ns_node* NSGod::gen_son(std::string a2) { + night::NSGod::GodsSon *v6 = new night::NSGod::GodsSon(); + v6->offset_0.assign(a2); + night::ns_node *v4 = new night::ns_node(); + v4->offset_0.assign(a2); + v6->offset_24_node = v4; + this->offset_0.push_back(v6); + + return v4; } void NSGod::hamlet(void) @@ -38,19 +47,27 @@ namespace night auto v3 = this->offset_0[i]; if (v3->offset_0 == night::std_v_n) { - auto v4 = v3->offset_24; + auto v4 = v3->offset_24_vec; if (v4) { delete v4; } + if (v3->offset_24_node) + { + delete v3->offset_24_node; + } } if (v3->offset_0 == night::std_v_v_n) { - auto v4 = v3->offset_24; + auto v4 = v3->offset_24_vec; if (v4) { delete v4; } + if (v3->offset_24_node) + { + delete v3->offset_24_node; + } } delete v3; diff --git a/src/night/ns_stream.cpp b/src/night/ns_stream.cpp index be15c70..b952518 100644 --- a/src/night/ns_stream.cpp +++ b/src/night/ns_stream.cpp @@ -14,18 +14,25 @@ namespace night { } - void NSStream::peek(void) + char NSStream::peek(void) { if (this->offset_48 < this->offset_24.length()) { char v3 = this->offset_24.at(this->offset_48); + return v3; } else { - + return 0; } } - void NSStream::peek_2(void) + + bool NSStream::eof(void) + { + return this->peek() == 0; + } + + char NSStream::peek_2(void) { if (this->offset_48 + 1 < this->offset_24.length()) { @@ -35,12 +42,42 @@ namespace night this->offset_52++; this->offset_56 = 1; } + return v3; } else { - + return 0; } } + + bool NSStream::eof_2(void) + { + return this->peek_2() == 0; + } + + char NSStream::next(void) + { + if (this->offset_48 < this->offset_24.length()) + { + char v7 = this->offset_24.at(this->offset_48); + this->offset_48++; + if (v7 == 10) // \n + { + this->offset_56 = 1; + this->offset_52++; + } + else + { + this->offset_56++; + } + return v7; + } + else + { + return 0; + } + } + void NSStream::err(std::string const& a2, int a3, int a4, bool a5) { std::string v10; diff --git a/src/night/ns_token.cpp b/src/night/ns_token.cpp index 0aa85a9..da517eb 100644 --- a/src/night/ns_token.cpp +++ b/src/night/ns_token.cpp @@ -1,4 +1,5 @@ #include "../include/night.h" +#include "../include/wxml.h" namespace night { @@ -9,6 +10,7 @@ namespace night NSToken::~NSToken() { } + night::ns_node* NSToken::peek(void) { auto result = this->offset_8; @@ -19,9 +21,38 @@ namespace night } return result; } + night::ns_node* NSToken::read_next(void) { + night::ns_node* v7 = nullptr; + if (this->offset_12.begin() == this->offset_12.end()) + { + auto v14 = this->read_while(night::NSToken::tk_is_whitespace, 0); + bool isEnd = this->offset_4.eof(); + if (!isEnd) + { + this->skip_comment(v14); + } + if ( isEnd + || (this->offset_4.eof()) + ) + { + v7 = 0; + } + else + { + auto v13 = this->offset_4.peek(); + this->read_string(v13, v14); + // TODO... + + } + return v7; + } + auto ret = this->offset_12.back(); + this->offset_12.pop_back(); + return ret; } + night::ns_node* NSToken::next(void) { auto result = this->offset_8; @@ -38,14 +69,160 @@ namespace night return this->peek() == 0; } - void NSToken::push(night::ns_node*) + void NSToken::push(night::ns_node* a2) { + if (this->offset_8) + { + this->offset_12.push_back(this->offset_8); + this->offset_8 = nullptr; + } + if (a2) + { + this->offset_12.push_back(a2); + } + } + + void NSToken::read_comment_method_1() + { + this->read_while(night::NSToken::tk_is_not_line_break, 0); + } + void NSToken::read_comment_method_2() + { + this->read_while(night::NSToken::tk_is_comment2, &this->offset_4); + this->offset_4.next(); + } + + void NSToken::skip_comment(std::string &a2) + { + while (true) + { + if (this->offset_4.eof()) + { + break; + } + auto v5 = this->offset_4.peek(); + if (v5 != '/') + { + break; + } + if (this->offset_4.eof_2()) + { + break; + } + v5 = this->offset_4.peek_2(); + if (v5 == '/') + { + v5 = this->offset_4.next(); + v5 = this->offset_4.next(); + this->read_comment_method_1(); + } + else + { + v5 = this->offset_4.peek_2(); + if (v5 == '*') + return; + v5 = this->offset_4.next(); + v5 = this->offset_4.next(); + this->read_comment_method_2(); + } + a2 = this->read_while(night::NSToken::tk_is_whitespace, 0); + + } } + night::ns_node * NSToken::read_string(char a2, std::string const& a3) + { + auto v12 = this->offset_4.next(); + std::string v10 = ""; + char v4; + for (int i = 0; ; i = v4) + { + v4 = this->offset_4.eof(); + if (v4) + { + break; + } + auto v9 = this->offset_4.eof(); + if ( v9 == '\n') + { + if (!i) + { + this->offset_4.err("Unexpected `\\n`", 0, 0, false); + } + v10.push_back('\n'); + } + else + { + if (!i) + { + if (v9 == '\\') + { + v4 = 1; + v10.push_back('\\'); + continue; + } + if (v9 == a2) + { + break; + } + } + v10.push_back(v9); + } + } + auto son = this->offset_0.gen_son(night::NS_TYPE_STR); + + son->offset_60 = WXML::Rewrite::ToStringCode(v10); + son->offset_108.replace(0, son->offset_108.length(), 1, a2); + son->offset_84.assign(a3); + return son; + + } + + std::string NSToken::read_while(bool (*a3)(char,void *), void *a4) + { + std::string result = ""; + while (!this->offset_4.eof()) + { + auto v6 = this->offset_4.peek(); + if (!a3(v6, a4)) + { + break; + } + v6 = this->offset_4.next(); + result.push_back(v6); + } + return result; + } void NSToken::err(std::string const& a2, int a3, int a4, bool a5) { this->offset_4.err(a2, a3, a4, a5); } + + bool NSToken::tk_is_whitespace(char ch, void *) + { + auto v1 = night::NS_BUILTIN_SPACE.find(ch, 0); + return v1 != -1; + } + bool NSToken::tk_is_not_line_break(char ch, void *) + { + return ch != 10; + } + bool NSToken::tk_is_comment2(char ch, void * t) + { + night::NSStream *a2 = (night::NSStream *)t; + auto v3 = a2->peek(); + if (v3 != '*') + { + return 1; + } + v3 = a2->peek_2(); + if (v3 != '/') + { + return 1; + } + a2->next(); + return 0; + } } \ No newline at end of file diff --git a/src/night/str/str.cpp b/src/night/str/str.cpp index 79b2fed..e52c28c 100644 --- a/src/night/str/str.cpp +++ b/src/night/str/str.cpp @@ -1,16 +1,58 @@ #include "../../include/night.h" +#include "../../include/wxa.h" +#include "../../include/wxml.h" + namespace night { namespace str { - void get_token(std::string const&, int) + std::string get_token(std::string const& a2, int a3) { - + std::string result; + char v3; + while (a3 < a2.length()) + { + v3 = a2[a3]; + if ((v3 & 0xdf) - 65 > 0x19u && v3 != '_' && v3 - '0' > 9u) + { + break; + } + ++a3; + result.push_back(v3); + } + return result; + } - bool path_combine(std::string const&, std::string const&, std::string&) - { + /** + * todo... + */ + bool path_combine(std::string const& a1, std::string const& a2, std::string& a3) + { + std::string v11; + MMBizWxaAppComm::PathCombine(a1, a2, v11); + if (v11.length() > 3) + { + std::string v14 = v11.substr(v11.length() - 3); + int code = v14 == ".wxs"; + if (code) + { + code = 2; + } + else + { + std::string v3 = WXML::Rewrite::ToStringCode(v11); + if (v3 == "") + { + + } + else + { + + } + } + } } } // namespace str } // namespace night diff --git a/test/wcc.disassembly.cpp b/test/wcc.disassembly.cpp index ce97d19..d9c36e4 100644 --- a/test/wcc.disassembly.cpp +++ b/test/wcc.disassembly.cpp @@ -15901,26 +15901,33 @@ _DWORD *__thiscall night::NSGod::gen_son(void *this, int a2) v6[0] = (int)v3; std::string::_M_assign((int)v3, a2); v4 = operator new(0xF8u); - *v4 = v4 + 2; - v4[6] = v4 + 8; - v4[15] = v4 + 17; - v4[21] = v4 + 23; - v4[27] = v4 + 29; - v4[33] = v4 + 35; - v4[39] = v4 + 41; + *v4 = v4 + 2; // std::string offset_0 v4[1] = 0; - *((_BYTE *)v4 + 8) = 0; + + v4[6] = v4 + 8; // std::string offset_24 v4[7] = 0; - *((_BYTE *)v4 + 32) = 0; + + v4[15] = v4 + 17; // std::string offset_60 v4[16] = 0; - *((_BYTE *)v4 + 68) = 0; + + v4[21] = v4 + 23; // std::string offset_84 v4[22] = 0; - *((_BYTE *)v4 + 92) = 0; + + v4[27] = v4 + 29; // std::string offset_108 v4[28] = 0; - *((_BYTE *)v4 + 116) = 0; + + v4[33] = v4 + 35; // std::string offset_132 v4[34] = 0; - *((_BYTE *)v4 + 140) = 0; + + v4[39] = v4 + 41; // std::string offset_156 v4[40] = 0; + + *((_BYTE *)v4 + 8) = 0; + *((_BYTE *)v4 + 32) = 0; + *((_BYTE *)v4 + 68) = 0; + *((_BYTE *)v4 + 92) = 0; + *((_BYTE *)v4 + 116) = 0; + *((_BYTE *)v4 + 140) = 0; *((_BYTE *)v4 + 164) = 0; v4[13] = 0; v4[12] = 0; @@ -15962,16 +15969,16 @@ struct _Unwind_Exception *__thiscall night::NSToken::read_string(night::NSStream void *v12[8]; // [esp+78h] [ebp-20h] BYREF night::NSStream::next(v12, this[1]); - v11 = 0; - v10[0] = &v11; + v10[0] = &v11; // std::string v10[1] = 0; + v11 = 0; for ( i = 0; ; i = v4 ) { v4 = night::NSStream::eof(this[1]); if ( v4 ) break; night::NSStream::next(v9, this[1]); - if ( LOBYTE(v9[0]) == 10 ) + if ( LOBYTE(v9[0]) == '\n'/*10*/ ) { if ( !i ) { @@ -15984,7 +15991,7 @@ struct _Unwind_Exception *__thiscall night::NSToken::read_string(night::NSStream { if ( !i ) { - if ( LOBYTE(v9[0]) == 92 ) + if ( LOBYTE(v9[0]) == '\\'/*92*/ ) { v4 = 1; std::string::push_back(v10, 92); @@ -16222,7 +16229,7 @@ unsigned __int8 **__fastcall night::NSToken::read_next(int a1) { night::NSStream::peek(v13, *(night::NSStream **)(a1 + 4)); v8 = v13[0]; - if ( LOBYTE(v13[0]) == 34 || LOBYTE(v13[0]) == 39 ) + if ( LOBYTE(v13[0]) == '"'/*34*/ || LOBYTE(v13[0]) == '\''/*39*/ ) { string = night::NSToken::read_string((night::NSStream **)a1, v13[0], (int)v14); } @@ -16290,7 +16297,7 @@ unsigned __int8 **__fastcall night::NSToken::read_next(int a1) } v7 = (unsigned __int8 **)string; } -LABEL_19: + LABEL_19: std::string::_M_dispose(v14); return v7; } @@ -18680,7 +18687,7 @@ unsigned __int8 **__fastcall night::NSASTParse::ast_require(int *a1) v4 = v22; v22[57] = (unsigned __int8 *)v17; std::string::operator=((unsigned int *)v4 + 27, (char *)&byte_551F04); - + v5 = night::NSToken::peek(a1[7]); if ( !v5 ) return v22; @@ -20605,17 +20612,17 @@ int __cdecl night::compile_ns(int a1, int a2, int a3, int a4, unsigned int *a5, std::string::basic_string((char *)v29, a1); night::NSASTParse::NSASTParse((int)v39, (int)v29, (int)v27, (int)v17); std::string::_M_dispose(v29); - v29[1] = 0; // v29.offset_4 v29[0] = &v30; // v29.offset_0 std::string缓冲区 - v31 = v39; // v29.offset_12 - v19[0] = &v20; + v29[1] = 0; // v29.offset_4 v30 = 0; // v29.offset_8 + v31 = v39; // v29.offset_24 = v39 + v32 = 0; // v29.offset_16 + v33 = 0; // v29.offset_20 v34 = 0; // v29.offset_24 v35 = 0; // v29.offset_28 v36 = 0; // v29.offset_32 - v32 = 0; // v29.offset_16 - v33 = 0; // v29.offset_20 v37 = 1; // v29.offset_36 + v19[0] = &v20; v19[1] = 0; v20 = 0; memset(v18, 0, sizeof(v18)); @@ -21645,7 +21652,7 @@ int __cdecl night::str::path_combine(_DWORD *a1, _DWORD *a2, int a3) int v17[5]; // [esp+90h] [ebp-18h] BYREF v12 = 0; - v11 = &v13; + v11 = &v13; // std::string 00(v11) 00 00 00, 00(v12) 00 00 00, 00(v13) 00 00 00 v13 = 0; lpuexcpt = MMBizWxaAppComm::PathCombine(a1, a2, (unsigned int *)&v11); if ( !lpuexcpt ) @@ -21710,7 +21717,7 @@ int __cdecl night::str::get_token(int a1, _DWORD *a2, unsigned int a3) { char v3; // al - *(_DWORD *)(a1 + 4) = 0; + *(_DWORD *)(a1 + 4) = 0; // std::string *(_DWORD *)a1 = a1 + 8; *(_BYTE *)(a1 + 8) = 0; while ( a3 < a2[1] ) @@ -53938,10 +53945,10 @@ char __cdecl night::NSToken::tk_is_comment2(night::NSToken *this, night::NSStrea int v5[4]; // [esp+34h] [ebp-14h] BYREF night::NSStream::peek(v3, a2); - if ( LOBYTE(v3[0]) != 42 ) + if ( LOBYTE(v3[0]) != '*'/*42*/ ) return 1; night::NSStream::peek_2(v4, a2); - if ( LOBYTE(v4[0]) != 47 ) + if ( LOBYTE(v4[0]) != '/'/*47*/ ) return 1; night::NSStream::next(v5, a2); return 0;