aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2020-03-09 20:17:26 +0000
committerbloodstalker <thabogre@gmail.com>2020-03-09 20:17:26 +0000
commit71b69bce18bae3863a8033d0d5228fc3dca203ab (patch)
tree9e6c8986d6a3879d18fce212c7eeb83721e59dc9
parentreadme update [ci skip] (diff)
downloadmutator-71b69bce18bae3863a8033d0d5228fc3dca203ab.tar.gz
mutator-71b69bce18bae3863a8033d0d5228fc3dca203ab.zip
mostly bug fixes for the misra-c rule checker
-rw-r--r--.travis.yml6
-rw-r--r--README.md3
-rw-r--r--bruiser/lua-scripts/libwasm32.lua3
-rw-r--r--bruiser/lua-scripts/wasmtest.lua1
m---------cgrep0
-rw-r--r--m0/mutator-lvl0.cpp155
-rwxr-xr-xm0/run.sh2
7 files changed, 83 insertions, 87 deletions
diff --git a/.travis.yml b/.travis.yml
index 2574847..769ba74 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -131,9 +131,9 @@ matrix:
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update -y
- sudo apt-get install libstdc++-7-dev -y
- - wget https://apt.llvm.org/llvm.sh
- - chmod +x llvm.sh
- - sudo ./llvm.sh 10
+ - sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
+ - sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main"
+ - sudo apt-get update
- sudo apt-get install llvm-10-dev libclang-common-10-dev libclang-10-dev -y
- sudo apt-get install libffi-dev -y
- sudo apt-get install bear -y
diff --git a/README.md b/README.md
index d67342c..3f9756b 100644
--- a/README.md
+++ b/README.md
@@ -61,13 +61,16 @@ At its core, bruiser is a Lua REPL:
* Through bruiser's Xobj feature, you can pull in functions from object code, run them and get the result back.<br/>
* Through the ASMRewriter functionality you can manipulate the machine code and push it back in the object. For more detail you can look at the wiki or check out bruiser's README.md.<br/>
* Luarocks: You can use your Luarocks modules/libraries in bruiser too. Just make sure `luarocks` is in your path and bruiser will take care of the rest.<br/>
+You can read more about buiser [here](./bruiser/README.md)
### cgrep
cgrep is grep for c/c++ source files. simple as that.<br/>
cgrep is added here as a submodule for more exposure. You can find the main repo [here](https://github.com/bloodstalker/cgrep).<br/>
+You can read more about cgrep [here](./cgrep/README.md)
### obfuscator
obfuscator is a C/C++ source code obfuscator.<br/>
+You can read more about obfuscator [here](./obfuscator/README.md)
### delf
`delf` is a custom ELF dump script developed for bruiser. bruiser uses it to interact with ELF files.<br/>
diff --git a/bruiser/lua-scripts/libwasm32.lua b/bruiser/lua-scripts/libwasm32.lua
index 0f7ad11..9fafa18 100644
--- a/bruiser/lua-scripts/libwasm32.lua
+++ b/bruiser/lua-scripts/libwasm32.lua
@@ -39,8 +39,9 @@ function libwasm.dump_import_section(a)
if v:kind() == 0 then
print()
io.write("kind:"..tostring(v:type()).."\n")
+ --FIXME
elseif v:kind() == 1 then
- io.write("element_type:"..v:type():element_type().."\n")
+ --io.write("element_type:"..v:type():element_type().."\n")
--io.write("rsz:"..v:type():resizable_limit().."\t")
--io.write("flags:"..v:type():resizable_limit():flags().."\t")
--io.write("init:"..v:type():resizable_limit():init().."\t")
diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua
index 0c2e04f..5360207 100644
--- a/bruiser/lua-scripts/wasmtest.lua
+++ b/bruiser/lua-scripts/wasmtest.lua
@@ -39,6 +39,7 @@ function libwasm.dump_import_section(a)
if v:kind() == 0 then
print()
io.write("kind:"..tostring(v:type()).."\n")
+ --FIXME
elseif v:kind() == 1 then
io.write("element_type:"..v:type():element_type().."\n")
--io.write("rsz:"..v:type():resizable_limit().."\t")
diff --git a/cgrep b/cgrep
-Subproject cce8d6a9d7a05dd13a5b7295492316a91ee62a3
+Subproject fba22de6a97102158bf41f82b17826cca649a89
diff --git a/m0/mutator-lvl0.cpp b/m0/mutator-lvl0.cpp
index 10cd06a..12f6598 100644
--- a/m0/mutator-lvl0.cpp
+++ b/m0/mutator-lvl0.cpp
@@ -1829,7 +1829,8 @@ public:
MCExpr128 (Rewriter &Rewrite) : Rewrite(Rewrite) {}
virtual void run(const MatchFinder::MatchResult &MR) {
- if (MR.Nodes.getNodeAs<clang::Expr>("mcexpr128lhs") != nullptr && MR.Nodes.getNodeAs<clang::Expr>("mcexpr128rhs") != nullptr) {
+ if ((nullptr != MR.Nodes.getNodeAs<clang::Expr>("mcexpr128lhs"))
+ && (nullptr != MR.Nodes.getNodeAs<clang::Expr>("mcexpr128rhs"))) {
const Expr* RHS = MR.Nodes.getNodeAs<clang::Expr>("mcexpr128rhs");
const Expr* LHS = MR.Nodes.getNodeAs<clang::Expr>("mcexpr128lhs");
@@ -1853,6 +1854,7 @@ public:
uint64_t LHSSize = ASTC->getTypeSize(CanonType);
llvm::APSInt Result;
+ SourceLocation *Loc;
if (RHS->isIntegerConstantExpr(Result, *ASTC, nullptr, true)) {
if ((Result >= (LHSSize - 1U)) || (Result <= 0)) {
@@ -4140,15 +4142,12 @@ private:
};
/**********************************************************************************************************************/
/*@DEVI-ASTContext doesn not have all the comments in a source file. i dunno why.*/
-class MCLangX23 : public MatchFinder::MatchCallback
-{
+class MCLangX23 : public MatchFinder::MatchCallback {
public:
MCLangX23 (Rewriter &Rewrite) : Rewrite(Rewrite) {}
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::Expr>("mclangx23") != nullptr)
- {
+ virtual void run(const MatchFinder::MatchResult &MR) {
+ if (MR.Nodes.getNodeAs<clang::Expr>("mclangx23") != nullptr) {
ASTContext *const ASTC = MR.Context;
const SourceManager &SM = ASTC->getSourceManager();
@@ -4156,7 +4155,8 @@ public:
RawCommentList RCL = ASTC->Comments;
#if __clang_major__ >= 10
- auto RawComments = RCL.getCommentsInFile(SM.getMainFileID());
+ //auto RawComments = RCL.getCommentsInFile(SM.getMainFileID());
+ const std::map<unsigned, RawComment*> *RawComments= RCL.getCommentsInFile(SM.getMainFileID());
#elif __clang_major__ < 10
ArrayRef<RawComment*> RawComments = RCL.getComments();
#endif
@@ -4169,67 +4169,60 @@ public:
unsigned MatchCounter = 0U;
+ if (nullptr != RawComments) {
#if __clang_major__ >= 10
- for (auto &iter : *RawComments)
+ for (auto iter : *RawComments)
#elif __clang_major__ < 10
for (auto &iter : RawComments)
#endif
- {
+ {
#if __clang_major__ >= 10
- RawText = iter.second->getRawText(SM);
+ RawText = iter.second->getRawText(SM);
#elif __clang_major__ < 10
- RawText = iter->getRawText(SM);
+ RawText = iter->getRawText(SM);
#endif
#if __clang_major__ >= 10
- SourceLocation RCSL = iter.second->DEVI_GETLOCSTART();
+ SourceLocation RCSL = iter.second->DEVI_GETLOCSTART();
#elif __clang_major__ < 10
- SourceLocation RCSL = iter->DEVI_GETLOCSTART();
+ SourceLocation RCSL = iter->DEVI_GETLOCSTART();
#endif
- CheckSLValidity(RCSL);
- RCSL = Devi::SourceLocationHasMacro(RCSL, Rewrite, "start");
+ CheckSLValidity(RCSL);
+ RCSL = Devi::SourceLocationHasMacro(RCSL, Rewrite, "start");
- while (true)
- {
- matchLoc = RawText.find("/*", currentLoc);
+ while (true) {
+ matchLoc = RawText.find("/*", currentLoc);
- if (matchLoc != std::string::npos)
- {
- currentLoc = matchLoc + 1U;
+ if (matchLoc != std::string::npos) {
+ currentLoc = matchLoc + 1U;
- MatchCounter++;
- }
- else
- {
- break;
+ MatchCounter++;
+ } else {
+ break;
+ }
}
- }
- currentLoc = 1U;
+ currentLoc = 1U;
- if (!once)
- {
- if (MatchCounter >= 1U)
- {
- if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, RCSL))
- {
- /*intentionally left blank*/
- }
- else
- {
- if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, RCSL))
+ if (!once) {
+ if (MatchCounter >= 1U) {
+ if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, RCSL))
{
- std::cout << "2.3:" << "character sequence \"/*\" used inside the comment:";
- std::cout << RCSL.printToString(*MR.SourceManager) << ":" << "\n";
+ /*intentionally left blank*/
+ } else {
+ if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, RCSL)) {
+ std::cout << "2.3:" << "character sequence \"/*\" used inside the comment:";
+ std::cout << RCSL.printToString(*MR.SourceManager) << ":" << "\n";
- XMLDocOut.XMLAddNode(MR.Context, RCSL, "2.3", "character sequence \"/*\" used inside the comment : ");
- JSONDocOUT.JSONAddElement(MR.Context, RCSL, "2.3", "character sequence \"/*\" used inside the comment : ");
+ XMLDocOut.XMLAddNode(MR.Context, RCSL, "2.3", "character sequence \"/*\" used inside the comment : ");
+ JSONDocOUT.JSONAddElement(MR.Context, RCSL, "2.3", "character sequence \"/*\" used inside the comment : ");
+ }
}
}
}
- }
- MatchCounter = 0U;
+ MatchCounter = 0U;
+ }
}
once = true;
@@ -4244,23 +4237,20 @@ private:
/**********************************************************************************************************************/
/*@DEVI-changes done to the pointee through unaryOperators ++ and -- will not be tagged by this class.
see implementation notes for the explanation.*/
-class MCFunction167 : public MatchFinder::MatchCallback
-{
+class MCFunction167 : public MatchFinder::MatchCallback {
public:
MCFunction167 (Rewriter &Rewrite) : Rewrite(Rewrite) {}
virtual void run(const MatchFinder::MatchResult &MR)
{
- if (MR.Nodes.getNodeAs<clang::ParmVarDecl>("mcfunction167") != nullptr)
- {
+ if (MR.Nodes.getNodeAs<clang::ParmVarDecl>("mcfunction167") != nullptr) {
const ParmVarDecl* PVD = MR.Nodes.getNodeAs<clang::ParmVarDecl>("mcfunction167");
SourceLocation SL = PVD->DEVI_GETLOCSTART();
CheckSLValidity(SL);
SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start");
- if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
- {
+ if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) {
return void();
}
@@ -4268,18 +4258,12 @@ public:
ASTContext *const ASTC [[maybe_unused]] = MR.Context;
- if (!QT.isConstQualified())
- {
- if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
- {
+ if (!QT.isConstQualified()) {
+ if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) {
/*intentionally left blank*/
- }
- else
- {
- if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL))
- {
- if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL))
- {
+ } else {
+ if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL)) {
+ if (Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL)) {
std::cout << "16.7:" << "pointerType ParmVarDecl is not used to change the contents of the object it points to but is not declared as const:";
std::cout << SL.printToString(*MR.SourceManager) << ":" << "\n";
@@ -4516,25 +4500,24 @@ public:
clang::UnaryOperator::Opcode UnoOpKind = UO->getOpcode();
const Expr* UnoSubEXP = UO->getSubExpr();
#if __clang_major__ >= 8
- clang::Expr::EvalResult UnoResult;
+ clang::Expr::EvalResult *UnoResult;
#elif __clang_major__ < 8
- llvm::APSInt UnoResult;
+ llvm::APSInt *UnoResult;
UnoFinal = UnoResult.getExtValue();
#endif
- if (UnoSubEXP->EvaluateAsInt(UnoResult, *ASTC)) {
+ if (UnoSubEXP->EvaluateAsInt(*UnoResult, *ASTC)) {
if (UnoOpKind == UO_PostInc || UnoOpKind == UO_PreInc) {
- UnoFinal++;
+ (UnoFinal)++;
} else if (UnoOpKind == UO_PostDec || UnoOpKind == UO_PreDec) {
- UnoFinal--;
+ (UnoFinal)--;
} else {
/*intentionally left blank. we cant get anything else. were only matching for these two unaryoperators.*/
}
}
}
- if (MR.Nodes.getNodeAs<clang::BinaryOperator>("mcexpr1211dous") != nullptr)
- {
+ if (MR.Nodes.getNodeAs<clang::BinaryOperator>("mcexpr1211dous") != nullptr) {
MatchedDous = true;
const BinaryOperator* BO = MR.Nodes.getNodeAs<clang::BinaryOperator>("mcexpr1211dous");
@@ -4552,8 +4535,8 @@ public:
llvm::APSInt DousRHSAPS;
#endif
- if (DousLHS->EvaluateAsInt(DousLHSAPS, *ASTC) && DousRHS->EvaluateAsInt(DousRHSAPS, *ASTC))
- {
+ if ((DousLHS->EvaluateAsInt(DousLHSAPS, *ASTC))
+ && (DousRHS->EvaluateAsInt(DousRHSAPS, *ASTC))) {
#if __clang_major__ >= 8
int64_t DousLHSInt64 = DousLHSAPS.Val.getInt().getExtValue();
int64_t DousRHSInt64 = DousRHSAPS.Val.getInt().getExtValue();
@@ -4582,20 +4565,28 @@ public:
}
}
+ bool EvaledAsInt = false;
+ int64_t IntExprValue;
#if __clang_major__ >= 8
- clang::Expr::EvalResult OverflowCondidate;
- EXP->EvaluateAsInt(OverflowCondidate, *ASTC);
- int64_t IntExprValue = OverflowCondidate.Val.getInt().getExtValue();
+ clang::Expr::EvalResult OverflowCandidate;
+ if (true == EXP->EvaluateAsInt(OverflowCandidate, *ASTC)) {
+ IntExprValue = OverflowCandidate.Val.getInt().getExtValue();
+ EvaledAsInt = true;
+ }
#elif __clang_major__ < 8
- llvm::APSInt OverflowCondidate;
- EXP->EvaluateAsInt(OverflowCondidate, *ASTC);
- int64_t IntExprValue = OverflowCondidate.getExtValue();
+ llvm::APSInt OverflowCandidate;
+ if (EXP->EvaluateAsInt(OverflowCandidate, *ASTC)) {
+ IntExprValue = OverflowCandidate.getExtValue();
+ EvaledAsInt = true;
+ }
#endif
- if ((MatchedDous && (DousFinal != IntExprValue)) || (MatchedUno && (UnoFinal != IntExprValue))) {
- std::cout << "12.11" << ":" << "Constant Unsinged Expr evaluation resuslts in an overflow:" << SL.printToString(*MR.SourceManager) << ":" << IntExprValue << " " << DousFinal << " " << ":" << targetExpr << "\n";
- XMLDocOut.XMLAddNode(MR.Context, SL, "12.11", "Constant Unsinged Expr evaluation resuslts in an overflow:");
- JSONDocOUT.JSONAddElement(MR.Context, SL, "12.11", "Constant Unsinged Expr evaluation resuslts in an overflow:");
+ if (true == EvaledAsInt) {
+ if ((MatchedDous && (DousFinal != IntExprValue)) || (MatchedUno && (UnoFinal != IntExprValue))) {
+ std::cout << "12.11" << ":" << "Constant Unsinged Expr evaluation resuslts in an overflow:" << SL.printToString(*MR.SourceManager) << ":" << IntExprValue << " " << DousFinal << " " << ":" << targetExpr << "\n";
+ XMLDocOut.XMLAddNode(MR.Context, SL, "12.11", "Constant Unsinged Expr evaluation resuslts in an overflow:");
+ JSONDocOUT.JSONAddElement(MR.Context, SL, "12.11", "Constant Unsinged Expr evaluation resuslts in an overflow:");
+ }
}
}
}
diff --git a/m0/run.sh b/m0/run.sh
index 9f6b635..b481217 100755
--- a/m0/run.sh
+++ b/m0/run.sh
@@ -1 +1 @@
-./mutator-lvl0 --jsonout ./report.json --xmlout ./report.xml --mutagenout ./mutagen.xml -MCEA -MCD="5.1 5.2 5.3 5.4 5.5 5.6 5.7" -SysHeader=false -MainOnly=true -MCV=C2 -mutagen ../test/testFuncs1.c ../test/testFuncs2.c ../test/testFuncs3.c ../test/testFuncs3.h ../test/testFuncs2.h ../test/testFuncs1.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7/include -Wall > ./misra-log
+./mutator-lvl0 --jsonout ./report.json --xmlout ./report.xml --mutagenout ./mutagen.xml -MCEA -MCD=" 5.1 5.2 5.3 5.4 5.5 5.6 5.7 " -SysHeader=false -MainOnly=true -MCV=C2 -mutagen ../test/testFuncs1.c ../test/testFuncs2.c ../test/testFuncs3.c ../test/testFuncs3.h ../test/testFuncs2.h ../test/testFuncs1.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/9/include -Wall > ./misra-log