Skip to content

Commit

Permalink
Added main.h
Browse files Browse the repository at this point in the history
  • Loading branch information
oxagast committed Feb 12, 2017
1 parent 0ceddd0 commit 49d3b0b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bin_PROGRAMS = ansvif find_suid faulty
endif
noinst_LIBRARIES = libgzstream.a
libgzstream_a_SOURCES = include/gzstream/gzstream.h include/gzstream/gzstream.C
ansvif_SOURCES = src/common.cpp src/linux/bin2hex.cpp src/linux/bin2hex_pc.cpp src/linux/popen2.cpp src/linux/main.cpp src/linux/help.cpp src/match_seg.cpp src/linux/sys_string.cpp src/linux/sys_string_pc.cpp src/linux/man_read.cpp src/trash.cpp src/randomizer.cpp include/gzstream/gzstream.h include/xmlwriter/xml_writer.hpp
ansvif_SOURCES = src/common.cpp src/linux/bin2hex.cpp src/linux/bin2hex_pc.cpp src/linux/popen2.cpp src/linux/main.cpp src/linux/help.cpp src/match_seg.cpp src/linux/sys_string.cpp src/linux/sys_string_pc.cpp src/linux/man_read.cpp src/trash.cpp src/randomizer.cpp include/gzstream/gzstream.h include/xmlwriter/xml_writer.hpp src/linux/main.h
if OS_IS_REDHAT
ansvif_LDADD = -lgzstream -lcryptopp -lstdc++ -lpthread -lz -L.
else
Expand All @@ -19,7 +19,7 @@ ansvif_CPPFLAGS = -O3 -D __REDHAT
else
ansvif_CPPFLAGS = -O3 -D __DEBIAN
endif
ansvif_LDFLAGS = -I./include/gzstream -I./include/xml_writer
ansvif_LDFLAGS = -I./include/gzstream -I./include/xml_writer -I./src/linux
find_suid_SOURCES = src/linux/find_suid.cpp
faulty_SOURCES = src/faulty.c
faulty_CFLAGS = -ansi -fno-stack-protector
Expand Down
11 changes: 6 additions & 5 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>
#include <signal.h>
#include <random>
#include "src/linux/main.h"

#define READ 0
#define WRITE 1
Expand All @@ -39,8 +40,8 @@ bool match_seg(int buf_size, std::vector<std::string> opts,
std::string junk_file_of_args, std::string always_arg_before,
std::string always_arg_after, bool never_rand,
std::string run_command, std::string fault_code, bool single_try,
bool percent_sign, int static_args, bool verbose, bool debug, std::string ver);
void help_me(std::string mr_me, std::string ver);
bool percent_sign, int static_args, bool verbose, bool debug);
void help_me(std::string mr_me);
std::vector<std::string> get_flags_man(std::string man_page,
std::string man_loc, bool verbose,
bool debug, bool dump_opts);
Expand All @@ -65,15 +66,15 @@ std::string remove_chars(const std::string &source, const std::string &chars) {
return(result);
}

int toint(std::string ints, std::string my_prog, std::string version) {
int toint(std::string ints, std::string my_prog) {
std::istringstream b_size(ints);
int is_int_b_s;
if (!(b_size >> is_int_b_s)) {
help_me(my_prog, version);
help_me(my_prog);
}
char buf_char_maybe_b_s;
if (b_size >> buf_char_maybe_b_s) {
help_me(my_prog, version);
help_me(my_prog);
} else {
/* for compatibility with cygwin */
return atoi(ints.c_str());
Expand Down
3 changes: 2 additions & 1 deletion src/linux/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <iostream>
#include <stdio.h>
#include <string>
#include "src/linux/main.h"

void help_me(std::string mr_me, std::string ver) {
void help_me(std::string mr_me) {
std::cout
<< "ansvif v" << ver << " -- A Not So Very Intelligent Fuzzer"
<< std::endl
Expand Down
45 changes: 21 additions & 24 deletions src/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <thread>
#include <unistd.h>
#include <vector>
#include "src/linux/main.h"

int toint(std::string ints, std::string my_prog, std::string version);
void help_me(std::string mr_me, std::string ver);
int toint(std::string ints, std::string my_prog);
void help_me(std::string mr_me);
std::vector<std::string> get_flags_man(std::string man_page,
std::string man_loc, bool verbose,
bool debug, bool dump_opts);
Expand All @@ -35,8 +36,7 @@ bool match_seg(int buf_size, std::vector<std::string> opts,
std::string junk_file_of_args, std::string always_arg_before,
std::string always_arg_after, bool never_rand,
std::string run_command, std::string fault_code, bool valgrind,
bool single_try, bool percent_sign, int static_args, bool verbose, bool debug,
std::string ver);
bool single_try, bool percent_sign, int static_args, bool verbose, bool debug);
std::vector<std::string> get_flags_template(std::string filename, bool verbose,
bool debug);
std::vector<std::string> get_other(std::string filename, bool verbose,
Expand All @@ -45,7 +45,7 @@ void write_seg(std::string filename, std::string seg_line);

/* globals to be passed to sig_handler because its easier this way */
std::string write_file_n, junk_file_of_args;

std::string ver = "1.6.2"; /* ansvif version */
void sig_handler(int sig) {
/* flush the screen buffer then sleep before printing
* the message about killing threads
Expand Down Expand Up @@ -120,8 +120,7 @@ int main(int argc, char *argv[]) { // initialize our main
write_to_file = false, u_strip_shell_set = false, verbose = false,
debug = false, is_other = false, dump_opts = false, never_rand = false,
valgrind = false, single_try = false, percent_sign = false;
/* what version of ansvif are we running? */
std::string ver = "1.6.2";

/* first off we're going to start the signal handler incase they
* do ctrl+c or something
*/
Expand Down Expand Up @@ -165,7 +164,7 @@ int main(int argc, char *argv[]) { // initialize our main
write_file_n = optarg;
break;
case 'h':
help_me(argv[0], ver);
help_me(argv[0]);
break;
case 'r':
rand_all = true;
Expand Down Expand Up @@ -221,13 +220,13 @@ int main(int argc, char *argv[]) { // initialize our main
percent_sign = true;
break;
case 'M':
static_args = toint(optarg, argv[0], ver);
static_args = toint(optarg, argv[0]);
break;
case 'y':
buf_size_int = 0;
break;
default:
help_me(argv[0], ver);
help_me(argv[0]);
}
}
if (u_strip_shell_set == true) {
Expand All @@ -244,44 +243,44 @@ int main(int argc, char *argv[]) { // initialize our main
/* send them to help because you can't have a manpage and
* a template at the same time
*/
help_me(argv[0], ver);
help_me(argv[0]);
} else if ((man_opt == false) && (template_opt == false)) {
/* can't fuzz if we don't have a template or manpage as
* a starting point, if you want nothing just touch a file
* and use it as a template
*/
help_me(argv[0], ver);
help_me(argv[0]);
} else if (path_str == "") {
/* if they didn't specify a command path then error out */
help_me(argv[0], ver);
help_me(argv[0]);
} else {
/* like if the option they supplied doesn't exist... */
help_me(argv[0], ver);
help_me(argv[0]);
}
if ((junk_file_of_args != "") && (is_other == false)) {
/* this will fix the -F no -x bug */
help_me(argv[0], ver);
help_me(argv[0]);
}
/* make sure the buffer size is really an integar and if it
* happens to not be, then we'll send them to the help page,
* otherwise we'll turn it into type int
*/
if ((buf_size_int == 0) && (buf_size != "")) {
help_me(argv[0], ver);
help_me(argv[0]);
}
if ((buf_size_int == -1) && (buf_size != "")) {
buf_size_int = toint(buf_size, argv[0], ver);
buf_size_int = toint(buf_size, argv[0]);
}
if (buf_size_int == -1) {
help_me(argv[0], ver);
help_me(argv[0]);
}
/* make sure the thread count is an integar the same way
* we did with the buffer size
*/
int thread_count_int = thread_count_def;
thread_count_int = toint(num_threads, argv[0], ver);
thread_count_int = toint(num_threads, argv[0]);
int thread_timeout_int = thread_timeout_def;
thread_timeout_int = toint(t_timeout, argv[0], ver);
thread_timeout_int = toint(t_timeout, argv[0]);
/* if we're not doing a single try then turn on
* threading
*/
Expand All @@ -295,8 +294,7 @@ int main(int argc, char *argv[]) { // initialize our main
is_other, other_sep, thread_timeout_int, low_lvl_user,
junk_file_of_args, always_arg_before, always_arg_after,
never_rand, run_command, fault_code, valgrind, single_try,
percent_sign, static_args, verbose, debug,
ver));
percent_sign, static_args, verbose, debug));
/* thrift shop */
for (auto &all_thread : threads)
all_thread.join();
Expand All @@ -311,8 +309,7 @@ int main(int argc, char *argv[]) { // initialize our main
is_other, other_sep, thread_timeout_int, low_lvl_user,
junk_file_of_args, always_arg_before, always_arg_after,
never_rand, run_command, fault_code, valgrind, single_try,
percent_sign, static_args, verbose, debug,
ver);
percent_sign, static_args, verbose, debug);
}
/* exit cleanly! */
exit(0);
Expand Down
8 changes: 8 additions & 0 deletions src/linux/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef main_h
#define main_h

#include <string>
/* what version of ansvif are we running? */
extern std::string ver;

#endif
3 changes: 2 additions & 1 deletion src/match_seg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <thread>
#include <unistd.h>
#include <vector>
#include "src/linux/main.h"

std::string remove_chars(const std::string &source, const std::string &chars);
int reaper(int grim, int t_timeout);
Expand Down Expand Up @@ -66,7 +67,7 @@ bool match_seg(int buf_size, std::vector<std::string> opts,
std::string always_arg_after, bool never_rand,
std::string run_command, std::string fault_code, bool valgrind,
bool single_try, bool percent_sign, int static_args,
bool verbose, bool debug, std::string ver) {
bool verbose, bool debug) {
bool segged = false;
std::vector<std::string> used_token;
std::string valgrind_str;
Expand Down

0 comments on commit 49d3b0b

Please sign in to comment.