forked from falltergeist/int2ssl
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNode.cpp
143 lines (121 loc) · 3.23 KB
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
*
* Copyright (c) 2005-2009 Anchorite (TeamX), <[email protected]>
* Copyright (c) 2014-2015 Nirran, phobos2077
* Copyright (c) 2015 alexeevdv <[email protected]>
* Distributed under the GNU GPL v3. For full terms see the file license.txt
*
*/
// C++ standard includes
#include <iostream>
#include <fstream>
// int2ssl includes
#include "Node.h"
#include "Utility.h"
// Third party includes
extern std::ifstream g_ifstream;
extern std::ofstream g_ofstream;
CNode::CNode(Type type) :
m_ulOffset(0),
m_Type(type)
{
}
CNode::CNode(const CNode& node) :
m_ulOffset(node.m_ulOffset),
m_Opcode(node.m_Opcode),
m_Type(node.m_Type)
{
m_Arguments = node.m_Arguments;
}
CNode::~CNode()
{
}
CNode& CNode::operator = (const CNode& node)
{
if (&node != this)
{
m_ulOffset = node.m_ulOffset;
m_Opcode = node.m_Opcode;
m_Type = node.m_Type;
m_Arguments = node.m_Arguments;
}
return (*this);
}
void CNode::StoreTree(int nIndent, int nIndex)
{
// Indent
if (nIndex != 0)
{
g_ofstream << " ";
for(int i = 0; i < nIndent; i++)
{
g_ofstream << " ";
}
}
switch(m_Type)
{
case TYPE_BEGIN_OF_BLOCK:
g_ofstream << "========= begin of block =========" << std::endl;
return;
case TYPE_END_OF_BLOCK:
g_ofstream << "========= end of block =========" << std::endl;
return;
default:
break;
}
// Node
std::string strOutLine;
uint16_t wOperator = m_Opcode.GetOperator();
uint32_t ulArgument = m_Opcode.GetArgument();
switch(wOperator)
{
case COpcode::O_STRINGOP:
case COpcode::O_INTOP:
g_ofstream << format("0x%04X 0x%08x ",
wOperator,
ulArgument) << std::endl;
break;
case COpcode::O_FLOATOP:
g_ofstream << format("0x%04X 0x%08X ",
wOperator,
ulArgument) << std::endl;
break;
default:
g_ofstream << format("0x%04X .......... ", wOperator) << std::endl;
break;
}
if (!m_Arguments.empty())
{
for(uint32_t i = 0; i < m_Arguments.size(); i++)
{
m_Arguments[i].StoreTree(nIndent + 1, i);
}
}
else
{
g_ofstream << std::endl;
}
}
uint32_t CNode::GetTopOffset()
{
if (m_Arguments.size() > 0)
{
return m_Arguments[0].GetTopOffset();
}
else
{
return m_ulOffset;
}
}
bool CNode::IsExpression() const
{
COpcode::COpcodeAttributes::Type type = m_Opcode.GetAttributes().m_Type;
return (type == COpcode::COpcodeAttributes::TYPE_EXPRESSION
|| type == COpcode::COpcodeAttributes::TYPE_EXPRESSIONSTATEMENT
|| m_Type == TYPE_CONDITIONAL_EXPRESSION);
}
bool CNode::IsInfix() const
{
return (m_Opcode.GetAttributes().m_Category == COpcode::COpcodeAttributes::CATEGORY_INFIX
|| m_Type == TYPE_CONDITIONAL_EXPRESSION);
}