diff options
author | bloodstalker <thabogre@gmail.com> | 2018-01-08 09:34:13 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-01-08 09:34:13 +0000 |
commit | bd4853e224818bb4ff21e56b386a2616020ee693 (patch) | |
tree | 6f31e3dd8d8b181f55efd39c0d78c9d94efbc396 /bruiser | |
parent | load.py now loads all objects and functions along with names to c++. next is ... (diff) | |
download | mutator-bd4853e224818bb4ff21e56b386a2616020ee693.tar.gz mutator-bd4853e224818bb4ff21e56b386a2616020ee693.zip |
the function code, function name, var names and var sized are now being returned to lua as tables.
Diffstat (limited to 'bruiser')
-rw-r--r-- | bruiser/bruiser.cpp | 62 | ||||
-rw-r--r-- | bruiser/lua-scripts/demo1.lua | 16 |
2 files changed, 44 insertions, 34 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index cd52603..90a05da 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -259,7 +259,7 @@ class PyExec { PyObject* pyrepr = PyObject_Repr(pybytes); PyObject* pyunicode = PyUnicode_AsEncodedString(pyrepr, "utf-8", "surrogateescape"); const char* dummy = PyBytes_AsString(pyunicode); - std::cout << RED << dummy << "\n" << NORMAL; + //std::cout << RED << dummy << "\n" << NORMAL; hexobj_str.push_back(std::string(dummy)); } } @@ -1192,46 +1192,50 @@ class LuaWrapper std::cout << CYAN << "initing the py embed class...\n" << NORMAL; PyExec py(filename.c_str(), funcname.c_str(), objjpath.c_str()); - std::cout << CYAN << "forking python script...\n" << NORMAL; - pid_t pid = fork(); - if (pid < 0) { - PRINT_WITH_COLOR_LB(RED, "could not fork..."); - lua_pushnumber(__ls, EXIT_FAILURE); - } + std::cout << BLUE << "running load.py: " << NORMAL << "\n"; + py.run(); + if (action == "code_list") { + py.getAsCppByte(); + //py.printHexObjs(); - if (pid == 0) { - std::cout << BLUE << "running load.py: " << NORMAL << "\n"; - py.run(); - if (action == "code_list") { - py.getAsCppByte(); - py.printHexObjs(); + int tableindex1 = 1; + int tableindex2 = 1; + // the return type to lua is a table of tables + lua_newtable(__ls); + if (!lua_checkstack(__ls, py.exportObjs().size() * 2)) { + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); } - else if (action == "symbol_list") { - py.getAsCppStringVec(); + for (auto& iter : py.exportObjs()) { + lua_pushnumber(__ls, tableindex1); + lua_newtable(__ls); + for (auto& iterer : iter) { + lua_pushnumber(__ls, tableindex2); + tableindex2++; + lua_pushnumber(__ls, iterer); + lua_settable(__ls, -3); + } + tableindex2 = 1; + tableindex1++; + lua_settable(__ls, -3); } - + } + else if (action == "symbol_list") { + py.getAsCppStringVec(); + int tableindex = 1 ; + // the return type to lua is a table lua_newtable(__ls); - int tableindex = 0 ; + if (!lua_checkstack(__ls, py.exportStrings().size() * 2)) { + PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small."); + } for (auto& iter : py.exportStrings()) { lua_pushnumber(__ls, tableindex); tableindex++; lua_pushstring(__ls, iter.c_str()); - lua_settable(__ls, 1); + lua_settable(__ls, -3); } - //py.killPyObj(); - //lua_pushnumber(__ls, 0); - exit(EXIT_SUCCESS); - } - - if (pid > 0) { - int status; - pid_t returned; - returned = waitpid(pid, &status, 0); - //lua_pushnumber(__ls, returned); } - //lua_pushnumber(__ls, 0); return 1; } diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index b382f2d..cb912b8 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -7,39 +7,45 @@ -- -- get the .so function names -- objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") +-- -- get the .so function code -- objload("elf_get_func_code", "../bfd/test/test.so", "code_list") -- function printObjNames() - local c = {objload("elf_get_obj_names", "../bfd/test/test.so", "symbol_list")} + local c = objload("elf_get_obj_names", "../bfd/test/test.so", "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", "../bfd/test/test.so", "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", "../bfd/test/test.so", "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", "../bfd/test/test.so", "code_list") for k,v in ipairs(c) do print(k,v) + if #v ~= 0 then + for k1,v1 in ipairs(v) do + print(k1, v1) + end + end end end printObjNames() printObjSizes() printFuncNames() ---printFuncCode() +printFuncCode() |