Пример #1
0
void TransmitExpression(DataType *arr)
{
	SymbolList();
	Stack p;
	DataType x = 0;
	CreatSatck(&p);
	int i = 0;
	int j = 0;
	while (arr[i] != '\0')
	{
		if (JudgeType(arr[i]))                 //读取的是数字
		{
			data[j++] = arr[i];                 //数字直接保存在data里面
			if (JudgeType(arr[i + 1]) != 1)
				data[j++] = ' ';                 //空格隔开
			i++;
		}
		else
		{
			if (p.low == p.top)                //栈是空栈,则直接压栈
			{
				push(&p,arr[i]);
				i++;
			}
			else
			{
				switch (check(&p, arr[i]))     
				{
				case '>':                        //栈顶符号的优先级高,退栈
					if(pop(&p, &x))
					{
						data[j++] = x;
						data[j++] = ' ';         //以空格隔开
					}
					break;
				case '<':                        //读取的优先级高,直接压栈
					push(&p,arr[i]);
					i++;
					break;
				case '=':
					pop(&p, &x);
					i++;
					break;
				}
			}
		}
	}
	while (pop(&p, &x))                                     //将剩下的符号全部退栈
	{
		data[j++] = ' ';
		data[j++] =x;
	}
	printf("%s\n", data);
	free(p.low);
}
Пример #2
0
//do action to the node.
void ONConstant::Action(Node *node)
{
	if ( !JudgeType(node) ) {
		return;
	}

	// do not obfuscate constant char 'x'
	if ( node->tokenString[0] == '\'' && node->tokenString.length() != 3 ) {
		return ;
	}

	// get Ture value. If fail do not obfusc.
	double trueValue;
	if ( !getConstantValue(node->tokenString,&trueValue) ) {
		return ;
	}

	// do Obfuscate To Node.
	beforeObfuscate = node->tokenString;
	afterObfuscated = NumberExpGenerator::get().Generate(trueValue); 

	// set value to the node.
	node->obfuscatedTokenString = afterObfuscated;
	node->isObfuscated = true;
	
	// will save the changes.
	recordTable->AddRecord(beforeObfuscate,afterObfuscated,
		node->first_line,node->first_column,
		node->last_line,node->last_column);
}
Пример #3
0
// main function. Obufuscator will call this function
void ONWhile::Action(Node *node)
{
	if ( !JudgeType(node) ) {
		return;
	}
// before Obfuscated
/* 
	WHILE '(' expression ')' 
		statement
*/
// after Obfuscated
/*
	l_continue:
		if (!(expression))
			goto l_break;
		statement;
		goto l_continue;
	l_break:;
*/
	string l_continue = GenerateId();
	string l_break = GenerateId();

	Node *expression = node->getChild(2);
	Node *statement = node->getChild(4);

	stringstream ss;
	ss << l_continue << ":";
	ss << "if(!(" << expression->ToSourceCode(isRemoveTypeset) << "))";
	ss << "goto " << l_break << ";";
	ss << statement->ToSourceCode(isRemoveTypeset) ;
	ss << "goto " << l_continue << ";";
	ss << l_break << ":;";

	string code = ss.str();

	node->isObfuscated = true;
	node->obfuscatedTokenString = code;
}
Пример #4
0
int EvaluateExpression()
{
	StackFigure p;
	int sum = 0;
	CreatSatckFigure(&p);
	int i = 0;
	int a = 0;
	int b = 0;
	while (data[i] != '\0')                    //读取后缀表达式数组中的符号 
	{
		switch (JudgeType(data[i]))
		{
		case 0:                                 //读取的是符号
			pop_figure(&p, &b);                 //将数字栈上面两个数字退栈
			pop_figure(&p, &a);
			sum = opreation(a,data[i],b);       //将这两个数字运算,并将结果返回
			push_figure(&p, sum);               //将结果入栈
			sum = 0;
			i++;
			break;
		case 1:
			while (data[i] != ' ')                 //将连续的数字全部读取,并转化为相应的整数
			{
				sum = sum * 10 + data[i]-'0';
				i++;
			}
			push_figure(&p,sum);                 //将运算结果压栈
			sum= 0;
			break;
		default:
			i++;
			break;
		}
	}
	pop_figure(&p, &sum);
	return sum;                                   //将数字栈剩下的元素返回
	free(p.low);
}
Пример #5
0
void ONString::Action(Node *node)
{
	if ( !JudgeType(node) ) {
		return;
	}
	
	if ( node->tokenString.length() < 2 ) {
		cerr << "error token string_literal length smaller than 2" << endl;
		return ;
	}

	// convert to hex style
	beforeObfuscate = node->tokenString;
	afterObfuscated = Convert2HexStyle(node->tokenString);

	// set obfuscated
	node->isObfuscated = true;
	node->obfuscatedTokenString = afterObfuscated;
	
	//save the changes.
	recordTable->AddRecord(beforeObfuscate, afterObfuscated,
		node->first_line, node->first_column,
		node->last_line, node->last_column);
}
Пример #6
0
/*
如:
    CREATE TABLE student(
        name char(20),
        id int,
        class char(10),
    );
*/
bool userDatabase::CreateTable(){
    kTable newTable;
    int Size = mySql.sqlWord.size();
    if(Size < 3)
        return false;
    newTable.name = mySql.sqlWord[2];
    int i = 3;
    string name;
    int type,unit,iskey;
    // if(i < Size)
    for(; i < Size; i++){
        type = -1;
        unit = 0;
        iskey = 0;
        //提取姓名
        name = mySql.sqlWord[i];
        i ++;
        //提取种类
        if(canRead(i))
            type = JudgeType(i);
        if(type == -1) return false;
        i++;
        //判断单位
        if(canRead(i) && mySql.sqlWord[i] != ","){
            if(type == 2){
                unit = JudgeUnit(i);
                i++;
            }
            if(canRead(i) && mySql.sqlWord[i] != ","){
                iskey = JudgeKey(i);
            }
        }
        if(!newTable.addColumn(name,type,unit,iskey)){
            cout << "[Error] The table have the same column!" << endl;
            return false;
        }
        //判断主键
    }
    Size = newTable.columnName.size();
    if(FindTable(newTable.name) != -1){
        cout << "[Error] Table is existing!" << endl;
        return false;
    }
    if((int)newTable.columnName.size() == 0){
        cout << "[Error] Can't create a empty table!" << endl;
        return false;
    }
    //--------------------------------------------------------------------
    cout << "[OK] Creating tables  success." << endl;
    kLine::MakeLine(60);
    cout << "Table's name is" << " [" << newTable.name << "]" << endl;
    cout << setiosflags(ios::left);
    cout << setw(15)  << "ColumnName";
    cout << setw(10)  << "type";
    cout << setw(10)  << "unit";
    cout << setw(15)  << "key" << endl;
    for(int i = 0; i < Size; i++){
        //列名字
        cout << setw(15)  << newTable.columnName[i];
        //列种类
        if(newTable.columnType[i] == 1)
            cout << setw(10) << "int";
        if(newTable.columnType[i] == 2)
            cout << setw(10) << "char";
        //
        cout << setw(10) << newTable.columnUnit[i];
        if(newTable.isKey[i] & (1 << 0))
            cout << setw(15) << "[PRIMARY KEY] ";
        if(newTable.isKey[i] & (1 << 1))
            cout << setw(8) << "[UNIQUE] ";
        if(newTable.isKey[i] & (1 << 2))
            cout << setw(10) << "[NOT NULL]";
        cout << endl;
    }
    kLine::MakeLine(60);
    myTable.push_back(newTable);
    return true;
};