From d7f4a97c10813eb4f8e8a31064deedbf0d7d2a8b Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Tue, 2 Jan 2018 22:42:05 +0330 Subject: load.py now loads all objects and functions along with names to c++. next is getting them to lua. --- bruiser/bruiser.cpp | 34 ++++++++++++++++++------------- bruiser/executioner.h | 11 +++++++--- bruiser/lua-scripts/demo1.lua | 47 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 19 deletions(-) (limited to 'bruiser') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 8934867..cd52603 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -283,7 +283,8 @@ class PyExec { tempvec.push_back(int(byte)); } } - if (!tempvec.empty()) {hexobj.push_back(tempvec);} + //if (!tempvec.empty()) {hexobj.push_back(tempvec);} + hexobj.push_back(tempvec); tempvec.clear(); } } @@ -305,9 +306,8 @@ class PyExec { } } - std::vector> exportObjs(void) { - return hexobj; - } + std::vector> exportObjs(void) {return hexobj;} + std::vector exportStrings(void) {return hexobj_str;} private: std::string py_script_name; @@ -1183,6 +1183,7 @@ class LuaWrapper funcname = lua_tostring(__ls, 1); objjpath = lua_tostring(__ls, 2); action = lua_tostring(__ls, 3); + lua_pop(__ls, 3); } else { std::cout << RED << "wrong number of arguments provided. should give the python script name, python func name and its args.\n" << NORMAL; @@ -1191,18 +1192,15 @@ 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) - { + if (pid < 0) { PRINT_WITH_COLOR_LB(RED, "could not fork..."); lua_pushnumber(__ls, EXIT_FAILURE); } - if (pid == 0) - { + if (pid == 0) { std::cout << BLUE << "running load.py: " << NORMAL << "\n"; py.run(); if (action == "code_list") { @@ -1212,20 +1210,28 @@ class LuaWrapper else if (action == "symbol_list") { py.getAsCppStringVec(); } + + lua_newtable(__ls); + int tableindex = 0 ; + for (auto& iter : py.exportStrings()) { + lua_pushnumber(__ls, tableindex); + tableindex++; + lua_pushstring(__ls, iter.c_str()); + lua_settable(__ls, 1); + } //py.killPyObj(); - lua_pushnumber(__ls, 0); + //lua_pushnumber(__ls, 0); exit(EXIT_SUCCESS); } - if (pid > 0) - { + if (pid > 0) { int status; pid_t returned; returned = waitpid(pid, &status, 0); - lua_pushnumber(__ls, returned); + //lua_pushnumber(__ls, returned); } - lua_pushnumber(__ls, 0); + //lua_pushnumber(__ls, 0); return 1; } diff --git a/bruiser/executioner.h b/bruiser/executioner.h index b881902..4b8b651 100644 --- a/bruiser/executioner.h +++ b/bruiser/executioner.h @@ -19,6 +19,9 @@ 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 "./bruiser.h" +#include "lua-5.3.4/src/lua.hpp" + #include #include #include @@ -27,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include #include #include -#include "lua-5.3.4/src/lua.hpp" /**********************************************************************************************************************/ #ifndef EXECUTIONER_H #define EXECUTIONER_H @@ -68,7 +70,7 @@ namespace { // start of anonymous namespace 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."); + 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 @@ -79,8 +81,10 @@ namespace { // start of anonymous namespace else if (lua_type(__ls, i) == LUA_TLIGHTUSERDATA) { } else if (lua_type(__ls, i) == LUA_TNUMBER) { + arg_double.push_back(std::make_pair(lua_tonumber(__ls, i), i)); } else if (lua_type(__ls, i) == LUA_TSTRING) { + arg_str.push_back(std::make_pair(lua_tostring(__ls, i), i)); } else if (lua_type(__ls, i) == LUA_TTABLE) { } @@ -92,12 +96,13 @@ namespace { // start of anonymous namespace } // type is Nil else { + PRINT_WITH_COLOR_LB(RED, "you passed a Nil argument..."); } } pid_t pid = fork(); if (pid < 0) { - //PRINT_WITH_COLOR_LB(RED, "could not fork..."); + PRINT_WITH_COLOR_LB(RED, "could not fork..."); lua_pushnumber(__ls, EXIT_FAILURE); } if (pid == 0) {} diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua index 98bdb0d..b382f2d 100644 --- a/bruiser/lua-scripts/demo1.lua +++ b/bruiser/lua-scripts/demo1.lua @@ -1,2 +1,45 @@ -objload("elf_get_func_names", "../bfd/test/test.so", "symbol_list") -objload("main2", "../bfd/test/test.so", "code_list") +-- +-- get the .so object names +-- objload("elf_get_obj_names", "../bfd/test/test.so", "symbol_list") +-- +-- get the .so object sizes +-- objload("elf_get_obj_sizes", "../bfd/test/test.so", "symbol_list") +-- +-- 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")} + 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")} + 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")} + 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")} + for k,v in ipairs(c) do + print(k,v) + end +end + +printObjNames() +printObjSizes() +printFuncNames() +--printFuncCode() -- cgit v1.2.3