Example #1
0
    def __init__(self, tui, disasm):

        self.tui = tui
        self.Disassemble = disasm
        self.current_address = '0x{:08X}'.format(
            self.Disassemble.getSections()[".text"])

        # Per tutti i comandi usabili dalla termimnale ho creato una matrice contente un dizionario e un'altra
        # lista. Nel dizionario uso come chiave 2 parole separate dal punto e virgola, con la funzione rispettiva
        # come valore
        self.commands = [[{
            "clear;cc": self.clear
        }, "Clear the terminal"],
                         [{
                             "graphic;v": self.graphic
                         }, "Get the graphic mode of the program"],
                         [{
                             "disasm;da": self.disasm
                         }, "Assembler code of debugged program"],
                         [{
                             "hexdump;hx": self.hexdump
                         }, "Hex code of debugged code"],
                         [{
                             "sections;se": self.sections
                         }, "Get sections names"],
                         [{
                             "strings;st": self.strings
                         }, "Get strings of debugged program"],
                         [{
                             "search;ss": self.searchString
                         }, "Search strings on debugged program"],
                         [{
                             "address;sa": self.setAddress
                         }, "Set poin   ter to memory address"],
                         [{
                             "banner;banner": self.banner
                         }, "Get the banner"],
                         [{
                             "help;h": self.bannerHelp
                         }, "This banner"], [{"^C;."},
                                             "Exit from visual mode"],
                         [{
                             "exit;exit": sys.exit
                         }, "Exit"]]

        self.banner = """

          _____                                 _ _           
         / ____|                               | | |          
        | |     _ __ ___  _ __   ___  ___    __| | |__   __ _ 
        | |    | '__/ _ \| '_ \ / _ \/ __|  / _` | '_ \ / _` |
        | |____| | | (_) | | | | (_) \__ \ | (_| | |_) | (_| |
         \_____|_|  \___/|_| |_|\___/|___/  \__,_|_.__/ \__, |
                                                         __/ |
                                                        |___/ 
           {}
           {}
               """.format(toColor("by Ramphy Aquino Nova", "YELLOW"),
                          toColor("I2a", "DBLUE"))
Example #2
0
    def hexdump(self, byteslen='304'):
        for _ in self.Disassemble.getHexdump(byteslen=byteslen,
                                             ref_address=self.current_address):
            address = toColor(_[0], "GREEN")
            hexvalues = _[1]
            asciivalues = toColor("|{:<16}|".format(_[2]), "YELLOW")

            print('{}  {:<39} {}'.format(address, hexvalues, asciivalues))
Example #3
0
 def setAddress(self, address):
     # Questa funzione serve per impostare l'indirizzo dal quale si partira per ricavare i dati
     max_address = self.Disassemble.getHexdump()[-1][0]
     if int(address, 0) <= int(max_address, 0):
         self.current_address = '0x{:08X}'.format(int(address, 0))
     else:
         print(toColor("[*] Empty address", "RED"))
         print(
             toColor("[!] Max address: ", "YELLOW") +
             toColor(max_address, "GREEN"))
Example #4
0
    def disasm(self, lines=25):
        # In questa funzione come in altre nel resto del programma ho usato una classe fatta da me per
        # colorare le stringhe
        for _ in self.Disassemble.disAssembler(lines=lines,
                                               ref_address=str(
                                                   int(self.current_address,
                                                       0))):
            address = toColor("0x{:08X}".format(_[0]), "GREEN")
            operation = toColor(_[1], "YELLOW")
            values = toColor(" ".join(_[2].split(" ")[0:2] + [""]), "DBLUE") + \
                     toColor(" ".join(_[2].split(" ")[2:]), "PURPLE")

            print("{} {} {}".format(address, operation, values))
Example #5
0
    def searchString(self, string):
        result = self.Disassemble.searchString(string)

        for _ in result:
            print(_)

        if not len(result):
            print(toColor("[!] Any result", "YELLOW"))
Example #6
0
    def run(self):
        print(self.banner)

        while True:
            address = toColor("{}".format(self.current_address), "YELLOW")

            command = input("\n[{}]>>> ".format(address)).lower()
            cExists = False

            for _ in self.commands:
                for key in _[0]:
                    index = self.commands.index(_)
                    param = command.split(" ")

                    if param[0] in key.split(";"):
                        # Tutte le funzioni della terminale possono essere usate senza parametri tranne le seguenti
                        # dove si devono specificare alcuni parametri
                        if len(param) > 1:
                            if key.split(
                                    ";")[0] == "disasm" and len(param) > 1:
                                self.commands[index][0][key](
                                    lines=int(param[1]))
                            elif key.split(
                                    ";")[0] == "hexdump" and len(param) > 1:
                                self.commands[index][0][key](byteslen=param[1])
                            elif key.split(
                                    ";")[0] == "search" and len(param) > 1:
                                self.commands[index][0][key](param[1])
                            elif key.split(
                                    ";")[0] == "address" and len(param) > 1:
                                self.commands[index][0][key](param[1])
                        else:
                            if command in key.split(";"):
                                self.commands[index][0][key]()

                        cExists = True
                        break
                    elif len(command) == 0:
                        cExists = True

            if not cExists:
                print(toColor("[!] Command not found", "RED"))
Example #7
0
 def sections(self):
     for _ in self.Disassemble.getSections():
         print(
             toColor('0x{:08X}'.format(self.Disassemble.getSections()[_]),
                     "GREEN"), toColor(_, "YELLOW"))