Skip to content

Commit

Permalink
Merge pull request #18 from r-richter/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
r-richter authored Jun 23, 2020
2 parents 2f7a64b + f014d17 commit 6f68918
Show file tree
Hide file tree
Showing 24 changed files with 982 additions and 27 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.9 (Jun. 23rd, 2020)
- Bug fixes
- Code refactoring\
\
[Source Code](https://github.com/r-richter/hyenae-ng/releases/tag/v0.9)

## Version 0.8 (Jun. 21st, 2020)
- Code refactoring
- Enhanced user interface\
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ endif

all :\
common.o\
io.o\
model.o\
model_data_transformations.o\
model_generators.o\
Expand All @@ -48,6 +49,9 @@ all :\
common.o:
$(CXX) $(CXXFLAGS) -c ./src/*.cpp

io.o:
$(CXX) $(CXXFLAGS) -c ./src/io/*.cpp

model.o:
$(CXX) $(CXXFLAGS) -c ./src/model/*.cpp

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Besides switching from C to C++, using modern design concepts, Hyenae NG was
(just like the original Hyenae) written with maximum portability in mind.
Since the original Hyenae had a very complex command line syntax Hyenae NG
comes with a fast and intuitively usable command line menu that will allow
you to effectively set up even complex stress-tests or attacks scenarios
you to effectively set up even complex stress-tests or attack scenarios
within seconds.

![Main Menu](msc/main_menu.png "Main Menu")
Expand Down
22 changes: 20 additions & 2 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace hyenae

/* Methods */

template< class T >
template< class T>
void safe_delete(T*& ptr)
{
if (ptr != NULL)
Expand All @@ -88,7 +88,25 @@ namespace hyenae
}

} /* safe_delete */


template< class T>
void safe_delete(vector_t<T*> pointers)
{
T* current = NULL;

while (pointers.size() > 0)
{
current = pointers.front();
pointers.erase(pointers.begin());

if (current != NULL)
{
delete current;
}
}

} /* free_vector_pointers */

int64_t to_ms(duration_t duration);

string_t to_ms_string(duration_t duration);
Expand Down
115 changes: 115 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Hyenae NG
* Advanced Network Packet Generator (NextGen)
*
* Copyright (C) 2020 Robin Richter
*
* Contact : hyenae.tool@googlemail.com
* Homepage : https://github.com/r-richter/hyenae-ng
*
* This file is part of Hyenae NG.
*
* Hyenae NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hyenae NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hyenae NG. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef CONFIG_H
#define CONFIG_H

#include "common.h"

namespace hyenae
{
/*---------------------------------------------------------------------- */

class config
{
public:
/* Delimiters */
static const char VALUE_ASSIGNER = '=';
static const char VALUE_DELIMITER = ';';
static const char SECTION_ASSIGNER = '{';
static const char SECTION_DELIMITER = '}';

class value
{
private:
string_t _name;
string_t _value;

public:
value(const string_t& name, const string_t& value = "");
string_t get_name() const;
string_t get_value() const;
void set_value(const string_t& value);
string_t to_string() const;

}; /* value */

class section
{
private:
string_t _name;
vector_t<value*> _values;
vector_t<section*> _sub_sections;

public:
section(const string_t& name);
~section();
string_t get_name() const;
size_t value_count() const;
size_t sub_section_count() const;
bool has_value(const string_t& name) const;
bool has_sub_section(const string_t& name) const;
value* value_at(const size_t pos) const;
section* sub_section_at(const size_t pos) const;
value* value_by_name(const string_t& name) const;
section* sub_section_by_name(const string_t& name) const;
config::section* add_sub_section(const string_t& name);
void remove_sub_section(const string_t& name);

config::value* add_value(
const string_t& name, const string_t& value = "");

void remove_value(const string_t& name);
string_t to_string() const;

private:
value* value_by_name(
const string_t& name, bool throw_exception) const;

section* sub_section_by_name(
const string_t& name, bool throw_exception) const;

}; /* section */

private:
section* _root_section;

config(section* root_section);

public:
config(string_t name = "config");
~config();
static config* parse(const string_t& text);
section* get_root_section() const;
string_t to_string();

}; /* config */

/*---------------------------------------------------------------------- */

} /* hyenae */

#endif /* CONFIG_H */
55 changes: 55 additions & 0 deletions include/file_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Hyenae NG
* Advanced Network Packet Generator (NextGen)
*
* Copyright (C) 2020 Robin Richter
*
* Contact : hyenae.tool@googlemail.com
* Homepage : https://github.com/r-richter/hyenae-ng
*
* This file is part of Hyenae NG.
*
* Hyenae NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hyenae NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hyenae NG. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef FILE_IO_H
#define FILE_IO_H

#include "common.h"

namespace hyenae
{
/*---------------------------------------------------------------------- */

class file_io
{
public:
using provider = func_t<file_io*()>;

virtual ~file_io() {}
virtual bool is_open() const = 0;
virtual void open(const string_t& filename, bool overwrite) = 0;
virtual void close() noexcept = 0;
virtual void write(const string_t& content) = 0;
virtual void write(byte_t* data, size_t size) = 0;
virtual string_t read_all() = 0;

}; /* file_io */

/*---------------------------------------------------------------------- */

} /* hyenae */

#endif /* FILE_IO_H */
7 changes: 6 additions & 1 deletion include/frontend/console/console_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef CONSOLE_APP_H
#define CONSOLE_APP_H

#include "../../../include/file_io.h"
#include "../../../include/frontend/console/console_io.h"
#include "../../../include/frontend/console/console_app_state.h"
#include "../../../include/frontend/console/console_app_state_context.h"
Expand All @@ -40,9 +41,13 @@ namespace hyenae::frontend::console
{
private:
console_io* _console_io;
file_io::provider _file_io_provider;

public:
console_app(console_io* console_io);
console_app(
console_io* console_io,
file_io::provider file_io_provider);

int run(int argc, char** argv);

}; /* console_app */
Expand Down
2 changes: 1 addition & 1 deletion include/frontend/console/console_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace hyenae::frontend::console
/* Margins */
static const size_t BASE_MARGIN = 1;
static const size_t MENU_ITEM_MARGIN = 2;
static const size_t MENU_ITEM_INFO_MARGIN = 39;
static const size_t MENU_ITEM_INFO_MARGIN = 38;

/* ANSI Foregrounds */
static const string_t ANSI_FG_RESET;
Expand Down
5 changes: 4 additions & 1 deletion include/frontend/console/states/main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef MAIN_MENU_H
#define MAIN_MENU_H

#include "../../../../include/file_io.h"
#include "../../../../include/frontend/console/console_menu.h"
#include "../../../../include/frontend/console/console_app_state.h"
#include "../../../../include/frontend/console/states/output_setup.h"
Expand Down Expand Up @@ -56,7 +57,9 @@ namespace hyenae::frontend::console::states

public:
main_menu(
console_app_state_context* context, console_io* console_io);
console_app_state_context* context,
console_io* console_io,
file_io::provider file_io_provider);

~main_menu();
bool run();
Expand Down
3 changes: 3 additions & 0 deletions include/frontend/console/states/output_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef OUTPUT_SETUP_H
#define OUTPUT_SETUP_H

#include "../../../../include/file_io.h"
#include "../../../../include/model/data_output.h"
#include "../../../../include/model/outputs/network_output.h"
#include "../../../../include/frontend/console/console_menu.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ namespace hyenae::frontend::console::states
private:
static const char* FILE_OUTPUT_PATH;

file_io::provider _file_io_provider;
network_device_selector* _network_device_selector = NULL;
console_menu* _menu = NULL;
unordered_map_t<console_menu::item*, data_output_t*> _menu_items;
Expand All @@ -68,6 +70,7 @@ namespace hyenae::frontend::console::states
output_setup(
console_app_state_context* context,
console_io* console_io,
file_io::provider file_io_provider,
console_app_state* parent);

~output_setup();
Expand Down
61 changes: 61 additions & 0 deletions include/io/std_file_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Hyenae NG
* Advanced Network Packet Generator (NextGen)
*
* Copyright (C) 2020 Robin Richter
*
* Contact : hyenae.tool@googlemail.com
* Homepage : https://github.com/r-richter/hyenae-ng
*
* This file is part of Hyenae NG.
*
* Hyenae NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hyenae NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hyenae NG. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef STD_FILE_IO_H
#define STD_FILE_IO_H

#include "../file_io.h"

#include <fstream>

namespace hyenae::io
{
/*---------------------------------------------------------------------- */

class std_file_io :
public file_io
{
public:
static const file_io::provider PROVIDER;

private:
std::fstream _stream;

public:
bool is_open() const;
void open(const string_t& filename, bool overwrite);
void close() noexcept;
void write(const string_t& content);
void write(byte_t* data, size_t size);
string_t read_all();

}; /* std_file_io */

/*---------------------------------------------------------------------- */

} /* hyenae::io */

#endif /* STD_FILE_IO_H */
Loading

0 comments on commit 6f68918

Please sign in to comment.