add --no-extend option + rename --help-lxsh-commands to --help-extend-fcts

This commit is contained in:
zawz 2021-03-26 15:59:22 +01:00
parent baadd1d927
commit a1b2d74940
4 changed files with 51 additions and 45 deletions

9
include/errcodes.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef ERRCODES_H
#define ERRCODES_H
#define ERR_HELP 1001
#define ERR_OPT 1002
#define ERR_PARSE 1003
#define ERR_RUNTIME 1004
#endif //ERRCODES_H

View file

@ -11,7 +11,7 @@ extern bool g_include;
extern bool g_resolve; extern bool g_resolve;
extern bool g_shebang; extern bool g_shebang;
void print_lxsh_cmd_help(); void print_lxsh_extension_help();
void get_opts(); void get_opts();
@ -39,4 +39,6 @@ options:
*/ */
ztd::option_set create_resolve_opts(); ztd::option_set create_resolve_opts();
void oneshot_opt_process(const char* arg0);
#endif //OPTIONS_HPP #endif //OPTIONS_HPP

View file

@ -19,40 +19,7 @@
#include "exec.hpp" #include "exec.hpp"
#include "shellcode.hpp" #include "shellcode.hpp"
#include "version.h" #include "errcodes.h"
#include "g_version.h"
#define ERR_HELP 1001
#define ERR_OPT 1002
#define ERR_PARSE 1003
#define ERR_RUNTIME 1004
void oneshot_opt_process(const char* arg0)
{
if(options['h'])
{
print_help(arg0);
exit(ERR_HELP);
}
else if(options["version"])
{
printf("%s %s%s\n", arg0, VERSION_STRING, VERSION_SUFFIX);
printf("%s\n", VERSION_SHA);
exit(0);
}
else if(options["help-link-commands"])
{
print_include_help();
printf("\n\n");
print_resolve_help();
exit(ERR_HELP);
}
else if(options["help-lxsh-commands"])
{
print_lxsh_cmd_help();
exit(ERR_HELP);
}
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
@ -160,13 +127,9 @@ int main(int argc, char* argv[])
if(is_exec) if(is_exec)
{ {
if(options["debashify"]) if(options["debashify"])
{
shebang = "#!/bin/sh"; shebang = "#!/bin/sh";
}
if(options["debashify"] || basename(shebang) == "bash") if(options["debashify"] || basename(shebang) == "bash")
{
g_bash = true; g_bash = true;
}
args.erase(args.begin()); args.erase(args.begin());
return exec_process(shebang.substr(2), args, filecontents, file); return exec_process(shebang.substr(2), args, filecontents, file);
} }
@ -213,7 +176,7 @@ int main(int argc, char* argv[])
// post-listing modifiers // post-listing modifiers
// implement commands // implement commands
std::set<std::string> req_fcts; std::set<std::string> req_fcts;
if(shebang_is_bin) if(shebang_is_bin && !options["no-extend"])
req_fcts = find_lxsh_commands(sh); req_fcts = find_lxsh_commands(sh);
if(options["debashify"]) if(options["debashify"])
concat_sets(req_fcts, debashify(sh) ); concat_sets(req_fcts, debashify(sh) );

View file

@ -3,6 +3,10 @@
#include "processing.hpp" #include "processing.hpp"
#include "shellcode.hpp" #include "shellcode.hpp"
#include "errcodes.h"
#include "version.h"
#include "g_version.h"
ztd::option_set options = gen_options(); ztd::option_set options = gen_options();
bool opt_minify=false; bool opt_minify=false;
@ -18,8 +22,8 @@ ztd::option_set gen_options()
ztd::option("\r [Help]"), ztd::option("\r [Help]"),
ztd::option('h', "help", false, "Display this help message"), ztd::option('h', "help", false, "Display this help message"),
ztd::option("version", false, "Display version"), ztd::option("version", false, "Display version"),
ztd::option("help-link-commands", false, "Print help for special lxsh commands"), ztd::option("help-link-commands", false, "Print help for linker commands"),
ztd::option("help-lxsh-commands", false, "Print help for linker commands"), ztd::option("help-extend-fcts", false, "Print help for lxsh extension functions"),
ztd::option("\r [Output]"), ztd::option("\r [Output]"),
ztd::option('o', "output", true , "Output result script to file", "file"), ztd::option('o', "output", true , "Output result script to file", "file"),
ztd::option('c', "stdout", false, "Output result script to stdout"), ztd::option('c', "stdout", false, "Output result script to stdout"),
@ -33,6 +37,7 @@ ztd::option_set gen_options()
ztd::option('C', "no-cd", false, "Don't cd when doing %include and %resolve"), ztd::option('C', "no-cd", false, "Don't cd when doing %include and %resolve"),
ztd::option('I', "no-include", false, "Don't resolve %include commands"), ztd::option('I', "no-include", false, "Don't resolve %include commands"),
ztd::option('R', "no-resolve", false, "Don't resolve %resolve commands"), ztd::option('R', "no-resolve", false, "Don't resolve %resolve commands"),
ztd::option("no-extend", false, "Don't add lxsh extension functions"),
ztd::option("debashify", false, "Attempt to turn a bash-specific script into a POSIX shell script"), ztd::option("debashify", false, "Attempt to turn a bash-specific script into a POSIX shell script"),
ztd::option("\r [var/fct processing]"), ztd::option("\r [var/fct processing]"),
ztd::option("minify-var", false, "Minify variable names"), ztd::option("minify-var", false, "Minify variable names"),
@ -133,10 +138,37 @@ void print_resolve_help()
opts.print_help(3,7); opts.print_help(3,7);
} }
void print_lxsh_cmd_help() void print_lxsh_extension_help()
{ {
for(auto it: lxsh_extend_fcts) for(auto it: lxsh_extend_fcts)
{ {
printf("%s %s\n%s\n\n", it.first.c_str(), it.second.arguments.c_str(), it.second.description.c_str()); printf("%s %s\n%s\n\n", it.first.c_str(), it.second.arguments.c_str(), it.second.description.c_str());
} }
} }
void oneshot_opt_process(const char* arg0)
{
if(options['h'])
{
print_help(arg0);
exit(ERR_HELP);
}
else if(options["version"])
{
printf("%s %s%s\n", arg0, VERSION_STRING, VERSION_SUFFIX);
printf("%s\n", VERSION_SHA);
exit(0);
}
else if(options["help-link-commands"])
{
print_include_help();
printf("\n\n");
print_resolve_help();
exit(ERR_HELP);
}
else if(options["help-extend-fcts"])
{
print_lxsh_extension_help();
exit(ERR_HELP);
}
}