diff options
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/bruiser-extra.h | 1 | ||||
-rw-r--r-- | bruiser/bruiser.cpp | 20 | ||||
-rw-r--r-- | bruiser/bruiser.h | 6 | ||||
-rw-r--r-- | bruiser/executioner.h | 48 |
4 files changed, 62 insertions, 13 deletions
diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h index 40e22f0..24c2a6b 100644 --- a/bruiser/bruiser-extra.h +++ b/bruiser/bruiser-extra.h @@ -123,6 +123,7 @@ std::vector<std::string> LUA_FUNCS = "pwd()", "objload()", "listObjects", + "xobjwrapper", "_G", "_VERSION", "assert", diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 324841d..8934867 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -299,7 +299,7 @@ class PyExec { PRINT_WITH_COLOR_LB(YELLOW, "functions with a zero size will not be printed:"); for (auto &iter : hexobj) { for (auto &iterer : iter) { - std::cout << RED << int(iterer) << " "; + std::cout << RED << std::hex << int(iterer) << " "; } std::cout << "\n" << NORMAL; } @@ -1588,8 +1588,7 @@ class LuaWrapper unsigned int returncount = 0; for (auto &iter : ShellGlobalInstance.PATH) - { - lua_pushstring(__ls, iter.c_str()); + { lua_pushstring(__ls, iter.c_str()); std::cout << BLUE << iter.c_str() << NORMAL << "\n"; returncount++; } @@ -1611,6 +1610,21 @@ class LuaWrapper return returncount; } + int BruiserLuaCallXFunc(lua_State* __ls) { + int numargs = lua_gettop(__ls); + std::string argtype; + + if (numargs % 2 != 0) { + PRINT_WITH_COLOR_LB(RED, "Each arg should be accompanied with its type."); + } + + for (int i = 0; i < numargs; i = i + 2) { + argtype = lua_tostring(__ls, i); + } + + return 0; + } + int BruiserLuaChangeDirectory(lua_State* __ls) { int numargs = lua_gettop(__ls); diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h index 3cd8eaa..3b4513c 100644 --- a/bruiser/bruiser.h +++ b/bruiser/bruiser.h @@ -47,6 +47,9 @@ namespace bruiser /**********************************************************************************************************************/ const char* M0REP = "../test/misrareport.xml"; /**********************************************************************************************************************/ +#define JOIN2(x1, x2) x1##x2 +#define JOIN3(x1, x2, x3) x1##x2##x3 + #define RED "\033[1;31m" #define CYAN "\033[1;36m" #define GREEN "\033[1;32m" @@ -145,7 +148,8 @@ help CMDHelp[] = { {"changedirectory()", "changedirectory()", "changes bruiser's working directory. only use it when you know what you are doing.", "destination directory, [string]", "return value"}, {"pwd()", "pwd()", "pwd", "", ""}, {"objload()", "objload(\"main\", \"../bfd/test/test.so\")", "load the compiled functions into bruiser", "string", "success or failure"}, - {"listObjects()", "listObjects(\"function\")", "lists the loaded objects of the given type", "string", "success or failure"} + {"listObjects()", "listObjects(\"function\")", "lists the loaded objects of the given type", "string", "success or failure"}, + {"xobjwrapper()", "xobjwrapper(\"function\")", "call an xobject", "", "success or failure"} }; /**********************************************************************************************************************/ /** diff --git a/bruiser/executioner.h b/bruiser/executioner.h index ed5009b..b881902 100644 --- a/bruiser/executioner.h +++ b/bruiser/executioner.h @@ -54,12 +54,45 @@ namespace { // start of anonymous namespace return 0; } - int LuaGenericWrapper(lua_State* __ls, XObject __x) { - int numargs = lua_gettop(__ls); - std::vector<uint64_t> arg_vec; + std::vector<uint8_t> arg_emitter(std::vector<uint8_t> _args) {} - for (int i = 0; i < numargs; ++i) { - arg_vec.push_back(lua_tonumber(__ls, i + 1)); + int LuaXobjWrapper(lua_State* __ls) { + int numargs = lua_gettop(__ls); + std::vector<uint8_t> arg_vec; + std::string xfuncname; + std::vector<std::pair<intptr_t, int>> arg_ptr; + std::vector<std::pair<std::string, int>> arg_str; + std::vector<std::pair<double, int>> arg_double; + std::vector<std::pair<bool, int>> arg_bool; + + if (lua_type(__ls, 1) == LUA_TSTRING) { + xfuncname = lua_tostring(__ls, 1); + } else { + //PRINT_WITH_COLOR_LB(RED, "the first argument should be a string that is the name of the xfunc to be called."); + } + + // detecting arg types + for (int i = 2; i <= numargs; ++i) { + if (lua_type(__ls, i) == LUA_TBOOLEAN) { + arg_bool.push_back(std::make_pair(!!lua_tonumber(__ls, i), i)); + } + else if (lua_type(__ls, i) == LUA_TLIGHTUSERDATA) { + } + else if (lua_type(__ls, i) == LUA_TNUMBER) { + } + else if (lua_type(__ls, i) == LUA_TSTRING) { + } + else if (lua_type(__ls, i) == LUA_TTABLE) { + } + else if (lua_type(__ls, i) == LUA_TFUNCTION) { + } + else if (lua_type(__ls, i) == LUA_TUSERDATA) { + } + else if (lua_type(__ls, i) == LUA_TTHREAD) { + } + // type is Nil + else { + } } pid_t pid = fork(); @@ -69,7 +102,6 @@ namespace { // start of anonymous namespace } if (pid == 0) {} if (pid > 0) { - __x; } return 0; @@ -125,9 +157,7 @@ class Executioner { } void registerWithLua(lua_State* _lua_State) { - for (auto& iter : names) { - //lua_register(_lua_State, iter.c_str(), LuaGeneric); - } + lua_register(_lua_State, "xobjwrapper", LuaXobjWrapper); } void xobjsGetPtrs(void) { |