aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-04-13 19:01:38 +0000
committerbloodstalker <thabogre@gmail.com>2017-04-13 19:01:38 +0000
commit11d22f7d8b9ae021c234b581adcbc273ea8a1208 (patch)
tree51235666b35f4efcf522a5f163c9e4f19245d097 /bruiser
parentfixed a broken link (diff)
downloadmutator-11d22f7d8b9ae021c234b581adcbc273ea8a1208.tar.gz
mutator-11d22f7d8b9ae021c234b581adcbc273ea8a1208.zip
added some more experimental stuff. right now bruiser can only hijack the main.
Diffstat (limited to 'bruiser')
-rw-r--r--bruiser/bruiser.cpp99
1 files changed, 84 insertions, 15 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 4371e25..439605b 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -98,7 +98,7 @@ class AbstractMatcherHandler : public virtual MatchFinder::MatchCallback
class MatcherHandlerLVL0 : public AbstractMatcherHandler
{
public:
- MatcherHandlerLVL0 (Rewriter &Rewrite) : AbstractMatcherHandler(Rewrite) {}
+ explicit MatcherHandlerLVL0 (Rewriter &Rewrite) : AbstractMatcherHandler(Rewrite) {}
virtual void run(const MatchFinder::MatchResult &MR) override
{
@@ -111,21 +111,45 @@ class MatcherHandlerLVL0 : public AbstractMatcherHandler
class NameFinder
{
public:
- NameFinder (Rewriter &Rewrite) : Rewrite(Rewrite) {}
+ NameFinder () {}
- virtual void runDeclRefExprMatcher(const llvm::StringRef __sr)
- {
- //Matcher.addMatcher();
- }
-
- virtual void runDeclMatcher(const llvm::StringRef __sr)
- {
-
- }
+ class runDeclRefExprMatcher
+ {
+ public:
+ runDeclRefExprMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {}
+
+ virtual void runMatcher(const StringRef __sr, ASTContext &__ctx)
+ {
+ Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("declrefexpbyname"), &LVL0Proto);
+ Matcher.matchAST(__ctx);
+ }
+
+ private:
+ MatchFinder Matcher;
+ MatcherHandlerLVL0 LVL0Proto;
+ Rewriter __rwrt;
+ StringRef __sr;
+ };
+
+ class runNamedDeclMatcher
+ {
+ public:
+ runNamedDeclMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {}
+
+ virtual void runMatcher(const StringRef __sr, ASTContext &__ctx)
+ {
+ Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("nameddeclbyname"), &LVL0Proto);
+ Matcher.matchAST(__ctx);
+ }
+
+ private:
+ MatchFinder Matcher;
+ MatcherHandlerLVL0 LVL0Proto;
+ Rewriter __rwrt;
+ StringRef __sr;
+ };
private:
- Rewriter &Rewrite;
- MatchFinder Matcher;
};
/**********************************************************************************************************************/
/**********************************************************************************************************************/
@@ -151,7 +175,6 @@ class IfBreaker : public MatchFinder::MatchCallback
const clang::Type* CTP = TIProto.getTypeInfo(MR.Context);
- //Matcher.addMatcher();
}
if (MR.Nodes.getNodeAs<clang::BinaryOperator>("dous") != nullptr)
@@ -181,22 +204,68 @@ class IfBreaker : public MatchFinder::MatchCallback
MatchFinder Matcher;
};
/**********************************************************************************************************************/
+/**
+ * @brief Hijacks the main main and replaces it with bruiser's main.
+ */
+class MainWrapper : public MatchFinder::MatchCallback
+{
+public:
+ MainWrapper (Rewriter &Rewrite) : Rewrite(Rewrite) {}
+
+ virtual void run(const MatchFinder::MatchResult &MR)
+ {
+ if (MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper") != nullptr)
+ {
+ const FunctionDecl* FD = MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper");
+
+ SourceLocation SL = FD->getLocStart();
+ CheckSLValidity(SL);
+ SL = Devi::SourceLocationHasMacro(SL, Rewrite);
+
+ SourceLocation SLE = FD->getLocEnd();
+ CheckSLValidity(SLE);
+ SLE = Devi::SourceLocationHasMacro(SLE, Rewrite);
+
+ SourceRange SR(SL, SLE);
+
+ std::string MainSig = Rewrite.getRewrittenText(SR);
+
+ size_t mainbegin = MainSig.find("main");
+
+ StringRef __sr("sub_main");
+
+ Rewrite.ReplaceText(SL.getLocWithOffset(mainbegin), 4U, __sr);
+
+ Rewrite.InsertTextAfter(SLE.getLocWithOffset(1U), StringRef("\n\nint main(int argc, const char **argv)\n{\n\tsub_main(argc, argv);\n}"));
+
+ //ruiseRep << "changed main main's name.\n"
+ }
+ }
+
+ private:
+ Rewriter &Rewrite;
+};
+/**********************************************************************************************************************/
+/**********************************************************************************************************************/
/**********************************************************************************************************************/
class MyASTConsumer : public ASTConsumer {
public:
- MyASTConsumer(Rewriter &R) : HIfBreaker(R)
+ MyASTConsumer(Rewriter &R) : HIfBreaker(R), HMainWrapper(R)
{}
void HandleTranslationUnit(ASTContext &Context) override
{
Matcher.addMatcher(ifStmt(hasDescendant(expr(anyOf(unaryOperator().bind("uno"), binaryOperator().bind("dous"))))), &HIfBreaker);
+ Matcher.addMatcher(functionDecl(hasName("main")).bind("mainwrapper"), &HMainWrapper);
+
Matcher.matchAST(Context);
}
private:
IfBreaker HIfBreaker;
+ MainWrapper HMainWrapper;
MatchFinder Matcher;
Rewriter R;
};