Esempio n. 1
0
def main(argv):
    (command, episodes, season) = cmd_parse(argv)

    file_manager = FileManager(HP["game"], season)
    env = gym.make(HP["game"])
    if command == 'record':
        env = gym.wrappers.Monitor(env,
                                   "{}/recording".format(file_manager.cwd),
                                   force=True)
    agent = SpaceInvadersAgent(file_manager.cwd, env.action_space.n,
                               HP["alpha"], HP["epsilon"], HP["epsilon_min"],
                               HP["epsilon_drop"], HP["gamma"],
                               HP["num_neurons"], HP["mem_cap"],
                               HP["recall_size"], HP["update_weight_freq"])
    game_master = GameMaster(env, agent)
    analyzer = Analyzer(file_manager.cwd)

    if command == 'train':
        training_digest = game_master.run_season(season,
                                                 episodes,
                                                 training=True)
        file_manager.save(training_digest.facts, 'training-digest.json')
        file_manager.save(HP, 'hyperparameters.json')
        analyzer.create_graphs(training_digest, 'training')
    elif command == 'analyze':
        digest = game_master.run_season(season, episodes, training=False)
        file_manager.save(digest.facts, 'analyze-digest.json')
        analyzer.create_graphs(digest, 'analyze')
    elif command == 'record':
        digest = game_master.run_season(season, 1, training=False)

    env.close()
Esempio n. 2
0
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

from lib.analyzer import Analyzer

import argparse

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='D4-IPA')
    parser.add_argument('-p',
                        '--path',
                        type=str,
                        nargs=1,
                        help='Path of local dataset.')

    dataset = None

    args = parser.parse_args()
    if args.path:
        dataset = args.path[0]

    ipa = Analyzer(dataset_path=dataset)
Esempio n. 3
0
    def __init__(self, ctx):
        self.ctx = ctx
        ctx.vim = False

        self.COMMANDS_ALPHA = [
            "analyzer",
            "da",
            "db",
            "dd",
            "dw",
            "dq",
            "dump",
            "exit",
            "functions",
            "help",
            "history",
            "info",
            "jmptable",
            "load",
            "lrawarm",
            "lrawmips",
            "lrawmips64",
            "lrawx86",
            "lrawx64",
            "mips_set_gp",
            "py",
            "save",
            "sections",
            "sym",
            "x",
            "v",
            "display.print_section",
            "display.print_comments",
            "xrefs",
        ]

        self.COMMANDS = {
            "analyzer":
            Command(0, self.__exec_analyzer, None, [
                "",
                "Analyzer information",
            ]),
            "help":
            Command(0, self.__exec_help, None, ["", "Display this help"]),
            "history":
            Command(0, self.__exec_history, None, [
                "",
                "Display the command history",
            ]),
            "save":
            Command(0, self.__exec_save, None, [
                "",
                "Save the database (only symbols and history currently).",
            ]),
            "load":
            Command(1, self.__exec_load, self.__complete_load, [
                "filename",
                "Load a new binary file.",
            ]),
            "lrawx86":
            Command(1, self.__exec_lrawx86, self.__complete_load, [
                "filename",
                "Load a x86 raw file.",
            ]),
            "lrawx64":
            Command(1, self.__exec_lrawx64, self.__complete_load, [
                "filename",
                "Load a x64 raw file.",
            ]),
            "lrawarm":
            Command(1, self.__exec_lrawarm, self.__complete_load, [
                "filename",
                "Load a ARM raw file.",
            ]),
            "lrawmips":
            Command(1, self.__exec_lrawmips, self.__complete_load, [
                "filename",
                "Load a MIPS raw file.",
            ]),
            "lrawmips64":
            Command(1, self.__exec_lrawmips64, self.__complete_load, [
                "filename",
                "Load a MIPS64 raw file.",
            ]),
            "x":
            Command(1, self.__exec_x, self.__complete_x, [
                "[SYMBOL|0xXXXX|EP]",
                "Decompile and print on stdout. By default it will be main.",
                "The decompilation is forced, it dosn't check if addresses",
                "are defined as code."
            ]),
            "v":
            Command(1, self.__exec_v, self.__complete_x, [
                "[SYMBOL|0xXXXX|EP]",
                "Visual mode",
                "Shortcuts:",
                "c       create code",
                "p       create function",
                "x       show xrefs",
                "g       top",
                "G       bottom",
                "z       set current line on the middle",
                "q       quit",
                ";       edit inline comment (enter/escape to validate/cancel)",
                "%       goto next bracket",
                "*       highlight current word (ctrl-k to clear)",
                "{ }     previous/next paragraph",
                "tab     switch between dump/decompilation",
                "enter   follow address",
                "escape  go back",
                "u       re-enter (for undo)",
            ]),
            "da":
            Command(2, self.__exec_data, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Print data in ascii, it stops when the end of the section is found",
            ]),
            "db":
            Command(2, self.__exec_data, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Print data in bytes, it stops when the end of the section is found",
            ]),
            "dd":
            Command(2, self.__exec_data, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Print data in dwords, it stops when the end of the section is found",
            ]),
            "dw":
            Command(2, self.__exec_data, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Print data in words, it stops when the end of the section is found",
            ]),
            "dq":
            Command(2, self.__exec_data, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Print data in qwords, it stops when the end of the section is found",
            ]),

            # by default it will be ctx.lines
            "dump":
            Command(2, self.__exec_dump, self.__complete_x, [
                "SYMBOL|0xXXXX|EP [NB_LINES]",
                "Disassemble only.",
            ]),
            "set":
            Command(3, None, None, ["", "Set options"]),
            "sym":
            Command(3, self.__exec_sym, self.__complete_x, [
                "[SYMBOL 0xXXXX] [| FILTER]",
                "Print all symbols or set a new symbol.",
                "You can filter symbols by searching the word FILTER.",
                "If FILTER starts with -, the match is inversed."
            ]),
            "exit":
            Command(0, self.__exec_exit, None, ["", "Exit"]),
            "sections":
            Command(0, self.__exec_sections, None, [
                "",
                "Print all sections",
            ]),
            "info":
            Command(0, self.__exec_info, None,
                    ["", "Information about the current binary"]),
            "display.print_section":
            Command(0, self.__exec_display_print_section, None,
                    ["", "Print or not section when an address is found"]),
            "display.print_comments":
            Command(0, self.__exec_display_print_comments, None,
                    ["", "Print or not comments"]),
            "jmptable":
            Command(4, self.__exec_jmptable, None, [
                "INST_ADDR TABLE_ADDR NB_ENTRIES SIZE_ENTRY",
                "Create a jump table referenced at TABLE_ADDR and called",
                "from INST_ADDR."
            ]),
            "py":
            Command(0, self.__exec_py, None,
                    ["", "Run an interactive python shell."]),
            "mips_set_gp":
            Command(1, self.__exec_mips_set_gp, None,
                    ["ADDR", "Set the register $gp to a fixed value."]),
            "functions":
            Command(1, self.__exec_functions, None,
                    ["", "Print the function list."]),
            "xrefs":
            Command(1, self.__exec_xrefs, self.__complete_x,
                    ["SYMBOL|0xXXXX|EP", "Print all xrefs."]),
        }

        self.analyzer = Analyzer()
        self.analyzer.start()

        rl = ReadLine(self.exec_command, self.complete, self.send_control_c)
        self.rl = rl

        if ctx.filename is not None:
            self.__exec_load(["", ctx.filename])

        if ctx.entry is not None:
            self.__exec_x(["", ctx.entry])

        rl.reload_cursor_line()

        while 1:
            rl.loop()
            if not self.check_db_modified():
                break

        self.analyzer.msg.put("exit")
Esempio n. 4
0
import os
from lib.input_parser import load_sentences_from_file
from lib.analyzer import Analyzer
from lib.grapher import Grapher

FILE_TO_ANALYZE = os.getcwd() + "/samples/debug.txt"
WARNING_THRESHOLD = 20
WORD_GAP = 5
PREFIX = "Debug"


if __name__ == '__main__':
    print(":: Text Analyzer")
    sentences = load_sentences_from_file(FILE_TO_ANALYZE)
    analyzer = Analyzer(sentences, WARNING_THRESHOLD, PREFIX, WORD_GAP)
    analyzer.run_analyses()
    grapher = Grapher(analyzer)
    grapher.run_all()
Esempio n. 5
0
from time import time

from lib.analyzer import Analyzer
from lib.helpers import Helpers
from lib.writer import Writer
from lib.grapher import Grapher
from lib.reporter import Reporter

ENCODING = "latin-1"
FILEFORMAT = ".log"

if __name__ == '__main__':
    print("Running Log Auswertung")
    start = time()

    helpers = Helpers(ENCODING, FILEFORMAT)
    helpers.create_directorys()
    analyzer = Analyzer(helpers)
    analyzer.run()
    grapher = Grapher(ENCODING, helpers)
    grapher.run()
    csv_writer = Writer(ENCODING, helpers)
    csv_writer.run_all()
    reporter = Reporter()
    reporter.write_html_doc()

    end = time() - start
    print("Prozess beendet: {:02.0f}:{:02.0f}:{:02.2f}".format(
        end // 3600, end % 3600 // 60, end % 60))