implement lxsh commands + reorder processing order
This commit is contained in:
parent
ad78740636
commit
588aae09e9
3 changed files with 60 additions and 35 deletions
|
|
@ -31,6 +31,7 @@ extern bool b_gotvar, b_gotfct, b_gotcmd;
|
|||
|
||||
/** map get functions (optimizations) **/
|
||||
|
||||
|
||||
// rescans
|
||||
void require_rescan_all();
|
||||
void require_rescan_var();
|
||||
|
|
@ -72,6 +73,7 @@ bool r_delete_var(_obj* in, set_t* vars);
|
|||
|
||||
/** Processing **/
|
||||
|
||||
void insert_lxsh_commands(shmain* sh);
|
||||
void add_unset_variables(shmain* sh, std::regex const& exclude);
|
||||
|
||||
#endif //PROCESSING_HPP
|
||||
|
|
|
|||
41
src/main.cpp
41
src/main.cpp
|
|
@ -187,10 +187,28 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
} // end of argument parse
|
||||
|
||||
if(options["debashify"])
|
||||
// list outputs
|
||||
if(options["list-var"])
|
||||
list_vars(sh, re_var_exclude);
|
||||
else if(options["list-var-def"])
|
||||
list_var_defs(sh, re_var_exclude);
|
||||
else if(options["list-var-call"])
|
||||
list_var_calls(sh, re_var_exclude);
|
||||
else if(options["list-fct"])
|
||||
list_fcts(sh, re_fct_exclude);
|
||||
else if(options["list-cmd"])
|
||||
list_cmds(sh, regex_null);
|
||||
// output
|
||||
else if(options['J'])
|
||||
{
|
||||
debashify(sh);
|
||||
std::cout << gen_json_struc(sh) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// modifiers
|
||||
insert_lxsh_commands(sh);
|
||||
if(options["debashify"])
|
||||
debashify(sh);
|
||||
|
||||
// processing before output
|
||||
// minify
|
||||
|
|
@ -208,19 +226,7 @@ int main(int argc, char* argv[])
|
|||
if(options["unset-var"])
|
||||
add_unset_variables( sh, re_var_exclude );
|
||||
|
||||
// list outputs
|
||||
if(options["list-var"])
|
||||
list_vars(sh, re_var_exclude);
|
||||
else if(options["list-var-def"])
|
||||
list_var_defs(sh, re_var_exclude);
|
||||
else if(options["list-var-call"])
|
||||
list_var_calls(sh, re_var_exclude);
|
||||
else if(options["list-fct"])
|
||||
list_fcts(sh, re_fct_exclude);
|
||||
else if(options["list-cmd"])
|
||||
list_cmds(sh, regex_null);
|
||||
// output
|
||||
else if(options['o']) // file output
|
||||
if(options['o']) // file output
|
||||
{
|
||||
std::string destfile=options['o'];
|
||||
// resolve - to stdout
|
||||
|
|
@ -232,15 +238,12 @@ int main(int argc, char* argv[])
|
|||
if(destfile.substr(0,5) != "/dev/")
|
||||
ztd::exec("chmod", "+x", destfile);
|
||||
}
|
||||
else if(options['J'])
|
||||
{
|
||||
std::cout << gen_json_struc(sh) << std::endl;
|
||||
}
|
||||
else // to console
|
||||
{
|
||||
std::cout << sh->generate(g_shebang, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef NO_PARSE_CATCH
|
||||
catch(ztd::format_error& e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "recursive.hpp"
|
||||
#include "parse.hpp"
|
||||
#include "util.hpp"
|
||||
#include "shellcode.hpp"
|
||||
#include "struc_helper.hpp"
|
||||
|
||||
// Global regex
|
||||
|
||||
|
|
@ -399,6 +401,24 @@ bool r_delete_var(_obj* in, set_t* vars)
|
|||
return true;
|
||||
}
|
||||
|
||||
void insert_lxsh_commands(shmain* sh)
|
||||
{
|
||||
cmdmap_get(sh, regex_null);
|
||||
bool req_rescan=false;
|
||||
for(auto it: lxsh_shellcode_fcts)
|
||||
{
|
||||
if(m_cmds.find(it.first) != m_cmds.end())
|
||||
{
|
||||
sh->lst->insert(0, make_condlist(it.second.code));
|
||||
req_rescan=true;
|
||||
}
|
||||
}
|
||||
if(req_rescan)
|
||||
require_rescan_all();
|
||||
}
|
||||
|
||||
/** JSON **/
|
||||
|
||||
std::string quote_string(std::string const& in)
|
||||
{
|
||||
return '"' + stringReplace(in, "\"", "\\\"") + '"';
|
||||
|
|
|
|||
Loading…
Reference in a new issue