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
|
||||
|
|
|
|||
73
src/main.cpp
73
src/main.cpp
|
|
@ -187,27 +187,6 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
} // end of argument parse
|
||||
|
||||
if(options["debashify"])
|
||||
{
|
||||
debashify(sh);
|
||||
}
|
||||
|
||||
// processing before output
|
||||
// minify
|
||||
if(options['m'])
|
||||
opt_minify=true;
|
||||
if(options["remove-unused"])
|
||||
delete_unused( sh, re_var_exclude, re_fct_exclude );
|
||||
if(options["minify-quotes"])
|
||||
minify_quotes(sh);
|
||||
if(options["minify-var"])
|
||||
minify_var( sh, re_var_exclude );
|
||||
if(options["minify-fct"])
|
||||
minify_fct( sh, re_fct_exclude );
|
||||
// other processing
|
||||
if(options["unset-var"])
|
||||
add_unset_variables( sh, re_var_exclude );
|
||||
|
||||
// list outputs
|
||||
if(options["list-var"])
|
||||
list_vars(sh, re_var_exclude);
|
||||
|
|
@ -220,25 +199,49 @@ int main(int argc, char* argv[])
|
|||
else if(options["list-cmd"])
|
||||
list_cmds(sh, regex_null);
|
||||
// output
|
||||
else if(options['o']) // file output
|
||||
{
|
||||
std::string destfile=options['o'];
|
||||
// resolve - to stdout
|
||||
if(destfile == "-")
|
||||
destfile = "/dev/stdout";
|
||||
// output
|
||||
std::ofstream(destfile) << sh->generate(g_shebang, 0);
|
||||
// don't chmod on /dev/
|
||||
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
|
||||
else
|
||||
{
|
||||
std::cout << sh->generate(g_shebang, 0);
|
||||
// modifiers
|
||||
insert_lxsh_commands(sh);
|
||||
if(options["debashify"])
|
||||
debashify(sh);
|
||||
|
||||
// processing before output
|
||||
// minify
|
||||
if(options['m'])
|
||||
opt_minify=true;
|
||||
if(options["remove-unused"])
|
||||
delete_unused( sh, re_var_exclude, re_fct_exclude );
|
||||
if(options["minify-quotes"])
|
||||
minify_quotes(sh);
|
||||
if(options["minify-var"])
|
||||
minify_var( sh, re_var_exclude );
|
||||
if(options["minify-fct"])
|
||||
minify_fct( sh, re_fct_exclude );
|
||||
// other processing
|
||||
if(options["unset-var"])
|
||||
add_unset_variables( sh, re_var_exclude );
|
||||
|
||||
if(options['o']) // file output
|
||||
{
|
||||
std::string destfile=options['o'];
|
||||
// resolve - to stdout
|
||||
if(destfile == "-")
|
||||
destfile = "/dev/stdout";
|
||||
// output
|
||||
std::ofstream(destfile) << sh->generate(g_shebang, 0);
|
||||
// don't chmod on /dev/
|
||||
if(destfile.substr(0,5) != "/dev/")
|
||||
ztd::exec("chmod", "+x", destfile);
|
||||
}
|
||||
else // to console
|
||||
{
|
||||
std::cout << sh->generate(g_shebang, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef NO_PARSE_CATCH
|
||||
|
|
|
|||
|
|
@ -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