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 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'bruiser/bruiser.cpp') 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; } -- cgit v1.2.3