feat: 一些方法

This commit is contained in:
msojocs 2023-08-12 21:38:54 +08:00
parent 1e0236bfcc
commit 7b37dcaabd
8 changed files with 266 additions and 32 deletions

View File

@ -49,6 +49,8 @@ add_executable(wcc
src/utils/file.cpp
)
add_executable(wcsc
src/include/bittest.h
src/utils/bittest.cpp
src/wcsc.cpp
src/wcsc/usage.cpp
src/wxa/wxa.cpp

6
src/include/bittest.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __BITTEST_H__
#define __BITTEST_H__
#include <iostream>
unsigned char bittest(std::int32_t const *a, std::int32_t b);
#endif

View File

@ -25,9 +25,12 @@ namespace WXSS
private:
/* data */
public:
int offset_0;
int offset_20;
int offset_24;
int offset_0 = 0;
std::shared_ptr<std::string> offset_4;
int offset_12 = 0;
int offset_16 = 0;
int offset_20 = 0;
int offset_24 = 0;
std::string offset_28;
Token(/* args */);
~Token();
@ -167,7 +170,13 @@ namespace WXSS
public:
Parser(/* args */);
~Parser();
int Parse(std::string const&, std::string const&, std::string&, std::string const&);
/**
*
* @param a2
* @param a3
* @param a4 errorMessage
*/
int Parse(std::string const& a2, std::string const& a3, std::string& a4, std::string const& a5);
};

9
src/utils/bittest.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "../include/bittest.h"
unsigned char bittest(std::int32_t const *a, std::int32_t b)
{
auto const bits{ reinterpret_cast<unsigned char const*>(a) };
auto const value{ bits[b >> 3] };
auto const mask{ (unsigned char)(1 << (b & 7)) };
return (value & mask) != 0;
}

View File

@ -13,10 +13,30 @@ namespace WXSS
std::string Token::GetLiteral(void)
{
throw "not implement";
if (this->offset_0 == 1)
{
return this->offset_28;
}
std::string result = "$";
if (this->offset_0 != 8)
{
result = "UNKNOWN";
if (this->offset_4.get())
{
return *this->offset_4.get();
}
}
return result;
}
WXSS::Token& Token::operator=(WXSS::Token const&)
WXSS::Token& Token::operator=(WXSS::Token const& old)
{
throw "not implement";
this->offset_0 = old.offset_0;
this->offset_4 = old.offset_4;
this->offset_12 = old.offset_12;
this->offset_16 = old.offset_16;
this->offset_20 = old.offset_20;
this->offset_24 = old.offset_24;
this->offset_28 = old.offset_28;
return *this;
}
}

View File

@ -1,4 +1,5 @@
#include "../include/wxss.h"
#include "../include/bittest.h"
#include <cstring>
#include <sstream>
@ -306,12 +307,14 @@ namespace WXSS
{
v4 = a4;
}
std::string v35, v41;
int v47 = 0, v44 = 0;
a2.reserve(a2.size());
// GetTokens - 5
int AnotherTypeByAnySubStr = 0;
int v33 = 4194305;
// int AnotherTypeByAnySubStr = 0;
int v37 = 1;
int v41 = 1;
int v35 = 1;
int v31 = 0;
for (int sa = 0; ; sa = v31)
{
@ -329,9 +332,163 @@ namespace WXSS
{
v10 = 0;
}
int v11 = this->TT[1024 * v4 + 2 * 10];
// WXSS::TokenType AnotherTypeByAnySubStr;
// AnotherTypeByAnySubStr = this->TryGetAnotherTypeByAnySubStr(this->offset_0.data(), v47, v42, AnotherTypeByAnySubStr);
int lt = this->TT[1024 * v4 + 2 * 10];
WXSS::TokenType AnotherTypeByAnySubStr;
AnotherTypeByAnySubStr = this->TryGetAnotherTypeByAnySubStr(this->offset_0.data(), v47, v4, AnotherTypeByAnySubStr);
if (!lt)
{
lt = this->TT[1024 * v4];
if (!lt)
{
std::stringstream v66;
v66 << "no transition for " << v4 << " with input " << v44;
a3 = v66.str();
return -1;
}
}
if (lt == -1)
break;
if (lt & 0x30000 != 0)
{
int v43 = ((lt & 0x20000) == 0) + v47 - 1;
if ( !AnotherTypeByAnySubStr )
{
AnotherTypeByAnySubStr = 2;
if (!bittest(&lt, 0x12))
{
AnotherTypeByAnySubStr = 4;
if (!bittest(&lt, 0x13))
{
AnotherTypeByAnySubStr = 6;
if (!bittest(&lt, 0x16))
{
AnotherTypeByAnySubStr = 5;
if (!bittest(&lt, 0x15))
{
AnotherTypeByAnySubStr = (lt & 0x2000000) == 0 ? 1 : 7;
}
}
}
}
}
if (sa <= v43)
{
char dest[64];
int v58 = AnotherTypeByAnySubStr;
const char * v59 = nullptr;
int v61 = sa;
int v63 = v35;
int v62 = ((lt & 0x20000) == 0) + v47 - sa;
if (AnotherTypeByAnySubStr == 1)
{
strncpy(dest, &this->offset_0[sa], v62);
dest[v43 - sa + 1] = 0;
}
else
{
int v38 = ((lt & 0x20000) == 0) + v47 - 1;
if (bittest(&lt, 0x18u))
{
for (char i = this->offset_0[sa]; v43 != sa && i-10 <= 0x16u && ((0x400009u >> (i - 10)) & 1) != 0 ; i = this->offset_0[sa])
{
if (i == 10)
{
++v63;
}
sa++;
}
int v38 = ((lt & 0x20000) == 0) + v47 - 1;
for (char j = this->offset_0[v43]; sa < v38; j = this->offset_0[v38])
{
int v21 = j - 10;
if (v21 > 0x16 || ((0x400009u >> v21) & 1) == 0)
{
break;
}
--v38;
}
}
v61 = sa;
int v39 = v38 - sa + 1;
std::string str = this->offset_0.substr(sa, v39);
v59 = str.data();
}
if (v58 != 1)
{
if (!v59)
{
std::stringstream ss;
ss << "pos: " << v47 << "f739 error" << std::endl;
a3 = ss.str();
return -1;
}
if (v58 == 4)
{
int v42 = 0;
if (
!strcasecmp(v59, "@media")
|| !strcasecmp(v59, "@keyframes")
|| !strcasecmp(v59, "@-webkit-keyframes")
|| !strcasecmp(v59, "@supports")
)
{
v42 = 24;
}
const char *DIRECTIVES = "@import";
for (int k = 0; DIRECTIVES[k]; k++)
{
if (!strcasecmp(v59, DIRECTIVES + k))
{
WXSS::Token v66;
v66.offset_0 = 1;
v66.offset_12 = v61;
v66.offset_16 = v62;
v66.offset_20 = v63;
v66.offset_24 = v37;
v66.offset_28 = DIRECTIVES + k;
a2.push_back(v66);
goto LABEL_77;
}
}
}
}
{
WXSS::Token _v58;
a2.push_back(_v58);
}
LABEL_77:
sa = v43 + 1;
v37 = v41 + 1;
}
AnotherTypeByAnySubStr = 0;
}
if (bittest(&lt, 0x1Au))
{
--v47;
}
else
{
if (v44 == 10)
{
++v35;
v41 = 0;
}
++v41;
}
++v47;
int v30 = v37;
v31 = sa;
if ((lt & 0x8000000) != 0)
{
v30 = v41;
v31 = v47;
}
v37 = v30;
}
// GetTokens - 10
@ -363,4 +520,33 @@ namespace WXSS
this->offset_24 = t.offset_24;
return *this;
}
WXSS::TokenType Tokenizer::TryGetAnotherTypeByAnySubStr(char const* a1, uint a2, WXSS::Tokenizer::STATE a3, WXSS::TokenType a4)
{
if (!a4)
{
auto v4 = WXSS::Tokenizer::SCC;
int v5 = 0;
int v6 = a2 + 1;
for (int i = 0; i < 5; i++)
{
auto cur = v4[i];
if (!cur.offset_0)
{
break;
}
if (a3 == cur.offset_0)
{
auto v7 = cur.offset_4;
if (v6 >= v7 && !strncmp(cur.offset_8, a1 + v6 - v7, cur.offset_4))
{
return this->TT[(0x5206B8 - 0x005222A0) / 4 + 7 * i];
}
}
}
}
return a4;
}
}

View File

@ -88,8 +88,7 @@ namespace WXSS
}
std::string v74 = v42;
std::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree> v75(new WXSS::CSSTreeLib::CSSSyntaxTree());
// this->offset_32.
// todo...
this->offset_32[v74] = v75;
}
}
// end for
@ -157,7 +156,6 @@ namespace WXSS
}
}
// XCompiler - 5 - 5

View File

@ -9128,8 +9128,11 @@ void __thiscall WXSS::XCompiler::XCompiler(char *this, _DWORD *a2, char a3, int
}
std::string::basic_string((char *)v74, (int)v42);
std::__shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree,(__gnu_cxx::_Lock_policy)2>::__shared_ptr(&v75, &v57);
// _DWORD *Blocka
Blocka = operator new(0x30u);
// Blocka->offset_16
std::string::basic_string(Blocka + 4, v74);
// Blocka->offset_40
std::__shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree,(__gnu_cxx::_Lock_policy)2>::__shared_ptr(Blocka + 10, &v75);
insert_unique_pos = std::_Rb_tree<std::string,std::pair<std::string const,zcc::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree>>,std::_Select1st<std::pair<std::string const,zcc::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree>>>,std::less<std::string>,std::allocator<std::pair<std::string const,zcc::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree>>>>
::_M_get_insert_unique_pos(
@ -12579,6 +12582,7 @@ int __thiscall WXSS::Tokenizer::GetTokens(int *this, int a2, unsigned int **a3,
++String1a;
}
v38 = (((unsigned int)lpuexcpt & 0x20000) == 0) + v47 - 1;
// v45 -> this->offset_0
for ( j = *(_BYTE *)(v45 + v43); (int)String1a < v38; j = *(_BYTE *)(v45 + v38) )
{
v21 = j - 10;
@ -12588,14 +12592,14 @@ int __thiscall WXSS::Tokenizer::GetTokens(int *this, int a2, unsigned int **a3,
}
}
v61 = String1a;
Block = (_BYTE **)operator new(0x18u);
Block = (_BYTE **)operator new(0x18u); // std::string
v39 = v38 - (_DWORD)String1a + 1;
String1b = (unsigned __int8 *)&String1a[v45];
*Block = Block + 2;
if ( &String1b[v39] && !String1b )
std::__throw_logic_error((std::logic_error *)"basic_string::_M_construct null not valid");
v66 = v39;
if ( v39 > 0xF )
if ( v39 > 0xF ) // 大于16 新开辟一个空间
{
*Block = std::string::_M_create((unsigned int *)&v66, 0);
Block[2] = (_BYTE *)v66;
@ -12606,7 +12610,7 @@ int __thiscall WXSS::Tokenizer::GetTokens(int *this, int a2, unsigned int **a3,
(*Block)[v22] = 0;
v55 = 0;
v56 = 0;
v66 = (int)Block;
v66 = (int)Block; // std::string
v67 = 0;
v23 = (volatile signed __int32 *)operator new(0x10u);
v24 = (int)v55;
@ -12665,34 +12669,34 @@ int __thiscall WXSS::Tokenizer::GetTokens(int *this, int a2, unsigned int **a3,
if ( !__stricmp(String1d, (&WXSS::Tokenizer::DIRECTIVES)[k]) )
{
v73[0] = 0;
v67 = 0;
v67 = 0; // v66.offset_4;
v29 = (&WXSS::Tokenizer::DIRECTIVES)[k];
v68 = 0;
v66 = 1;
v69 = 0;
v70 = 0;
v71 = 0;
v72 = 0;
v68 = 0; // v66.offset_8;
v66 = 1; // v66.offset_0;
v69 = 0; // v66.offset_12;
v70 = 0; // v66.offset_16;
v71 = 0; // v66.offset_20;
v72 = 0; // v66.offset_24;
strcpy(v73, v29);
v69 = v61;
v71 = v63;
v72 = v64;
v70 = v62;
v69 = v61; // v66.offset_12;
v71 = v63; // v66.offset_20;
v72 = v64; // v66.offset_24;
v70 = v62; // v66.offset_16;
std::vector<WXSS::Token>::push_back(a2, &v66);
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count(&v68);
goto LABEL_77;
}
}
}
}
}// end if
std::vector<WXSS::Token>::push_back(a2, (int *)&v58);
LABEL_77:
String1a = (char *)(v43 + 1);
v37 = v41 + 1;
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count(&v60);
}
}// end if
AnotherTypeByAnySubStr = 0;
}
}// end if
if ( _bittest((const signed __int32 *)&lpuexcpt, 0x1Au) )
{
--v47;