aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/bruiser.h
blob: 4e9c2e7f357a7c8526a3e6cc7172f74b9d2cdc41 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/***************************************************Project Mutator****************************************************/
//-*-c++-*-
/*first line intentionally left blank.*/
/*the header for mutator's code breaker.*/
/*Copyright (C) 2017 Farzad Sadeghi

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/
/*code structure inspired by Eli Bendersky's tutorial on Rewriters.*/
/**********************************************************************************************************************/
/*inclusion guard*/
#ifndef BRUISER_H
#define BRUISER_H
/**********************************************************************************************************************/
/*included modules*/
/*project headers*/
#include "../tinyxml2/tinyxml2.h"
/*standard library headers*/
#include <string>
#include <fstream>
/*clang headers*/
#include "clang/AST/ASTContext.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Type.h"
#include "clang/AST/ASTTypeTraits.h"
/*llvm headers*/

/*boost*/
#include "boost/circular_buffer.hpp"
/**********************************************************************************************************************/
/*using*/
using namespace tinyxml2;
using namespace llvm;
using namespace clang;
/**********************************************************************************************************************/
namespace bruiser
{ //start of namespace bruiser
/**********************************************************************************************************************/
  const char* M0REP = "../test/misrareport.xml";
/**********************************************************************************************************************/
#define RED "\033[1;31m"
#define CYAN "\033[1;36m"
#define GREEN "\033[1;32m"
#define BLUE "\033[1;34m"
#define BLACK "\033[1;30m"
#define BROWN "\033[1;33m"
#define MAGENTA "\033[1;35m"
#define GRAY "\033[1;37m"
#define DARKGRAY "\033[1;30m"
#define YELLOW "\033[1;33m"
#define NORMAL "\033[0m"
#define CLEAR	"\033[2J"

#define LN_RED 31
#define LN_GREEN 32
#define LN_YELLOW 33
#define LN_BLUE 34
#define LN_MAGENTA 35
#define LN_CYAN 36
#define LN_WHITE 37

#define BOLD 1
#define NO_BOLD 0

#define SHELL_HISTORY_SIZE  100
#define SHELL_HISTORY_FILE "bruiser-history.txt"

#define NOT_IMPLEMENTED \
  do{\
    printf(BROWN "not implemented yet.");\
    printf(NORMAL"\n");\
  }while(0)

#define  PRINT_WITH_COLOR(X,Y) \
  do{\
    printf(X Y NORMAL);\
  }while(0)

#define  PRINT_WITH_COLOR_LB(X,Y) \
  do{\
    printf(X "%s", Y);\
    printf(NORMAL"\n");\
  }while(0)
/**********************************************************************************************************************/
/*Error Codes*/
#define M0_ERROR_CODES \
  X(BAD_M0_XML, "bad m0 xml.", 100) \
  X(CANT_OPEN_M0_XML, "could not open m0 xml.", 101) \

#define X(__x1, __x2, __x3) __x1,
  enum class M0_ERR {M0_ERROR_CODES};
#undef X
/**********************************************************************************************************************/
/*Enums*/
  /**
   * @brief Gene Kinds.
   */
  enum class DoomKind {UnidentifiedGene, 
    CStyleCastExpr, ExplicitCastExpr, ImplicitCastExpr, 
    Stmt, CompoundStmt, LoopStmt, ForStmt, WhileStmt, IfStmt, ElseStmt, DoStmt, SwitchStmt, CaseStmt,
    Decl, FunctionDecl, ClassDecl, VarDecl, RecordDecl, ArrayDecl, StructDecl, UnionDecl, VectorDecl,
    MapDecl, UnorderedMapDecl, MemberFunctionDecl, TemplateDecl, ClassTemplateDecl, ParmVarDecl
  };
/**********************************************************************************************************************/
struct help
{
  public:
    std::string name;
    std::string proto;
    std::string descr;
    std::string protoprefix;
    std::string retval;
};

help CMDHelp[] = {
  {"help", "", "display general help", "", ""},
  {"quit", "", "quit bruiser", "", ""},
  {"exit", "", "quit bruiser", "", ""},
  {"m0", "", "bruiser reads the report generated by mutator-lvl0", "", ""},
  {"hijack", "hijack main", "runs a specific matcher that replaces the main with a new main", "", ""},
  {"clear", "", "clears the terminal", "", ""},
  {"shell", "", "opens up a bash shell inside bruiser", "", ""},
  {"history", "", "prints bruiser's history", "", ""},
  {"!", "", "prints the command from history", "", ""},
  {"list", "list functions", "lists the names of all available types", "", ""}
};
/**********************************************************************************************************************/
/**
 * @brief This class handles the logging for bruiser.
 */
class BruiserReport
{
  public:
    BruiserReport ();

    ~BruiserReport();

    template <typename T>
    bool PrintToLog(T __arg);

  private:
    std::ofstream BruiserLog;
};
/**********************************************************************************************************************/
/**
 * @brief looks through types.
 */
class TypeInfo
{
  public:
    explicit TypeInfo(const clang::ast_type_traits::DynTypedNode* __dtn);

    ~TypeInfo();

    const clang::Type* getTypeInfo(clang::ASTContext* __astc);

  private:
    const clang::ast_type_traits::DynTypedNode* DTN;
};
/**********************************************************************************************************************/
class ReadM0
{
  public:
    ReadM0() 
    {
      try
      {
      XMLError eResult [[maybe_unused]] = IntermediateXMLDoc.LoadFile(M0REP);

      RootPointer = IntermediateXMLDoc.FirstChild();
      }
      catch (std::exception& e)
      {

      }
    }

    ~ReadM0() {}

    XMLError LoadXMLDoc(void)
    {
      XMLError eResult = IntermediateXMLDoc.LoadFile(M0REP);

      return eResult;
    }

    XMLError ReadFirstElement(void)
    {
      RootPointer = IntermediateXMLDoc.FirstChild();

      if (RootPointer == nullptr)
      {
        return XML_ERROR_FILE_READ_ERROR;
      }
      else
      {
        return XML_SUCCESS;
      }
    }

    XMLNode* getRootPointer(void)
    {
      return RootPointer;
    }

  private:
    void Debug(void)
    {

    }

    XMLDocument IntermediateXMLDoc;
    XMLNode* RootPointer;
};
/**********************************************************************************************************************/
class SearchM0
{
  public:
    SearchM0(XMLNode* __rptr) : RootPointer(__rptr) {}

    ~SearchM0() {};

    void Debug(void) 
    {
      if (!RootPointer->NoChildren())
      {
        const XMLElement* XMLE [[maybe_unused]] = RootPointer->FirstChildElement();

      }
    }

  private:
    XMLNode* RootPointer;
};
/**********************************************************************************************************************/
class ShellHistory
{
  public:
    ShellHistory() {}
    boost::circular_buffer<std::string> History{SHELL_HISTORY_SIZE};
};
/**********************************************************************************************************************/
class Daemonize
{
  public:
    Daemonize (std::string __exe, std::string __opts) : Exe(__exe), Opts(__opts) {}



  private:
    std::string Exe;
    std::string Opts;
};
/**********************************************************************************************************************/
class Amino
{
  public:

  private:
};
/**********************************************************************************************************************/
/**
 * @brief A container class for the bad genes
 */
class DoomedStrain
{
  public:
  DoomedStrain() {}
  ~DoomedStrain() {}


  private:
  std::vector<bruiser::Amino> Aminos;
};
/**********************************************************************************************************************/
} // end of namespace bruiser
#endif
/*last line intentionally left balnk.*/