diff options
author | bloodstalker <thabogre@gmail.com> | 2018-02-11 20:29:49 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-02-11 20:29:49 +0000 |
commit | 26859306a2affd060fb4ebebed7525a5d88e967c (patch) | |
tree | 7f0e83bbcf8e9ccff43814fc53649a61de00cc23 | |
parent | makefile update or they kinda do what they were supposed to do (diff) | |
download | mutator-26859306a2affd060fb4ebebed7525a5d88e967c.tar.gz mutator-26859306a2affd060fb4ebebed7525a5d88e967c.zip |
2 major bug fixed for bruiser, a lot of little improvements and bug fixed here and there
-rw-r--r-- | .travis.yml | 3 | ||||
-rwxr-xr-x | bfd/codegen.py | 3 | ||||
-rwxr-xr-x | bfd/load.py | 1 | ||||
-rw-r--r-- | bruiser/bruiser.cpp | 80 | ||||
-rw-r--r-- | bruiser/bruiserffi.c | 36 | ||||
-rw-r--r-- | bruiser/bruiserffi.h | 1 | ||||
-rw-r--r-- | bruiser/compile_commands.json | 8 | ||||
-rw-r--r-- | bruiser/lua-scripts/demo1.lua | 28 | ||||
-rw-r--r-- | bruiser/lua-scripts/smoketest.lua | 9 | ||||
-rw-r--r-- | bruiser/makefile | 2 | ||||
-rwxr-xr-x | bruiser/run.sh | 3 | ||||
-rwxr-xr-x | extra-tools/precommitTests.sh | 61 | ||||
-rw-r--r-- | macros.mk | 2 | ||||
-rw-r--r-- | makefile | 1 | ||||
-rw-r--r-- | mutator-lvl2.cpp | 94 | ||||
-rw-r--r-- | obfuscator/compile_commands.json | 2 | ||||
-rw-r--r-- | obfuscator/makefile | 4 | ||||
-rw-r--r-- | obfuscator/obfuscator.cpp | 5 | ||||
-rwxr-xr-x | obfuscator/run.sh | 7 | ||||
-rw-r--r-- | test/m0-cpp-smoke/compile_commands.json | 2 | ||||
-rw-r--r-- | test/m0-cpp-smoke/makefile | 2 |
21 files changed, 177 insertions, 177 deletions
diff --git a/.travis.yml b/.travis.yml index 1c1bd51..5daf9a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_script: - travis_retry sudo apt-get install clang-5.0 libclang-5.0-dev libclang-common-5.0-dev libllvm5.0 llvm-5.0-dev llvm-5.0 llvm-5.0-runtime libclang1-5.0-dbg libllvm5.0-dbg lldb-5.0 -y - sudo apt-get install gcc-4.9 g++-4.9 - sudo apt-get install libffi-dev -y - #- sudo apt-get install libcapstone-dev -y + - ./extra-tools/capstoneubuntu14.sh - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 - sudo apt-get install libboost-dev - git submodule init @@ -48,6 +48,7 @@ before_script: script: - make PY_CONF=python3.5-config CXX=clang-5.0 LLVM_CONF=llvm-config-5.0 BUILD_MODE=COV_NO_CLANG -j2 + - cd ./extra-tools/precommitTests.sh after_failure: - find . -maxdepth 1 -name "core*" diff --git a/bfd/codegen.py b/bfd/codegen.py index 5019261..2f102e9 100755 --- a/bfd/codegen.py +++ b/bfd/codegen.py @@ -9,6 +9,7 @@ import capstone from load import ELF def SigHandler_SIGINT(signum, frame): + print() sys.exit(0) class Argparser(object): @@ -27,7 +28,7 @@ class Call_Rewriter(object): def run(): for i in md.disasm(self.obj_code, 0x0): - print("0x%x:\t%s\t%s", %(i.address, i.mnemonic, i.op_str)) + print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str)) class Global_Rewriter(object): def __init__(self): diff --git a/bfd/load.py b/bfd/load.py index 22c304e..865fe91 100755 --- a/bfd/load.py +++ b/bfd/load.py @@ -8,6 +8,7 @@ from capstone import * from capstone.x86 import * def SigHandler_SIGINT(signum, frame): + print() sys.exit(0) class ExceptionHandler(object): diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index e75b173..053bffc 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -104,6 +104,7 @@ cl::opt<bool> CheckSystemHeader("SysHeader", cl::desc("bruiser will run through cl::opt<bool> MainFileOnly("MainOnly", cl::desc("bruiser will only report the results that reside in the main file"), cl::init(false), cl::cat(BruiserCategory), cl::ZeroOrMore); cl::opt<std::string> M0XMLPath("xmlpath", cl::desc("tells bruiser where to find the XML file containing the Mutator-LVL0 report."), cl::init(bruiser::M0REP), cl::cat(BruiserCategory), cl::ZeroOrMore); cl::opt<bool> LuaJIT("jit", cl::desc("should bruiser use luajit or not."), cl::init(true), cl::cat(BruiserCategory), cl::ZeroOrMore); +cl::opt<bool> Verbose("verbose", cl::desc("verbosity"), cl::init(false), cl::cat(BruiserCategory), cl::ZeroOrMore); cl::opt<std::string> NonCLILuaScript("lua", cl::desc("specifies a lua script for bruiser to run in non-interactive mode"), cl::init(""), cl::cat(BruiserCategory), cl::Optional); /**********************************************************************************************************************/ class LuaEngine @@ -209,16 +210,16 @@ class PyExec { if (pModule != nullptr) { pFunc = PyObject_GetAttrString(pModule, py_func_name.c_str()); if (pFunc && PyCallable_Check(pFunc)) { - std::cout << GREEN << "function is callable." << NORMAL << "\n"; + if (Verbose) std::cout << GREEN << "function is callable." << NORMAL << "\n"; pArgs = PyTuple_New(1); pValue = PyUnicode_FromString(obj_path.c_str()); PyTuple_SetItem(pArgs, 0, pValue); pArgs = nullptr; - std::cout << BLUE << "calling python function..." << NORMAL << "\n"; + if (Verbose) std::cout << BLUE << "calling python function..." << NORMAL << "\n"; pValue = PyObject_CallObject(pFunc, pArgs); //Py_DECREF(pArgs); if (pValue != nullptr) { - std::cout << GREEN << "call finished successfully." << NORMAL << "\n"; + if (Verbose) std::cout << GREEN << "call finished successfully." << NORMAL << "\n"; //printf("Result of call: %ld\n", PyLong_AsLong(pValue)); //Py_DECREF(pValue); } else { @@ -247,11 +248,11 @@ class PyExec { } int getAsCppStringVec(void) { - PRINT_WITH_COLOR_LB(BLUE, "processing return result..."); + if (Verbose) PRINT_WITH_COLOR_LB(BLUE, "processing return result..."); if (PyList_Check(pValue)) { - std::cout << GREEN << "got a python list\n" << NORMAL; + if (Verbose) std::cout << GREEN << "got a python list\n" << NORMAL; int list_length = PyList_Size(pValue); - std::cout << BLUE << "length of list: " << list_length << NORMAL <<"\n"; + if (Verbose) std::cout << BLUE << "length of list: " << list_length << NORMAL <<"\n"; for (int i = 0; i < list_length; ++i) { PyObject* pybytes = PyList_GetItem(pValue, i); PyObject* pyrepr = PyObject_Repr(pybytes); @@ -265,11 +266,11 @@ class PyExec { } int getAsCppByte(void) { - PRINT_WITH_COLOR_LB(BLUE, "processing return result..."); + if (Verbose) PRINT_WITH_COLOR_LB(BLUE, "processing return result..."); std::vector<uint8_t> tempvec; if(PyList_Check(pValue)) { int list_length = PyList_Size(pValue); - std::cout << BLUE << "length of list: " << list_length << NORMAL << "\n"; + if (Verbose) std::cout << BLUE << "length of list: " << list_length << NORMAL << "\n"; for(int i = 0; i < list_length; ++i) { PyObject* pybytes = PyList_GetItem(pValue, i); if(PyList_Check(pybytes)) { @@ -1161,7 +1162,7 @@ class LuaWrapper std::string action; if (numargs == 3) { - std::cout << CYAN << "got args." << NORMAL << "\n"; + if (Verbose) std::cout << CYAN << "got args." << NORMAL << "\n"; funcname = lua_tostring(__ls, 1); objjpath = lua_tostring(__ls, 2); action = lua_tostring(__ls, 3); @@ -1172,10 +1173,10 @@ class LuaWrapper return EXIT_FAILURE; } - std::cout << CYAN << "initing the py embed class...\n" << NORMAL; + if (Verbose) std::cout << CYAN << "initing the py embed class...\n" << NORMAL; PyExec py(filename.c_str(), funcname.c_str(), objjpath.c_str()); - std::cout << BLUE << "running load.py: " << NORMAL << "\n"; + if (Verbose) std::cout << BLUE << "running load.py: " << NORMAL << "\n"; py.run(); if (action == "code_list") { py.getAsCppByte(); @@ -1185,8 +1186,7 @@ class LuaWrapper int tableindex2 = 1; // the return type to lua is a table of tables lua_newtable(__ls); - // @devi-FIXME-probably reserving way too much stack space - if (!lua_checkstack(__ls, py.exportObjs().size() * 2)) { + if (!lua_checkstack(__ls, py.exportObjs().size())) { PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); } for (auto& iter : py.exportObjs()) { @@ -1208,8 +1208,7 @@ class LuaWrapper int tableindex = 1 ; // the return type to lua is a table lua_newtable(__ls); - // @devi-FIXME-probably reserving way too much stack space - if (!lua_checkstack(__ls, py.exportStrings().size() * 2)) { + if (!lua_checkstack(__ls, py.exportStrings().size())) { PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); } for (auto& iter : py.exportStrings()) { @@ -1220,7 +1219,7 @@ class LuaWrapper } } - PRINT_WITH_COLOR_LB(GREEN, "done."); + if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "done."); return 1; } @@ -1235,20 +1234,27 @@ class LuaWrapper if (lua_type(__ls, 1) != LUA_TTABLE) { PRINT_WITH_COLOR_LB(RED, "the stack value is not a table but is being accessed as such."); } else { - PRINT_WITH_COLOR_LB(GREEN, "stack index 1 is a table."); + if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "stack index 1 is a table."); + } + if (Verbose) std::cout << CYAN << "table_length: " << table_length << NORMAL << "\n"; + if (!lua_checkstack(__ls, table_length)) { + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); } - std::cout << CYAN << "table_length: " << table_length << NORMAL << "\n"; for (int i = 1; i <= table_length; ++i) { lua_rawgeti(__ls, 1, i); xobj_code_.push_back(int(lua_tonumber(__ls, i + 2))); } - std::cout << BLUE << "function code: "; - for (auto& iter : xobj_code_) {std::cout << NORMAL << int(iter) << " ";} - std::cout << NORMAL <<"\n"; + if (Verbose) { + std::cout << BLUE << "function code: "; + for (auto& iter : xobj_code_) {std::cout << NORMAL << int(iter) << " ";} + std::cout << NORMAL <<"\n"; + } xobj_name = lua_tostring(__ls, 2); std::pair<void*, size_t> xobj = executioner.loadObjsInXMem(xobj_code_); - std::cout << "xobj will be registered as " << YELLOW << xobj_name << NORMAL << ". " << "it is recommended to use a post- or pre-fix for the xobj names to avoid namespace pollution." "\n"; - std::cout << GREEN << "pointer: " << BLUE << xobj.first << " " << GREEN << "size: " << BLUE << xobj.second << NORMAL << "\n"; + if (Verbose) { + std::cout << "xobj will be registered as " << YELLOW << xobj_name << NORMAL << ". " << "it is recommended to use a post- or pre-fix for the xobj names to avoid namespace pollution." "\n"; + std::cout << GREEN << "pointer: " << BLUE << xobj.first << " " << GREEN << "size: " << BLUE << xobj.second << NORMAL << "\n"; + } executioner.pushvptr(xobj.first, xobj_name); return 0; } @@ -1297,9 +1303,9 @@ class LuaWrapper PRINT_WITH_COLOR_LB(RED, "xcall: the stack value is not a table but is being accessed as such."); return 0; } else { - PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 2 is a table."); + if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 2 is a table."); } - std::cout << CYAN << "table_length: " << table_length_2 << NORMAL << "\n"; + if (Verbose) std::cout << CYAN << "table_length: " << table_length_2 << NORMAL << "\n"; for (int i = 1; i <= table_length_2; ++i) { lua_rawgeti(__ls, 2, i); args[i-1] = lua_tostring(__ls, i + numargs); @@ -1323,10 +1329,10 @@ class LuaWrapper PRINT_WITH_COLOR_LB(RED, "xcall: the stack value is not a table but is being accessed as such."); return 0; } else { - PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 5 is a table."); + if (Verbose) PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 5 is a table."); } - std::cout << CYAN << "table_length: " << table_length_5 << NORMAL << "\n"; + if (Verbose) std::cout << CYAN << "table_length: " << table_length_5 << NORMAL << "\n"; for (int i = 1; i <= table_length_5; ++i) { lua_rawgeti(__ls, 5, i); if (lua_type(__ls, i+numargs+argc) == LUA_TBOOLEAN) {} @@ -1382,7 +1388,7 @@ class LuaWrapper int BruiserLuaXObjGetList(lua_State* __ls) { auto xlist = executioner.getvptrs(); lua_newtable(__ls); - if (!lua_checkstack(__ls, xlist.size() * 2)) { + if (!lua_checkstack(__ls, xlist.size())) { PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); } for (auto& iter : xlist) { @@ -1552,6 +1558,7 @@ class LuaWrapper return 0; } + //@DEVI-FIXME-broken int BruiserLuaShowSourcecode(lua_State* __ls) { unsigned int args = 0U; @@ -1584,13 +1591,17 @@ class LuaWrapper } std::string line; + std::string dummy; while(getline(targetfile, line)) { - lua_pushstring(__ls, line.c_str()); + dummy += line; + //lua_pushstring(__ls, line.c_str()); } + lua_pushstring(__ls , dummy.c_str()); targetfile.close(); - return lineend - linebegin + 1U; + //return lineend - linebegin + 1U; + return 1; } int BruiserLuaMutagenExtraction(lua_State* __ls) @@ -2022,14 +2033,7 @@ int main(int argc, const char **argv) { /*The non-cli execution loop*/ if (NonCLILuaScript != "") { - std::ifstream lua_script_noncli; - lua_script_noncli.open(NonCLILuaScript); - std::string line; - while(std::getline(lua_script_noncli, line)) { - BruiserLog.PrintToLog("running in non-cli mode..."); - BruiserLog.PrintToLog(line + "\n"); - LE.RunChunk((char*)line.c_str()); - } + luaL_dofile(LE.GetLuaState(), NonCLILuaScript.c_str()); dostring(LE.GetLuaState(), "os.exit()", "test"); return 0; } diff --git a/bruiser/bruiserffi.c b/bruiser/bruiserffi.c index 409d755..1972c8c 100644 --- a/bruiser/bruiserffi.c +++ b/bruiser/bruiserffi.c @@ -21,13 +21,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* // @TODO-structs and unions not supported // @TODO-vararg xobjs are not supported /**********************************************************************************************************************/ +#include "bruiserffi.h" +#include <capstone/capstone.h> +#include <errno.h> #include <ffi.h> +#include <inttypes.h> #include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <string.h> -//#include <capstone/capstone.h> -#include "bruiserffi.h" /**********************************************************************************************************************/ #define VOIDIFY(X) (void*)X /**********************************************************************************************************************/ @@ -167,6 +169,32 @@ void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void* ffi_callX_var(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void** values) {return NULL;} /**********************************************************************************************************************/ +#define CODE_1 "\x55\x48\x89\xe5\x48\x83\xec\x20\x89\x7d\xfc\x89\x75\xf8\x89\x55\xf4\x89\x4d\xf0\x8b\x7d\xfc\x8b\x75\xf8\xe8\xd1\xfd\xff\xff\x8b\x7d\xf4\x8b\x75\xf0\x89\x45\xec\xe8\xc3\xfd\xff\xff\x8b\x4d\xec\x1\xc1\x89\xc8\x48\x83\xc4\x20\x5d\xc3" +int capstone_test(void) { + csh handle; + cs_insn* insn; + size_t count; + if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) return -1; + count = cs_disasm(handle, CODE_1, sizeof(CODE_1) - 1, 0x0, 0, &insn); + if (count > 0) { + size_t j; + for (j = 0; j <count; ++j) { + if (strcmp(insn[j].mnemonic, "call") == 0) { + printf("0x%"PRIx64":\t%s\t\t%s\n", insn[j].address, insn[j].mnemonic, insn[j].op_str); + char* endptr; + intmax_t address = strtoimax(insn[j].op_str, &endptr, 0); + uintmax_t uaddress = strtoumax(insn[j].op_str, &endptr, 0); + printf("address: %ld\n", address); + printf("uaddress: %ld\n", uaddress); + } + } + cs_free(insn, count); + } else { + printf("ERROR!!!\n"); + } + cs_close(&handle); + return 0; +} /**********************************************************************************************************************/ // @DEVI-the following lines are only meant for testing. uint32_t add2(uint32_t a, uint32_t b) {return a+b;} @@ -206,6 +234,10 @@ int main(int argc, char** argv) { result = ffi_callX(1, args3, ffi_type_pointer, pstring, values3); fprintf(stdout, "result of calling passthrough is %s\n", ffi_reinterpret_string(result)); + /*capstone tests*/ + printf("\n"); + capstone_test(); + return 0; } /**********************************************************************************************************************/ diff --git a/bruiser/bruiserffi.h b/bruiser/bruiserffi.h index c7a2821..e3afda0 100644 --- a/bruiser/bruiserffi.h +++ b/bruiser/bruiserffi.h @@ -18,6 +18,7 @@ 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.*/ /**********************************************************************************************************************/ +#include <capstone/capstone.h> #include <ffi.h> #include <stdint.h> /**********************************************************************************************************************/ diff --git a/bruiser/compile_commands.json b/bruiser/compile_commands.json index 48605af..51d9b0f 100644 --- a/bruiser/compile_commands.json +++ b/bruiser/compile_commands.json @@ -1,6 +1,6 @@ [ { - "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o bruiser.o bruiser.cpp", + "command": "c++ -c -I/home/bloodstalker/extra/llvm-6/llvm/include -I/home/bloodstalker/extra/llvm-6/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-6/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-6/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.6m -I/usr/include/python3.6m -o bruiser.o bruiser.cpp", "directory": "/home/bloodstalker/devi/hell2/bruiser", "file": "/home/bloodstalker/devi/hell2/bruiser/bruiser.cpp" }, @@ -10,17 +10,17 @@ "file": "/home/bloodstalker/devi/hell2/bruiser/linenoise/linenoise.c" }, { - "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o CompletionHints.o CompletionHints.cpp", + "command": "c++ -c -I/home/bloodstalker/extra/llvm-6/llvm/include -I/home/bloodstalker/extra/llvm-6/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-6/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-6/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.6m -I/usr/include/python3.6m -o CompletionHints.o CompletionHints.cpp", "directory": "/home/bloodstalker/devi/hell2/bruiser", "file": "/home/bloodstalker/devi/hell2/bruiser/CompletionHints.cpp" }, { - "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o mutagen.o mutagen.cpp", + "command": "c++ -c -I/home/bloodstalker/extra/llvm-6/llvm/include -I/home/bloodstalker/extra/llvm-6/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-6/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-6/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.6m -I/usr/include/python3.6m -o mutagen.o mutagen.cpp", "directory": "/home/bloodstalker/devi/hell2/bruiser", "file": "/home/bloodstalker/devi/hell2/bruiser/mutagen.cpp" }, { - "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o ORCmutation.o ORCmutation.cpp", + "command": "c++ -c -I/home/bloodstalker/extra/llvm-6/llvm/include -I/home/bloodstalker/extra/llvm-6/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-6/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-6/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.6m -I/usr/include/python3.6m -o ORCmutation.o ORCmutation.cpp", "directory": "/home/bloodstalker/devi/hell2/bruiser", "file": "/home/bloodstalker/devi/hell2/bruiser/ORCmutation.cpp" }, diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index 2e9cd56..6645098 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -13,6 +13,7 @@ -- -------------------------------------------------------------------------------------------------------------- elf_file = "../bfd/test/test.so" +--elf_file = "/home/bloodstalker/devi/hell2/bfd/test/test.so" --elf_file = "../bfd/test/test" function getGlobalTable() @@ -120,24 +121,8 @@ function printFuncSizes() end end --- start of @placeholder -function xobjRegister(code_table, registration_name) - -- lightuserdata - local Xobjpointer - return Xobjpointer -end --- should be varargs --- registration_name() --- end of @placeholder - --- start of @placeholder --- C--args = argc, arg_string, ffi_type, xptr, the_actual_args --- lua--args = number, table, string, xptr, args --- end of @placeholder -function callX(n_argc, t_string, str, index, t_values) -end - function main() + pwd() printObjNames() printObjSizes() printFuncNames() @@ -167,7 +152,6 @@ function main() printFuncSizes() - pwd() xobjregister(add2_code, "add2") xobjregister(sub2_code, "sub2") xobjregister(adddouble_code, "adddouble") @@ -189,20 +173,20 @@ function main() if a ~= -100 then print("test failed") end a=xcall(2,{"double", "double"},"double",2, {333.333,222.222}) print("xcall returned:",a) - -- FIXME - if tostring(a) ~= tostring(555.555) then print("test failed") end + if tostring(a) ~= tostring(555.555) then print("test failed"); os.exit(1) end a=xcall(2,{"double", "double"},"double",3, {333.333,222.222}) print("xcall returned:",a) - if tostring(a) ~= tostring(111.111) then print("test failed") end + if tostring(a) ~= tostring(111.111) then print("test failed"); os.exit(1) end a=xcall(3,{"double", "double", "double"},"double",4, {333.333,222.222,111.111}) print("xcall returned:",a) a=xcall(3,{"double", "double", "double"},"double","triple", {333.333,222.222,111.111}) print("xcall returned:",a) - if tostring(a) ~= tostring(666.666) then print("test failed") end + if tostring(a) ~= tostring(666.666) then print("test failed"); os.exit(1) end a=xcall(1,{"string"},"string","passthrough", {"i live!"}) print("xcall returned:",a) + if (a ~= "i live!") then print("test failed"); os.exit(1) end --a=xcall(4,{"sint32", "sint32", "sint32", "sint32"},"sint32",5, {10,20,30,40}) --print("xcall returned:",a) diff --git a/bruiser/lua-scripts/smoketest.lua b/bruiser/lua-scripts/smoketest.lua index f278365..c53fd9a 100644 --- a/bruiser/lua-scripts/smoketest.lua +++ b/bruiser/lua-scripts/smoketest.lua @@ -1,5 +1,5 @@ help() ---hijackmain() +hijackmain() clear() history() Vars() @@ -8,9 +8,10 @@ Classes() Structs() Arrays() Unions() -historysize(150) -showsource(1,5,"test.cpp") ---extractmutagen() +historysize(1500) +a=showsource(1,5,"test.cpp") +print(a) +extractmutagen() setmakepath("./test/bruisertest") setbinpath("./test/bruisertest") make("clean") diff --git a/bruiser/makefile b/bruiser/makefile index 81d4923..7bf3bf5 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -13,7 +13,7 @@ SRCS=$(wildcard *.cpp) C_SRCS=$(wildcard *.c) #for some reason without ld the build fails on ubuntu trusty on travis #EXTRA_LD_FLAGS+=-lpthread -ldl -lutil -lm -Xlinker -lpython3 -EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi +EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi -lcapstone ######################################RULES#################################### .DEFAULT: all diff --git a/bruiser/run.sh b/bruiser/run.sh index 912fcf2..226271b 100755 --- a/bruiser/run.sh +++ b/bruiser/run.sh @@ -1,3 +1,4 @@ #!/bin/bash -./bruiser ../test/bruisertest/test.cpp +cd $(dirname $0) +"./bruiser" ../test/bruisertest/test.cpp diff --git a/extra-tools/precommitTests.sh b/extra-tools/precommitTests.sh index 924731b..57c17aa 100755 --- a/extra-tools/precommitTests.sh +++ b/extra-tools/precommitTests.sh @@ -1,5 +1,7 @@ #!/bin/bash ######################################################################################################################## +#cd $(dirname $0) +######################################################################################################################## Red="\033[0;31m" Green="\033[0;32m" Lblue="\033[1;34m" @@ -35,6 +37,13 @@ function RelicKeeper printf "${Orange}RelicKeeper removed the oldest safercpp relic.\n${NC}" | tee -a ../../test/precommit.rep fi + cd ../obfuscator + RELIC_CNT=$(ls | gawk 'END{print NR}') + if (( $RELIC_CNT > $RELIC_COUNT )); then + rm "$(ls -t | tail -1)" + printf "${Orange}RelicKeeper removed the oldest obfuscator relic.\n${NC}" | tee -a ../../test/precommit.rep + fi + cd ../.. } ######################################################################################################################## @@ -57,8 +66,8 @@ fi printf "${Lblue}running mutator-lvl0 on the tdd sources...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 smoke test on the tdds passed.\n${NC}" | tee -a ./test/precommit.rep @@ -85,8 +94,8 @@ else fi printf "${Lblue}running smoke tests on mutator-lvl0...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 C++11 smoke test passed...\n${NC}" | tee -a ./test/precommit.rep @@ -142,15 +151,36 @@ if [[ $? == 0 ]]; then "cp" ./mutator-lvl0 ./reliquary/m0/m0-$TIME "cp" ./bruiser/bruiser ./reliquary/bruiser/bruiser-$TIME "cp" ./safercpp/safercpp-arr ./reliquary/safercpp/safercpp-$TIME + "cp" ./obfuscator/obfuscator ./reliquary/obfuscator/obfuscator-$TIME RelicKeeper source ./extra-tools/oracle.sh ./test/precommit.rep else printf "${Red}mutator c++1z test build failed.\n${NC}" | tee -a ./test/precommit.rep fi +printf "${Lblue}running load.py test...\n${NC}" | tee -a ./test/precommit.rep +printf "${Orange}../bfd/test.py\n${NC}" | tee -a ./test/precommit.rep +./bfd/test.py --obj ./bfd/test/test.so +# its not a mistake. the obfuscator test is supposed to return 128 +if [[ $? == 0 ]]; then + printf "${Green}load.py test passed.\n${NC}" | tee -a ./test/precommit.rep +else + printf "${Red}load.py test failed.\n${NC}" | tee -a ./test/precommit.rep +fi + +printf "${Lblue}running obfuscator test...\n${NC}" | tee -a ./test/precommit.rep +printf "${Orange}../obfuscator/run.sh\n${NC}" | tee -a ./test/precommit.rep +./obfuscator/run.sh +# its not a mistake. the obfuscator test is supposed to return 128 +if [[ $? == 128 ]]; then + printf "${Green}obfuscator test passed.\n${NC}" | tee -a ./test/precommit.rep +else + printf "${Red}obfuscator test failed.\n${NC}" | tee -a ./test/precommit.rep +fi + printf "${Lblue}running mutator-lvl0 on the tdd sources...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 smoke test on the tdds passed.\n${NC}" | tee -a ./test/precommit.rep @@ -177,8 +207,8 @@ else fi printf "${Lblue}running smoke tests on mutator-lvl0...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 C++1z smoke test passed...\n${NC}" | tee -a ./test/precommit.rep @@ -208,6 +238,13 @@ if [[ $? == 0 ]]; then else printf "${Red}bruiser C++11 smoke test failed...\n${NC}" | tee -a ./test/precommit.rep fi +printf "${Orange}./bruiser/bruiser ./test/bruisertest/test.cpp -lua ./bruiser/lua-scripts/demo.lua\n${NC}" | tee -a ./test/precommit.rep +"./bruiser/bruiser" ./test/bruisertest/test.cpp -lua ./bruiser/lua-scripts/demo.lua +if [[ $? == 0 ]]; then + printf "${Green}bruiser xobj test passed...\n${NC}" | tee -a ./test/precommit.rep +else + printf "${Red}bruiser xobj test failed...\n${NC}" | tee -a ./test/precommit.rep +fi printf "${Lblue}running cpp smoke tests on mutator-lvl0...\n${NC}" | tee -a ./test/precommit.rep printf "${Orange}./mutator-lvl0 ./test/m0-cpp-smoke/m0-cpp-smoke.cpp\n${NC}" | tee -a ./test/precommit.rep @@ -234,8 +271,8 @@ else fi printf "${Lblue}running mutator-lvl0 on the tdd sources...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs1.c ./test/testFuncs2.c ./test/testFuncs3.c -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 smoke test on the tdds passed.\n${NC}" | tee -a ./test/precommit.rep @@ -262,8 +299,8 @@ else fi printf "${Lblue}running smoke tests on mutator-lvl0...\n${NC}" | tee -a ./test/precommit.rep -printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep -"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/6.4.1/include -Wall > ./test/misra-log +printf "${Orange}./mutator-lvl0 -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log\n${NC}" | tee -a ./test/precommit.rep +"./mutator-lvl0" -SysHeader=false -MainOnly=true ./test/testFuncs3.h -- -std=c90 -I/lib/gcc/x86_64-redhat-linux/7.3.1/include -Wall > ./test/misra-log if [[ $? == 0 ]]; then printf "${Green}mutator-lvl0 C++14 smoke test passed...\n${NC}" | tee -a ./test/precommit.rep @@ -88,7 +88,7 @@ LD_FLAGS=-Wl,--start-group -lclangAST -lclangAnalysis -lclangBasic\ -lclangLex -lclangParse -lclangSema -lclangEdit -lclangASTMatchers\ -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerFrontend\ -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore\ --lclangSerialization -lclangToolingCore -lclangTooling -lstdc++ -lLLVMRuntimeDyld -lm -Wl,--end-group +-lclangSerialization -lclangToolingCore -lclangTooling -lstdc++ -lLLVMRuntimeDyld -lm -Wl,--end-group LD_FLAGS+=$(shell $(LLVM_CONF) --ldflags --libs --system-libs) CXX_FLAGS+=$(EXTRA_CXX_FALGS) @@ -85,6 +85,7 @@ install: if [[ ! -d "./reliquary/m0" ]]; then mkdir ./reliquary/m0; fi if [[ ! -d "./reliquary/bruiser" ]]; then mkdir ./reliquary/bruiser; fi if [[ ! -d "./reliquary/safercpp" ]]; then mkdir ./reliquary/safercpp; fi + if [[ ! -d "./reliquary/obfuscator" ]]; then mkdir ./reliquary/obfuscator; fi $(shell echo MUTATOR_HOME=$$(pwd) > ./daemon/mutator.config) help: diff --git a/mutator-lvl2.cpp b/mutator-lvl2.cpp index 5bb0020..4105488 100644 --- a/mutator-lvl2.cpp +++ b/mutator-lvl2.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* /**********************************************************************************************************************/ /*included modules*/ /*project headers*/ -#include "mutator_aux.h" +//#include "mutator_aux.h" /*standard headers*/ #include <string> #include <iostream> @@ -60,52 +60,8 @@ using namespace clang::driver; using namespace clang::tooling; /**********************************************************************************************************************/ /*global vars*/ - static llvm::cl::OptionCategory MatcherSampleCategory("Matcher Sample"); /**********************************************************************************************************************/ -class IfElseFixer : public MatchFinder::MatchCallback -{ -public: - IfElseFixer (Rewriter &Rewrite) : Rewrite (Rewrite) {} - - virtual void run(const MatchFinder::MatchResult &MR) - { - /*underdev*/ - if (MR.Nodes.getNodeAs<clang::IfStmt>("mrifelse") != nullptr) - { - const IfStmt *ElseIf = MR.Nodes.getNodeAs<clang::IfStmt>("mrifelse"); - //const IfStmt *LastIf = MR.Nodes.getNodeAs<clang::IfStmt>("mrifelse"); - - SourceLocation IFESL = ElseIf->getLocStart(); - IFESL = Devi::SourceLocationHasMacro(IFESL, Rewrite, "start"); - SourceLocation IFESLE = ElseIf->getLocEnd(); - IFESLE = Devi::SourceLocationHasMacro(IFESLE, Rewrite, "end"); - SourceRange SR; - SR.setBegin(IFESL); - SR.setEnd(IFESLE); - - clang::Rewriter::RewriteOptions opts; - - int RangeSize = Rewrite.getRangeSize(SR, opts); - - //std::cout << IFESLE.printToString(*MR.SourceManager) << "\n" << std::endl; - -#if 1 - //Rewrite.InsertText(ElseIf->getThen()->getLocStart(), "{\n", "true", "true"); - Rewrite.InsertTextAfterToken(IFESL.getLocWithOffset(RangeSize + 1U), "else\n{/*intentionally left blank*/\n}\n"); -#endif - } - else - { - std::cout << "matcher -mrifelse- returned nullptr." << std::endl; - } - } - - -private: - Rewriter &Rewrite; -}; -/**********************************************************************************************************************/ class BlankDiagConsumer : public clang::DiagnosticConsumer { public: @@ -116,16 +72,15 @@ class BlankDiagConsumer : public clang::DiagnosticConsumer /**********************************************************************************************************************/ class MyASTConsumer : public ASTConsumer { public: - MyASTConsumer(Rewriter &R) : HandlerForIfElse(R) { - Matcher.addMatcher(ifStmt(allOf(hasElse(ifStmt()), unless(hasAncestor(ifStmt())), unless(hasDescendant(ifStmt(hasElse(unless(ifStmt()))))))).bind("mrifelse"), &HandlerForIfElse); + MyASTConsumer(Rewriter &R) { } - void HandleTranslationUnit(ASTContext &Context) override { - Matcher.matchAST(Context); + void HandleTranslationUnit(ASTContext &Context) { + std::cout << "i was here\n"; + //Matcher.matchAST(Context); } private: - IfElseFixer HandlerForIfElse; MatchFinder Matcher; }; /**********************************************************************************************************************/ @@ -140,7 +95,10 @@ public: DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); + //return llvm::make_unique<ASTConsumer>(new MyASTConsumer(TheRewriter)); + //return llvm::make_unique<ASTConsumer>(*new MyASTConsumer(TheRewriter)); return llvm::make_unique<MyASTConsumer>(TheRewriter); + //return std::unique_ptr<ASTConsumer>(new ASTConsumer); } private: @@ -148,43 +106,15 @@ private: Rewriter TheRewriter; }; /**********************************************************************************************************************/ -#if 0 -class mutatorBEConsumer : public ASTConsumer { - public: - using LinkModule = CodeGenAction::LinkModule; - mutatorBEConsumer(clang::BackendAction Backend_EmitObj, DiagnosticsEngine &diags, const HeaderSearchOptions &HSO, - const PreprocessorOptions &PPO, const CodeGenOptions &CGO, const clang::TargetOptions &TO, - const LangOptions &LO, bool TimePasses, const std::string &InFile, llvm::SmallVector<LinkModule, 4> LinkModules, - std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &C) {} - - virtual void HandleTranslationUnit(ASTContext &astc) {} -}; -#endif -/**********************************************************************************************************************/ -class mutatorEmitObjAction : public EmitObjAction { - public: - mutatorEmitObjAction() {} -}; -/**********************************************************************************************************************/ /*Main*/ int main(int argc, const char **argv) { CommonOptionsParser op(argc, argv, MatcherSampleCategory); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); - std::vector<std::unique_ptr<ASTUnit>> ASTs; - auto buildASTRes [[maybe_unused]] = Tool.buildASTs(ASTs); - - for (auto &iter : ASTs) - { - if (iter->hasSema()) - { - std::cout << "sema acquired\n"; - iter->Save("./TU.save"); - clang::Sema &selfSema [[maybe_unused]] = iter->getSema(); - } - } - - return Tool.run(newFrontendActionFactory<MyFrontendAction>().get()); + int ret; + ret = Tool.run(newFrontendActionFactory<MyFrontendAction>().get()); + std::cout << "fucking done!\n"; + return ret; } /*last line intentionally left blank.*/ diff --git a/obfuscator/compile_commands.json b/obfuscator/compile_commands.json index 5b4729c..6fa5c24 100644 --- a/obfuscator/compile_commands.json +++ b/obfuscator/compile_commands.json @@ -1,6 +1,6 @@ [ { - "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -o obfuscator.o obfuscator.cpp", + "command": "c++ -c -v -I/home/bloodstalker/extra/llvm-6/llvm/include -I/home/bloodstalker/extra/llvm-6/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-6/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-6/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -o obfuscator.o obfuscator.cpp", "directory": "/home/bloodstalker/devi/hell2/obfuscator", "file": "/home/bloodstalker/devi/hell2/obfuscator/obfuscator.cpp" } diff --git a/obfuscator/makefile b/obfuscator/makefile index 11a3219..9a9981f 100644 --- a/obfuscator/makefile +++ b/obfuscator/makefile @@ -21,10 +21,10 @@ depend: .depend -include ./.depend .cpp.o: - $(CXX) $(CXX_FLAGS) -c $< -o $@ + $(CXX) -v $(CXX_FLAGS) -c $< -o $@ $(OBSC): $(OBSC).o ../mutator_aux.o - $(CXX) $^ $(LD_FLAGS) -o $@ + $(CXX) -v $^ $(LD_FLAGS) -o $@ clean: rm -f *.o *~ $(OBSC) diff --git a/obfuscator/obfuscator.cpp b/obfuscator/obfuscator.cpp index 2cbbd73..f6df690 100644 --- a/obfuscator/obfuscator.cpp +++ b/obfuscator/obfuscator.cpp @@ -445,10 +445,12 @@ class BlankDiagConsumer : public clang::DiagnosticConsumer class MyASTConsumer : public ASTConsumer { public: MyASTConsumer(Rewriter &R) : funcDeclHandler(R), HandlerForVar(R), HandlerForClass(R), HandlerForCalledFunc(R), HandlerForCalledVar(R) { +#if 1 Matcher.addMatcher(functionDecl().bind("funcdecl"), &funcDeclHandler); Matcher.addMatcher(varDecl(anyOf(unless(hasDescendant(expr(anything()))), hasDescendant(expr(anything()).bind("expr")))).bind("vardecl"), &HandlerForVar); Matcher.addMatcher(recordDecl(isClass()).bind("classdecl"), &HandlerForClass); Matcher.addMatcher(declRefExpr().bind("calledvar"), &HandlerForCalledVar); +#endif } void HandleTranslationUnit(ASTContext &Context) override { @@ -471,6 +473,7 @@ public: delete BDCProto; delete tee; } + void EndSourceFileAction() override { std::error_code EC; std::string OutputFilename = TEMP_FILE; @@ -608,6 +611,7 @@ class WhitespaceWarper { /**********************************************************************************************************************/ /*Main*/ int main(int argc, const char **argv) { +#if 1 CommonOptionsParser op(argc, argv, ObfuscatorCat); const std::vector<std::string> &SourcePathList = op.getSourcePathList(); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); @@ -616,6 +620,7 @@ int main(int argc, const char **argv) { CW.run(); dumpHashFilenames(hashFilenames(SourcePathList)); dumpDirList(listDirs("./test")); +#endif #if 0 for (auto &iter : SourcePathList) { std::cout << "name: " << std::get<0>(getNameFromPath(iter)) << "\t" << "extension: " << std::get<1>(getNameFromPath(iter)) << "\tpath: " << std::get<2>(getNameFromPath(iter)) << "\n"; diff --git a/obfuscator/run.sh b/obfuscator/run.sh index d5197d5..68d0632 100755 --- a/obfuscator/run.sh +++ b/obfuscator/run.sh @@ -1,6 +1,7 @@ #!/bin/bash - -#make +cd $(dirname $0) "./obfuscator" ./test/test.cpp "./obfuscator" ./test/header.hpp -- -#less dupe.cpp +"g++" ./FILE15118982290295364091.cpp +#expected to return 128 +./a.out diff --git a/test/m0-cpp-smoke/compile_commands.json b/test/m0-cpp-smoke/compile_commands.json index 1a23f8c..3c4a929 100644 --- a/test/m0-cpp-smoke/compile_commands.json +++ b/test/m0-cpp-smoke/compile_commands.json @@ -1,6 +1,6 @@ [ { - "command": "c++ -c -I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include -std=c++14 -o m0-cpp-smoke.o m0-cpp-smoke.cpp", + "command": "c++ -c -I/usr/lib/gcc/x86_64-redhat-linux/7.3.1/include -std=c++14 -o m0-cpp-smoke.o m0-cpp-smoke.cpp", "directory": "/home/bloodstalker/devi/hell2/test/m0-cpp-smoke", "file": "/home/bloodstalker/devi/hell2/test/m0-cpp-smoke/m0-cpp-smoke.cpp" } diff --git a/test/m0-cpp-smoke/makefile b/test/m0-cpp-smoke/makefile index dfec4a2..b341a3f 100644 --- a/test/m0-cpp-smoke/makefile +++ b/test/m0-cpp-smoke/makefile @@ -1,7 +1,7 @@ TARGET=m0-cpp-smoke CXX?=clang++ # you should change the include path to one that is right for you -CXX_FLAGS=-I/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include -std=c++14 +CXX_FLAGS=-I/usr/lib/gcc/x86_64-redhat-linux/7.3.1/include -std=c++14 .DEFAULT:all clean |