add string parse minifying
This commit is contained in:
parent
af5d276ff0
commit
1f75f18fba
8 changed files with 80 additions and 15 deletions
8
Makefile
8
Makefile
|
|
@ -18,17 +18,21 @@ CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++20
|
||||||
ifeq ($(DEBUG),true)
|
ifeq ($(DEBUG),true)
|
||||||
# debugging flags
|
# debugging flags
|
||||||
CC=clang++
|
CC=clang++
|
||||||
CXXFLAGS += -g -pg -D NO_PARSE_CATCH
|
CXXFLAGS += -g -D NO_PARSE_CATCH
|
||||||
else
|
else
|
||||||
# release flags
|
# release flags
|
||||||
CXXFLAGS += -Ofast
|
CXXFLAGS += -Ofast
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PROFILE),true)
|
||||||
|
CXXFLAGS += -pg
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(RELEASE), true)
|
ifneq ($(RELEASE), true)
|
||||||
VSUFFIX=-dev-$(SHA_SHORT)
|
VSUFFIX=-dev-$(SHA_SHORT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(STATIC),true)
|
ifeq ($(STATIC),true)
|
||||||
# static links
|
# static links
|
||||||
LDFLAGS += -l:libztd.a
|
LDFLAGS += -l:libztd.a
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -76,4 +76,6 @@ bool r_delete_var(_obj* in, set_t* vars);
|
||||||
std::set<std::string> find_lxsh_commands(shmain* sh);
|
std::set<std::string> find_lxsh_commands(shmain* sh);
|
||||||
void add_unset_variables(shmain* sh, std::regex const& exclude);
|
void add_unset_variables(shmain* sh, std::regex const& exclude);
|
||||||
|
|
||||||
|
void string_processors(_obj* in);
|
||||||
|
|
||||||
#endif //PROCESSING_HPP
|
#endif //PROCESSING_HPP
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef VERSION_H
|
#ifndef VERSION_H
|
||||||
#define VERSION_H
|
#define VERSION_H
|
||||||
|
|
||||||
#define VERSION_STRING "v1.1.0"
|
#define VERSION_STRING "v1.2.0"
|
||||||
|
|
||||||
#endif //VERSION_H
|
#endif //VERSION_H
|
||||||
|
|
|
||||||
|
|
@ -205,10 +205,6 @@ pid_t forkexec(const char* bin, char *const args[])
|
||||||
}
|
}
|
||||||
if (child_pid == 0) // child process
|
if (child_pid == 0) // child process
|
||||||
{
|
{
|
||||||
// char buf[1000] = {0};
|
|
||||||
// read(STDIN_FILENO, buf, 1000);
|
|
||||||
// std::cout << std::string(buf) << std::endl;
|
|
||||||
// std::cout << dup2(tfd, STDIN_FILENO) << std::endl;
|
|
||||||
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
|
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
|
||||||
execv(bin, args);
|
execv(bin, args);
|
||||||
throw std::runtime_error("execv() failed");
|
throw std::runtime_error("execv() failed");
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,10 @@ int main(int argc, char* argv[])
|
||||||
// processing before output
|
// processing before output
|
||||||
// minify
|
// minify
|
||||||
if(options['m'])
|
if(options['m'])
|
||||||
|
{
|
||||||
opt_minify=true;
|
opt_minify=true;
|
||||||
|
string_processors(sh);
|
||||||
|
}
|
||||||
if(options["minify-quotes"])
|
if(options["minify-quotes"])
|
||||||
minify_quotes(sh);
|
minify_quotes(sh);
|
||||||
if(options["minify-var"])
|
if(options["minify-var"])
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "shellcode.hpp"
|
#include "shellcode.hpp"
|
||||||
#include "struc_helper.hpp"
|
#include "struc_helper.hpp"
|
||||||
|
#include "options.hpp"
|
||||||
|
#include "minify.hpp"
|
||||||
|
|
||||||
|
#include "errcodes.h"
|
||||||
|
|
||||||
// Global regex
|
// Global regex
|
||||||
|
|
||||||
|
|
@ -415,6 +419,66 @@ std::set<std::string> find_lxsh_commands(shmain* sh)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<std::string> get_processors(std::string const& in)
|
||||||
|
{
|
||||||
|
std::set<std::string> ret;
|
||||||
|
if(in.size()>2 && in[0] == '\'' && in[in.size()-1] == '\'')
|
||||||
|
{
|
||||||
|
uint32_t i=1;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
std::string ln = in.substr(i, in.find('\n', i)-i);
|
||||||
|
if(ln.size()>1 && ln[0] == '#' && is_alphanum(ln[1]))
|
||||||
|
{
|
||||||
|
i+=ln.size();
|
||||||
|
ret.insert(get_word(ln.c_str(), ln.size(), 1, SEPARATORS).first);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool r_do_string_processor(_obj* in)
|
||||||
|
{
|
||||||
|
if(in->type == _obj::subarg_string)
|
||||||
|
{
|
||||||
|
string_subarg* t = dynamic_cast<string_subarg*>(in);
|
||||||
|
auto v = get_processors(t->val);
|
||||||
|
if(v.find("LXSH_PARSE_MINIFY") != v.end())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
shmain* tsh = parse_text(t->val.substr(1, t->val.size()-2));
|
||||||
|
require_rescan_all();
|
||||||
|
if(options["remove-unused"])
|
||||||
|
delete_unused( tsh, re_var_exclude, re_fct_exclude );
|
||||||
|
if(options["minify-quotes"])
|
||||||
|
minify_quotes(tsh);
|
||||||
|
if(options["minify-var"])
|
||||||
|
minify_var( tsh, re_var_exclude );
|
||||||
|
if(options["minify-fct"])
|
||||||
|
minify_fct( tsh, re_fct_exclude );
|
||||||
|
require_rescan_all();
|
||||||
|
t->val='\'' + tsh->generate(false, 0) + '\'';
|
||||||
|
}
|
||||||
|
catch(ztd::format_error& e) // if fail: skip processing
|
||||||
|
{
|
||||||
|
std::cerr << "Exception caused in string processing LXSH_PARSE_MINIFY\n";
|
||||||
|
printFormatError(e);
|
||||||
|
exit(ERR_RUNTIME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void string_processors(_obj* in)
|
||||||
|
{
|
||||||
|
recurse(r_do_string_processor, in);
|
||||||
|
}
|
||||||
|
|
||||||
/** JSON **/
|
/** JSON **/
|
||||||
|
|
||||||
std::string quote_string(std::string const& in)
|
std::string quote_string(std::string const& in)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ bool add_include(std::string const& file)
|
||||||
if(it == truepath)
|
if(it == truepath)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// std::cout << truepath << std::endl;
|
|
||||||
included.push_back(truepath);
|
included.push_back(truepath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/util.cpp
11
src/util.cpp
|
|
@ -236,14 +236,11 @@ void printErrorIndex(const char* in, const int index, const std::string& message
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(origin != "")
|
fprintf(stderr, "%s:%u:%u: %s\n", origin.c_str(), line, index-j+1, message.c_str());
|
||||||
|
if(print_line)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s:%u:%u: %s\n", origin.c_str(), line, index-j+1, message.c_str());
|
std::cerr << std::string(in+j, i-j) << std::endl;
|
||||||
if(print_line)
|
std::cerr << repeatString(" ", index-j) << '^' << std::endl;
|
||||||
{
|
|
||||||
std::cerr << std::string(in+j, i-j) << std::endl;
|
|
||||||
std::cerr << repeatString(" ", index-j) << '^' << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue