diff options
Diffstat (limited to 'bruiser')
| -rw-r--r-- | bruiser/bruiser-extra.h | 4 | ||||
| -rw-r--r-- | bruiser/bruiser.cpp | 52 | ||||
| -rw-r--r-- | bruiser/bruiser.h | 6 | ||||
| -rw-r--r-- | bruiser/executioner.h | 50 | ||||
| -rw-r--r-- | bruiser/lua-scripts/demo1.lua | 30 | ||||
| -rw-r--r-- | bruiser/makefile | 2 | 
6 files changed, 128 insertions, 16 deletions
| diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h index d6232a9..ac02451 100644 --- a/bruiser/bruiser-extra.h +++ b/bruiser/bruiser-extra.h @@ -125,6 +125,10 @@ std::vector<std::string> LUA_FUNCS =    "listObjects",    "xobjregister",    "xobjwrapper", +  "xcall(", +  "xobjlist()", +  "xallocglobal(", +  "xallocallglobals()",    "_G",    "_VERSION",    "assert", diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 114b0ec..17e2a51 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -1250,6 +1250,7 @@ class LuaWrapper        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";        XObject ptr = (XObject)xobj.first; +      executioner.pushvptr(xobj.first, xobj_name);        ptr();        xobj_2int ptr2;        ptr2 = (xobj_2int)ptr; @@ -1258,6 +1259,49 @@ class LuaWrapper        return 0;      } +    int BruiserLuaCallX(lua_State* __ls) { +      int numargs = lua_gettop(__ls); +      if (numargs != 2) {PRINT_WITH_COLOR_LB(RED, "bad number of args. expected exactly two.");} +      int x_index = lua_tointeger(__ls, 1); +      int x_arg_num = lua_tointeger(__ls, 2); +      xobj_2int ptr; +      auto dummy = executioner.getvptrbyindex(x_index).first; +      if (dummy != nullptr) { +        ptr = (xobj_2int)dummy; +        int result = ptr(30, 20); +        std::cout << "call made to xobj named " << GREEN << executioner.getvptrbyindex(x_index).second << NORMAL << "\n"; +        lua_pushnumber(__ls, result); +        return 1; +      } else { +        PRINT_WITH_COLOR_LB(RED, "the index is too high into the xobj vector."); +        return 0; +      } +    } + +    int BruiserLuaXObjGetList(lua_State* __ls) { +      auto xlist = executioner.getvptrs(); +        lua_newtable(__ls); +        if (!lua_checkstack(__ls, xlist.size() * 2)) { +          PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); +        } +        for (auto& iter : xlist) { +          std::cout << CYAN << iter.second << NORMAL <<"\n"; +          lua_pushstring(__ls, iter.second.c_str()); +          std::cout << MAGENTA << (long int)iter.first << NORMAL <<"\n"; +          lua_pushinteger(__ls, (long int)iter.first); +          lua_settable(__ls, -3); +        } +      return 1; +    } + +    int BruiserLuaXObjAllocGlobal(lua_State* __ls) { +      int nuamrgs = lua_gettop(__ls); +      std::string glob_name = lua_tostring(__ls , 1); +      size_t size = lua_tointeger(__ls, 2); +      return 0; +    } +    int BruiserLuaXObjAllocAllGlobals(lua_State* __ls) {return 0;} +      /*read the m0 report*/      int BruiserLuaM0(lua_State* __ls)      { @@ -1785,8 +1829,10 @@ int main(int argc, const char **argv) {    /*initializing the log*/    bruiser::BruiserReport BruiserLog; -  /*initing executioner*/ +  /*initing xobj stuff*/    Executioner executioner; +  Arguary arguary; +  XGlobals xglobals;    /*gets the compilation database and options for the clang instances that we would later run*/    CommonOptionsParser op(argc, argv, BruiserCategory); @@ -1857,6 +1903,10 @@ int main(int argc, const char **argv) {      lua_register(LE.GetLuaState(), "objload", &LuaDispatch<&LuaWrapper::BruiserPyLoader>);      lua_register(LE.GetLuaState(), "listObjects", &LuaDispatch<&LuaWrapper::BruiserLuaListObjects>);      lua_register(LE.GetLuaState(), "xobjregister", &LuaDispatch<&LuaWrapper::BruiserLuaxobjRegister>); +    lua_register(LE.GetLuaState(), "xcall", &LuaDispatch<&LuaWrapper::BruiserLuaCallX>); +    lua_register(LE.GetLuaState(), "xobjlist", &LuaDispatch<&LuaWrapper::BruiserLuaXObjGetList>); +    lua_register(LE.GetLuaState(), "xallocglobal", &LuaDispatch<&LuaWrapper::BruiserLuaXObjAllocGlobal>); +    lua_register(LE.GetLuaState(), "xallocallglobals", &LuaDispatch<&LuaWrapper::BruiserLuaXObjAllocAllGlobals>);      /*its just regisering the List function from LuaWrapper with X-macros.*/  #define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>); diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h index 0dce545..ed7fe85 100644 --- a/bruiser/bruiser.h +++ b/bruiser/bruiser.h @@ -153,7 +153,11 @@ help CMDHelp[] = {    {"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"},    {"xobjwrapper()", "xobjwrapper(\"function\")", "call an xobject", "", "success or failure"}, -  {"xobjregister", "xobjregister(code_table, registration_name)", "registers an xobject as a callable function from lua", "", "pointer to the function"} +  {"xobjregister", "xobjregister(code_table, registration_name)", "registers an xobject as a callable function from lua", "", "pointer to the function"}, +  {"xcall", "xcall(index, num_args)", "call xobj with the given index in to the xobj vector with the given number of args", "", "returns the xobj call result"}, +  {"xobjlist", "xobjlist()", "return a table containing xobj pointers and names. names are keys, values are the pointers.", "", "table of pairs"}, +  {"xallocglobal", "xallocglobal(index)", "allocate a global value with index index", "", ""}, +  {"xallocallglobals", "xallocallglobals()", "allocate all globals", "", ""}  };  /**********************************************************************************************************************/  /** diff --git a/bruiser/executioner.h b/bruiser/executioner.h index 98bd08b..5c04be1 100644 --- a/bruiser/executioner.h +++ b/bruiser/executioner.h @@ -227,6 +227,14 @@ class Executioner {      }      void pusheph(std::function<int(lua_State*)> __eph) {ephs.push_back(__eph);} +    void pushvptr(void* _vptr, std::string _name) {vptrs.push_back(std::make_pair(_vptr, _name));} +    std::vector<std::pair<void*, std::string>> getvptrs(void) {return vptrs;} +    std::pair<void*, std::string> getvptrbyindex(unsigned int _index) { +      if (vptrs.size() - 1 >= _index) { +        return vptrs[_index]; +      } +      return std::make_pair(nullptr, ""); +    }    private:      std::vector<std::pair<void*, size_t>> obj_mem_ptrs; @@ -235,6 +243,7 @@ class Executioner {      std::vector<XObject> xobjs;      std::vector<void*> xvoidptrs;      std::vector<std::function<int(lua_State*)>> ephs; +    std::vector<std::pair<void*, std::string>> vptrs;  };  /**********************************************************************************************************************/  /**********************************************************************************************************************/ @@ -281,6 +290,47 @@ int devi_luareg(lua_State* __ls, xobj_2int __xobj, std::string __name, Execution  #endif  /**********************************************************************************************************************/  /**********************************************************************************************************************/ +class Arguary { +  public: +    Arguary() = default; +    ~Arguary() {} + +    void pass_ptr(void* _arg) {ptr_stack.push_back(_arg);} +    void pass_int(int _arg) {int_stack.push_back(_arg);} +    void pass_uint64(uint64_t _arg) {uint64_stack.push_back(_arg);} +    void pass_string(char* _arg) {string_stack.push_back(_arg);} +    void pass_float(float _arg) {float_stack.push_back(_arg);} +    void pass_double(double _arg) {double_stack.push_back(_arg);} +    void pass_llint(long long int _arg) {llint_stack.push_back(_arg);} +    void clear_arg_stacks(void) { +      ptr_stack.clear(); +      int_stack.clear(); +      uint64_stack.clear(); +      string_stack.clear(); +      float_stack.clear(); +      double_stack.clear(); +      llint_stack.clear(); +    } + +  private: +    std::vector<void*> ptr_stack; +    std::vector<int> int_stack; +    std::vector<uint64_t> uint64_stack; +    std::vector<char*> string_stack; +    std::vector<float> float_stack; +    std::vector<double> double_stack; +    std::vector<long long int> llint_stack; +}; +/**********************************************************************************************************************/ +/**********************************************************************************************************************/ +class XGlobals { +  public: +    XGlobals() {} +    ~XGlobals() {} +  private: +}; +/**********************************************************************************************************************/ +/**********************************************************************************************************************/  #endif  /**********************************************************************************************************************/  /*last line intentionally left blank.*/ diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index eb55acb..0bf26f6 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -12,29 +12,32 @@  -- objload("elf_get_func_code", "../bfd/test/test.so", "code_list")  --  -------------------------------------------------------------------------------------------------------------- +elf_file = "../bfd/test/test.so" +--elf_file = "../bfd/test/test" +  function printObjNames() -  local c = objload("elf_get_obj_names", "../bfd/test/test.so", "symbol_list") +  local c = objload("elf_get_obj_names", elf_file, "symbol_list")    for k,v in ipairs(c) do      print(k,v)    end  end  function printObjSizes() -  local c = objload("elf_get_obj_sizes", "../bfd/test/test.so", "symbol_list") +  local c = objload("elf_get_obj_sizes", elf_file, "symbol_list")    for k,v in ipairs(c) do      print(k,v)    end  end  function printFuncNames() -  local c = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") +  local c = objload("elf_get_func_names", elf_file, "symbol_list")    for k,v in ipairs(c) do      print(k,v)    end  end  function printFuncCode() -  local c = objload("elf_get_func_code", "../bfd/test/test.so", "code_list") +  local c = objload("elf_get_func_code", elf_file, "code_list")    for k,v in ipairs(c) do      print(k,v)      if #v ~= 0 then @@ -47,7 +50,7 @@ function printFuncCode()  end  function findMain() -  local c = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") +  local c = objload("elf_get_func_names", elf_file, "symbol_list")    for k,v in ipairs(c) do      if v == "'main'" then         io.write("main index is".." "..k.."\n") @@ -58,8 +61,8 @@ end  function codeTables()    local return_table = {} -  local func_name_table = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") -  local code_table = objload("elf_get_func_code", "../bfd/test/test.so", "code_list") +  local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") +  local code_table = objload("elf_get_func_code", elf_file, "code_list")    for i=1,#func_name_table,1 do      return_table[func_name_table[i]] = code_table[i]    end @@ -68,8 +71,8 @@ end  function codeTableByName(name)    local return_table = {} -  local func_name_table = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") -  local code_table = objload("elf_get_func_code", "../bfd/test/test.so", "code_list") +  local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") +  local code_table = objload("elf_get_func_code", elf_file, "code_list")    for k,v in ipairs(func_name_table) do      if v == name then        for k1, v1 in ipairs(code_table[k]) do @@ -83,8 +86,8 @@ end  function codeTableByName_number(name)    local return_table = {} -  local func_name_table = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") -  local code_table = objload("elf_get_func_code", "../bfd/test/test.so", "code_list") +  local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") +  local code_table = objload("elf_get_func_code", elf_file, "code_list")    for k,v in ipairs(func_name_table) do      if v == name then        for k1, v1 in ipairs(code_table[k]) do @@ -97,8 +100,8 @@ function codeTableByName_number(name)  end  function printFuncSizes() -  local func_name_table = objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") -  local code_table = objload("elf_get_func_code", "../bfd/test/test.so", "code_list") +  local func_name_table = objload("elf_get_func_names", elf_file, "symbol_list") +  local code_table = objload("elf_get_func_code", elf_file, "code_list")    local counter = 1    print("function sizes:")    for k, v in ipairs(code_table) do @@ -142,6 +145,7 @@ function main()    printFuncSizes() +  pwd()    xobjregister(add2_code, "add2")    xobjregister(sub2_code, "sub2")  end diff --git a/bruiser/makefile b/bruiser/makefile index 680d314..9bc142f 100644 --- a/bruiser/makefile +++ b/bruiser/makefile @@ -17,7 +17,7 @@ EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags)  ######################################RULES####################################  .DEFAULT: all -.PHONY: all clean help $(BRUISER) +.PHONY: all clean help  all: $(BRUISER) | 
