diff options
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/bruiser.cpp | 9 | ||||
-rw-r--r-- | bruiser/bruisercapstone.c | 4 | ||||
-rw-r--r-- | bruiser/hs/.depend | 0 | ||||
-rw-r--r-- | bruiser/hs/Safe.hs | 9 | ||||
-rw-r--r-- | bruiser/hs/Safe_stub.h | 9 | ||||
-rw-r--r-- | bruiser/hs/bruiserhs.c | 45 | ||||
-rw-r--r-- | bruiser/hs/bruiserhs.h | 0 | ||||
-rw-r--r-- | bruiser/hs/makefile | 37 | ||||
-rwxr-xr-x | bruiser/hs/run.sh | 6 | ||||
-rw-r--r-- | bruiser/lua-scripts/demo2.lua | 4 |
10 files changed, 115 insertions, 8 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index ea2add1..82cd632 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -325,8 +325,7 @@ class PyExec { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); - std::cout << RED << "call failed." << NORMAL << "\n"; - fprintf(stderr, "Call failed\n"); + std::cout << RED << "Call failed." << NORMAL << "\n"; return EXIT_FAILURE; } } @@ -476,6 +475,8 @@ class PyExec { std::vector<std::string> exportStrings(void) {return hexobj_str;} std::vector<std::uint8_t> exportTextSection(void) {return text_section;} + void getVarargs(std::vector<void*> _varargs) {varargs = _varargs;} + private: std::string py_script_name; std::string py_func_name; @@ -491,6 +492,7 @@ class PyExec { std::vector<std::string> hexobj_str; std::vector<std::vector<uint8_t>> hexobj; std::vector<uint8_t> text_section; + std::vector<void*> varargs; }; /**********************************************************************************************************************/ class XObjReliquary {}; @@ -1339,6 +1341,7 @@ class LuaWrapper action = lua_tostring(__ls, 3); if (action == "") PRINT_WITH_COLOR_LB(RED, "third argument is nil"); lua_pop(__ls, 3); + std::cout << NORMAL; } else { std::cout << RED << "wrong number of arguments provided. should give the python script name, python func name and its args.\n" << NORMAL; @@ -1349,7 +1352,7 @@ class LuaWrapper PyExec py(filename.c_str(), funcname.c_str(), objjpath.c_str()); if (Verbose) std::cout << BLUE << "running load.py: " << NORMAL << "\n"; - py.run(); + if (py.run() == EXIT_FAILURE) return 0; if (action == "code_list") { py.getAsCppByte(); //py.printHexObjs(); diff --git a/bruiser/bruisercapstone.c b/bruiser/bruisercapstone.c index f8dff64..8edc7ad 100644 --- a/bruiser/bruisercapstone.c +++ b/bruiser/bruisercapstone.c @@ -344,9 +344,7 @@ int dumpjmptable(JMP_S_T* current) { } } /**********************************************************************************************************************/ -void jmprewriter_j(JMP_S_T* jmp, uint8_t* code, JMP_T type, uint8_t* rewritten) { - -} +void jmprewriter_j(JMP_S_T* jmp, uint8_t* code, JMP_T type, uint8_t* rewritten) {} void jmprewriter_jne(JMP_S_T* jmp, uint8_t* code, JMP_T type, uint8_t* rewritten) {}; void jmprewriter_je(JMP_S_T* jmp, uint8_t* code, JMP_T type, uint8_t* rewritten) {} /**********************************************************************************************************************/ diff --git a/bruiser/hs/.depend b/bruiser/hs/.depend new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bruiser/hs/.depend diff --git a/bruiser/hs/Safe.hs b/bruiser/hs/Safe.hs new file mode 100644 index 0000000..8994e9e --- /dev/null +++ b/bruiser/hs/Safe.hs @@ -0,0 +1,9 @@ +{-#Language ForeignFunctionInterface#-} +module Safe where +import Foreign.C.Types +fibonacci :: Int -> Int +fibonacci n = fibs !! n + where fibs = 0 : 1: zipWith (+) fibs (tail fibs) +fibonacci_hs ::CInt -> CInt +fibonacci_hs = fromIntegral.fibonacci.fromIntegral +foreign export ccall fibonacci_hs::CInt->CInt diff --git a/bruiser/hs/Safe_stub.h b/bruiser/hs/Safe_stub.h new file mode 100644 index 0000000..3d939a1 --- /dev/null +++ b/bruiser/hs/Safe_stub.h @@ -0,0 +1,9 @@ +#include "HsFFI.h" +#ifdef __cplusplus +extern "C" { +#endif +extern HsInt32 fibonacci_hs(HsInt32 a1); +#ifdef __cplusplus +} +#endif + diff --git a/bruiser/hs/bruiserhs.c b/bruiser/hs/bruiserhs.c new file mode 100644 index 0000000..1ab34d8 --- /dev/null +++ b/bruiser/hs/bruiserhs.c @@ -0,0 +1,45 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*bruiser's lua asmrewriter implementation for jump tables*/ +/*Copyright (C) 2018 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.*/ +/**********************************************************************************************************************/ +#include <HsFFI.h> +#ifdef __GLASCOW_HASKELL__ +#include "Safe_stub.h" +extern void __stginit_Safe(void); +#endif +#include "bruiserhs.h" +#include <stdio.h> + +#pragma weak main +int main(int argc, char** argv) { + int i; + hs_init(&argc, &argv); +#ifdef __GLASCOW_HASKELL__ + hs_add_root(__stginit_Safe); +#endif + + i = fibonacci_hs(42); + printf("Fibonnaci:%d\n", i); + + hs_exit(); + return 0; +} +/**********************************************************************************************************************/ +/*last line intentionally left blank*/ + diff --git a/bruiser/hs/bruiserhs.h b/bruiser/hs/bruiserhs.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bruiser/hs/bruiserhs.h diff --git a/bruiser/hs/makefile b/bruiser/hs/makefile new file mode 100644 index 0000000..8787dd4 --- /dev/null +++ b/bruiser/hs/makefile @@ -0,0 +1,37 @@ +TARGET=bruiserhs +CC=clang +CC?=clang +CC_FLAGS= +CC_EXTRA?= +CC_FLAGS+=$(CC_EXTRA) + +SRCS=$(wildcard *.c) + +.DEFAULT:all clean + +.PHONY:all clean help + +all:$(TARGET) + +depend:.depend + +.depend:$(SRCS) + rm -rf .depend + $(CC) -MM $(CC_FLAGS) $^ > ./.depend + +-include ./.depend + +.c.o: + $(CC) $(CC_FLAGS) -c $< -o $@ + +$(TARGET): $(TARGET).o + $(CC) $^ $(LD_FLAGS) -o $@ + +clean: + rm -f *.o *~ $(TARGET) + rm .depend + +help: + @echo "all is the default target" + @echo "there is delete." + @echo "there is clean." diff --git a/bruiser/hs/run.sh b/bruiser/hs/run.sh new file mode 100755 index 0000000..413b088 --- /dev/null +++ b/bruiser/hs/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +ghc -c -O Safe.hs +ghc --make -no-hs-main -optc-O bruiserhs.c Safe -o bruiserhs + +"./bruiserhs" diff --git a/bruiser/lua-scripts/demo2.lua b/bruiser/lua-scripts/demo2.lua index db840fc..bd2eb91 100644 --- a/bruiser/lua-scripts/demo2.lua +++ b/bruiser/lua-scripts/demo2.lua @@ -118,9 +118,9 @@ function get_jmp_table() end --main() ---pretty_dump() +pretty_dump() --test() --jmp_t_test() --integ_test() --asm_rewriter_pretty() -dump_jmp_table() +--dump_jmp_table() |