예제 #1
0
def manualJumptableLimit(proj, addr):
    romconfig = Config(proj.filename, rom=True)
    jumptables = romconfig.get(["Analysis", "Jumptable-List"])
    try:
        return jumptables[str(addr)]
    except KeyError:
        return None
예제 #2
0
파일: flow.py 프로젝트: resonancellc/awake
    def analyze(self):

        ctx = Context()

        romconfig = Config(self.filename, rom=True)
        rombank = romconfig.get(["Analysis", "FlowAnalysis-Rombank"])
        if str(hex(self.addr.virtual())) in rombank:
            print "a"
            ctx.setValue('ROMBANK',
                         Constant(rombank[str(hex(self.addr.virtual()))]))
        '''
        if self.addr.virtual() == 0x0A90:
            ctx.setValue('ROMBANK', Constant(1))
        if self.addr.virtual() == 0x3CCA:
            ctx.setValue('ROMBANK', Constant(0x15))
        if self.addr.virtual() in (0x0B34, 0x0B37, 0x0B3A, 0x0B3D):
            ctx.setValue('ROMBANK', Constant(1))
        if self.addr.virtual() in (0x0D68, 0x0E7F, 0x0EFC, 0x0EDB, 0x0C40, 0x149B, 0x15B3, 0x1732, 0x0C10):
            ctx.setValue('ROMBANK', Constant(2))
        '''

        if self.addr.inBankedSpace() and not self.addr.isAmbiguous():
            ctx.setValue('ROMBANK', Constant(self.addr.bank()))

        content = self.process(self.graph.start(), None, False, False, True)
        content = content.optimizedWithContext(ctx)
        content = content.optimizeDependencies(
            set(ALL_REGS) - set(['FZ', 'FN', 'FC', 'FH']))
        return content
예제 #3
0
 def __init__(self, filename, config_file, config_is_object=False):
     self.filename = filename
     self.rom = Rom(self.filename)
     if config_is_object:  #If configs passed as object [needed for openCopy()]
         self.config = config_file  #Use the objects
     else:  #Otherwise, use the filenames.
         self.config = Config(config_file)
     romconfig = Config(filename, rom=True)
     if romconfig.get(['Database', 'Auto-Upgrade']):
         updb.doUpgrade(self.filename)
     self.database = Database(self.filenameBase() + '.awakedb')
     self.disasm = Z80Disasm(self)
     self.flow = ProcedureFlowCache(self)
예제 #4
0
파일: project.py 프로젝트: amorri40/awake
 def __init__(self, filename, config_file, config_is_object=False):
     self.filename = filename
     self.rom = Rom(self.filename)
     if config_is_object:                #If configs passed as object [needed for openCopy()]
         self.config=config_file         #Use the objects
     else:                               #Otherwise, use the filenames.
         self.config = Config(config_file)
     romconfig=Config(filename, rom=True)
     if romconfig.get(['Database','Auto-Upgrade']):
         updb.doUpgrade(self.filename)
     self.database = Database(self.filenameBase()+'.awakedb')
     self.disasm = Z80Disasm(self)
     self.flow = ProcedureFlowCache(self)
예제 #5
0
 def __init__(self, filename, config_file, config_is_object=False):
     """
     Create a new Project with specified Rom Filename and configuration
     :type filename: str
     """
     self.filename = filename
     self.rom = Rom(self.filename)
     if config_is_object:  #If configs passed as object [needed for openCopy()]
         self.config = config_file  #Use the objects
     else:  #Otherwise, use the filenames.
         self.config = Config(config_file)
     romconfig = Config(
         filename, rom=True
     )  # TODO: Doesn't this negate the purpose of the previous self.config lines?
     if romconfig.get(['Database', 'Auto-Upgrade']):
         updb.doUpgrade(self.filename)
     self.database = Database(self.filenameBase() + '.awakedb')
     self.disasm = Z80Disasm(self)
     self.flow = ProcedureFlowCache(self)
     self.debug_symbols = None
예제 #6
0
    def __init__(self, proj, addr):
        self.addr = addr
        self.targets = []
        romconfig = Config(proj.filename, rom=True)
        jumptables = romconfig.get(["Analysis", "Jumptable-List"])
        try:
            size = jumptables[str(addr)]
        except KeyError:
            size = 256
        for i in range(size):
            a = addr.offset(i * 2)
            lo = proj.rom.get(a)
            hi = proj.rom.get(a.offset(1))
            value = address.fromVirtualAndCurrent((hi << 8) | lo, addr)

            if not value.inPhysicalMem():
                print "breaking"
                break

            self.targets.append(ProcAddress(value))
예제 #7
0
파일: gui.py 프로젝트: gb-archive/awake
class MainWindow(tk.Toplevel):

    def __init__(self, parent=None, filename=None, url=None, config_file=None):
        if not parent:
            parent = getTkRoot()
        tk.Toplevel.__init__(self, parent)
        self.parent = parent

        title = "Awake"
        if filename:
            title += ' - ' + os.path.basename(filename)
        self.title(title)

        if filename:
            self.romconfig=Config(filename, rom=True)
            self.proj = Project(filename, config_file)
            if self.proj.config.get(['Autostart-Server']):
                self.showServer()
        else:
            self.proj = None

        self.panes = tk.PanedWindow(self, orient='horizontal', sashwidth=10)
        self.panes.pack(side='top', fill='both', expand=True)

        self.tool_pane = ttk.Frame(self.panes)
        self.panes.add(self.tool_pane)
        self.main_pane = ttk.Frame(self.panes)
        self.panes.add(self.main_pane)

        toolbar = ttk.Frame(self.main_pane)
        toolbar.pack(side='top', fill='x', padx=5, pady=5)

        open_button = ttk.Button(toolbar, text="Open...", command=self.selectRom)
        open_button.pack(side='left')
        
        self.history = History(toolbar)
        self.history.pack(side='left')

        self.server_button = ttk.Button(toolbar, text="Start server...", width=15, command=self.showServer)
        self.server_button.pack(side='right')
        self.export_button = ttk.Button(toolbar, text="Export...", width=10, command=self.showExport)
        self.export_button.pack(side='right')

        self.main = MainFrame(self.main_pane, self.proj)
        self.main.pack(side='top', fill='both', expand=True)
        self.main.setLinkCallback(self.history.navigate)
        self.history.setOpenPageCallback(self.main.openPage)

        #bank_frame = ttk.Frame(self.tool_pane)
        #bank_frame.pack(side='top', fill='x', padx=5, pady=5)

        #self.bank_select = ttk.Combobox(bank_frame, state='readonly', values=['All banks', 'Bank 00', 'Bank 01'], width=10)
        #self.bank_select.pack(side='left', fill='x', expand=True)

        #bank_names_button = ttk.Button(bank_frame, text='...', width=3)
        #bank_names_button.pack(side='left')

        #symbol_frame = ttk.Frame(self.tool_pane)
        #symbol_frame.pack(side='top', fill='x')

        #self.symbol_list = tk.Listbox(symbol_frame, relief='flat', highlightthickness=0)
        #self.symbol_list.pack(side='left', fill='both', expand=True)
        #symbol_sb = ttk.Scrollbar(symbol_frame, orient="vertical", command=self.symbol_list.yview)
        #symbol_sb.pack(side="right", fill="y")
        #self.symbol_list.configure(yscrollcommand=symbol_sb.set)

        self.protocol("WM_DELETE_WINDOW", self.quit)

        if not url and self.proj:
            url = self.romconfig.get(['UI','Default-Page'])

        if url:
            self.history.navigate(url)

        if not self.proj:
            self.export_button.configure(state='disabled')
            self.server_button.configure(state='disabled')
            self.history.disable()

    def showExport(self):
        if self.proj:
            ExportDialog(self, self.proj)

    def showServer(self):
        if self.proj:
            ServerDialog(self, self.proj)

    def selectRom(self):
        filename = askopenfilename(title="Select ROM file", parent=self, filetypes=[('Gameboy rom files (*.gb)', '*.gb'), ('Gameboy Color rom files (*.gbc)', '*.gbc'), ('All files', '*.*')])
        if not filename:
            return

        fresh = MainWindow(getTkRoot(), filename)
        fresh.geometry(self.geometry())
        self.destroy()

    def wait(self):
        self.wait_window(self)

    def quit(self, *args):
        self.destroy()
        self.parent.destroy()