def on_opt_btn_clicked(self,action,name): if name == "OK": pn = self.notebook.get_current_page() if pn != -1: doc = self.das[pn] doff = int(self.options_off,16) dlen = int(self.options_len,16) lnum = utils.find_line(doc,doff) self.expwin.destroy() utils.html_export(self,doc,lnum,doff,dlen) else: self.expwin.destroy()
def on_entry_activate (self,action,cmdline=""): if cmdline == "": cmdline = self.entry.get_text() if len(cmdline) > 0: if self.curcmd == -1 or self.cmdhistory[self.curcmd] != cmdline: self.cmdhistory.append(cmdline) self.curcmd = -1 pn = self.notebook.get_current_page() data = '' if pn != -1: # try to take current selection doc = self.das[pn] if doc.sel: r1,c1,r2,c2 = doc.sel data = doc.data[doc.lines[r1][0]+c1:doc.lines[r2][0]+c2] cmd = cmdline.split() doc.bklines = [] doc.bkhvlines = [] doc.bklines += doc.lines doc.bkhvlines += doc.hvlines if cmd[0].lower() == "name" and len(cmd) > 1: ebox = self.notebook.get_tab_label(doc.table) ebox.get_children()[0].set_text(cmd[1]) elif cmd[0].lower() == "bck": pass elif cmd[0].lower() == "reload": exec("reload(%s)"%(cmd[1])) elif cmdline[:3].lower() == "run": hv = doc if len(cmdline) < 5: self.open_cli() cmdline = "" else: cmdline = cmdline[4:] exec(cmdline) hv.expose(None,None) elif cmd[0].lower() == "fmt": cmd = cmd[1:] mpos = cmdline.find("*") curpos = doc.lines[doc.curr][0] if mpos == -1: # wrap lines starting from current to provided lengths cmdacc = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] break doc.fmt_row(doc.curr,cmd) lrow = doc.curr+len(cmd) elif mpos == len(cmdline)-1: # repeat wrapping till end print("Rpt to end") cmd = cmdline[4:mpos].split() cmdacc = 0 rpt = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] rpt = 1 break if rpt == 0: rpt = 1+(doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0])/cmdacc for i in range(rpt): doc.fmt_row(doc.curr+i*len(cmd),cmd) lrow = doc.curr+i*len(cmd) else: cmd = cmdline[4:mpos].split() rpt = int(cmdline[mpos+1:].strip()) cmdacc = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] rpt = 1 break if cmdacc*rpt > doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0]: rpt = 1+(doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0])/cmdacc #repeat wrapping last arg times print("Rpt",rpt,"times",cmd) for i in range(rpt): doc.fmt_row(doc.curr+i*len(cmd),cmd) lrow = doc.curr+i*len(cmd)+1 doc.hvlines[lrow] = "" doc.set_maxaddr() doc.expose(None,None) elif cmd[0].lower() == "goto": addr = 0 addrflag = 0 if len(cmd) > 1: try: goto = cmdline[4:] pos = goto.find("+") if pos != -1: if pos == 1: addr = doc.lines[doc.curr][0]+doc.curc+int(goto[pos+1:],16) addrflag = 1 else: addr = int(goto[1:pos],16)+int(goto[pos+1:],16) else: pos = goto.find("-") if pos != -1: if pos == 1: addr = doc.lines[doc.curr][0]+doc.curc-int(goto[pos+1:],16) addrflag = 1 else: addr = int(goto[1:pos],16)-int(goto[pos+1:],16) else: addr = int(goto[1:], 16) print("Addr: ",addr) except: print("Wrong string for Hex address") elif doc.sel: if len(data) <4: dstr = data + "\x00"*(4-len(data[:4])) else: dstr = data[:4] addr = struct.unpack("<I",dstr) print("Addr sel: %04x"%addr) # try to validate/scroll llast = len(doc.lines) if addr < doc.lines[len(doc.lines)-1][0]: lnum = utils.find_line(doc,addr) print("Lnum found",lnum,"%x %x"%(doc.lines[lnum][0],doc.lines[lnum+1][0])) if addrflag == 0: self.entry.set_text("goto %x"%addr) doc.curr = lnum doc.curc = addr - doc.lines[lnum][0] doc.offnum = min(lnum,llast-doc.numtl) doc.offset = doc.lines[lnum][0] else: print("Address after end of file") doc.offnum = llast-doc.numtl doc.offset = doc.lines[llast-1][0] doc.vadj.value = doc.offnum doc.expose(doc.hv,action) elif cmdline[0] == "?": utils.cmd_parse(cmdline,self,doc) elif cmdline[0] == "!": # off;len;text cmd = cmdline[1:].split(";") if len(cmd) < 3: # add comment to selection or cursor if doc.cursor_in_sel(): rs,cs,re,ce = doc.sel clen = doc.get_sel_len() else: rs = doc.curr cs = doc.curc clen = 1 text = cmdline[1:] off = doc.lines[rs][0]+cs+1 else: text = ";".join(cmd[2:]) off = int(cmd[0],16)+1 clen = int(cmd[1],16) try: doc.insert_comment2(text,off,clen) doc.expose(doc.hv,action) except: print("Wrong args",sys.exc_info()) elif cmdline.lower() == "dump": fname = self.file_open('Save',None,gtk.FILE_CHOOSER_ACTION_SAVE) if fname: f = open(fname,'wb') f.write(doc.data) f.close() else: print("Nothing to save") elif cmd[0].lower() == "html": off = -1 try: off = int(cmd[1],16) clen = int(cmd[2],16) lnum = 0 if off < len(doc.data): lnum = utils.find_line(doc,off) addr = doc.lines[lnum] if addr < off: clen += off - addr except: print("Something wrong with arguments",sys.exc_info()) if off == -1: lnum = 0 clen = len(doc.data) utils.html_export(self,doc,lnum,off,clen) elif cmdline[0] == "/": if len(cmdline) > 1: pos1 = cmdline.find("+") pos2 = cmdline.find("-") if pos1 != -1 or pos2 != -1: pos = max(pos1,pos2) try: arg1 = int(cmdline[1:pos],16) arg2 = int(cmdline[pos+1:],16) if pos1 != -1: addr = arg1+arg2 self.entry.set_text("/%x+%x"%(addr,arg2)) else: addr = arg1-arg2 self.entry.set_text("/%x-%x"%(addr,arg2)) lnum = utils.find_line (doc,addr) cnum = addr - doc.lines[lnum][0] except: print("Invalid offset") else: arg = cmdline[1:] try: addr = int(arg,16) lnum = utils.find_line (doc,addr) cnum = addr - doc.lines[lnum][0] except: print("Invalid offset") else: lnum = doc.curr cnum = doc.curc if lnum > 0: if cnum > 0: doc.fmt(lnum,[cnum]) lnum += 1 doc.curr = lnum doc.curc = 0 s = (doc.lines[lnum-1][1]+1)%4 doc.lines[lnum-1] = (doc.lines[lnum-1][0],s) # scroll down if went below screen if lnum > doc.offnum+doc.numtl-3: doc.offnum += doc.numtl/2 # scroll up if went above screen if lnum < doc.offnum: doc.offnum = lnum doc.expose(None,None)
def on_entry_activate (self,action,cmdline=""): if cmdline == "": cmdline = self.entry.get_text() if len(cmdline) > 0: if self.curcmd == -1 or self.cmdhistory[self.curcmd] != cmdline: self.cmdhistory.append(cmdline) self.curcmd = -1 pn = self.notebook.get_current_page() data = '' if pn != -1: # try to take current selection doc = self.das[pn] if doc.sel: r1,c1,r2,c2 = doc.sel data = doc.data[doc.lines[r1][0]+c1:doc.lines[r2][0]+c2] cmd = cmdline.split() doc.bklines = [] doc.bkhvlines = [] doc.bklines += doc.lines doc.bkhvlines += doc.hvlines if cmd[0].lower() == "name" and len(cmd) > 1: ebox = self.notebook.get_tab_label(doc.table) ebox.get_children()[0].set_text(cmd[1]) elif cmd[0].lower() == "bck": pass elif cmd[0].lower() == "reload": exec("reload(%s)"%(cmd[1])) elif cmdline[:3].lower() == "run": hv = doc if len(cmdline) < 5: self.open_cli() cmdline = "" else: cmdline = cmdline[4:] exec(cmdline) hv.expose(None,None) elif cmd[0].lower() == "fmt": cmd = cmd[1:] mpos = cmdline.find("*") curpos = doc.lines[doc.curr][0] if mpos == -1: # wrap lines starting from current to provided lengths cmdacc = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] break doc.fmt_row(doc.curr,cmd) lrow = doc.curr+len(cmd) elif mpos == len(cmdline)-1: # repeat wrapping till end print "Rpt to end" cmd = cmdline[4:mpos].split() cmdacc = 0 rpt = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] rpt = 1 break if rpt == 0: rpt = 1+(doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0])/cmdacc for i in range(rpt): doc.fmt_row(doc.curr+i*len(cmd),cmd) lrow = doc.curr+i*len(cmd) else: cmd = cmdline[4:mpos].split() rpt = int(cmdline[mpos+1:].strip()) cmdacc = 0 for k in cmd: cmdacc += int(k) if cmdacc + curpos > len(doc.data): cmd = cmd[:k] rpt = 1 break if cmdacc*rpt > doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0]: rpt = 1+(doc.lines[len(doc.lines)-1][0]-doc.lines[doc.curr][0])/cmdacc #repeat wrapping last arg times print "Rpt",rpt,"times",cmd for i in range(rpt): doc.fmt_row(doc.curr+i*len(cmd),cmd) lrow = doc.curr+i*len(cmd)+1 doc.hvlines[lrow] = "" doc.set_maxaddr() doc.expose(None,None) elif cmd[0].lower() == "goto": addr = 0 addrflag = 0 if len(cmd) > 1: try: goto = cmdline[4:] pos = goto.find("+") if pos != -1: if pos == 1: addr = doc.lines[doc.curr][0]+doc.curc+int(goto[pos+1:],16) addrflag = 1 else: addr = int(goto[1:pos],16)+int(goto[pos+1:],16) else: pos = goto.find("-") if pos != -1: if pos == 1: addr = doc.lines[doc.curr][0]+doc.curc-int(goto[pos+1:],16) addrflag = 1 else: addr = int(goto[1:pos],16)-int(goto[pos+1:],16) else: addr = int(goto[1:], 16) print "Addr: ",addr except: print "Wrong string for Hex address" elif doc.sel: if len(data) <4: dstr = data + "\x00"*(4-len(data[:4])) else: dstr = data[:4] addr = struct.unpack("<I",dstr) print "Addr sel: %04x"%addr # try to validate/scroll llast = len(doc.lines) if addr < doc.lines[len(doc.lines)-1][0]: lnum = utils.find_line(doc,addr) print "Lnum found",lnum,"%x %x"%(doc.lines[lnum][0],doc.lines[lnum+1][0]) if addrflag == 0: self.entry.set_text("goto %x"%addr) doc.curr = lnum doc.curc = addr - doc.lines[lnum][0] doc.offnum = min(lnum,llast-doc.numtl) doc.offset = doc.lines[lnum][0] else: print "Address after end of file" doc.offnum = llast-doc.numtl doc.offset = doc.lines[llast-1][0] doc.vadj.value = doc.offnum doc.expose(doc.hv,action) elif cmdline[0] == "?": utils.cmd_parse(cmdline,self,doc) elif cmdline[0] == "!": # off;len;text cmd = cmdline[1:].split(";") if len(cmd) < 3: # add comment to selection or cursor if doc.cursor_in_sel(): rs,cs,re,ce = doc.sel clen = doc.get_sel_len() else: rs = doc.curr cs = doc.curc clen = 1 text = cmdline[1:] off = doc.lines[rs][0]+cs+1 else: text = ";".join(cmd[2:]) off = int(cmd[0],16)+1 clen = int(cmd[1],16) try: doc.insert_comment2(text,off,clen) doc.expose(doc.hv,action) except: print "Wrong args",sys.exc_info() elif cmdline.lower() == "dump": fname = self.file_open('Save',None,gtk.FILE_CHOOSER_ACTION_SAVE) if fname: f = open(fname,'wb') f.write(doc.data) f.close() else: print "Nothing to save" elif cmd[0].lower() == "html": off = -1 try: off = int(cmd[1],16) clen = int(cmd[2],16) lnum = 0 if off < len(doc.data): lnum = utils.find_line(doc,off) addr = doc.lines[lnum] if addr < off: clen += off - addr except: print "Something wrong with arguments",sys.exc_info() if off == -1: lnum = 0 clen = len(doc.data) utils.html_export(self,doc,lnum,off,clen) elif cmdline[0] == "/": if len(cmdline) > 1: pos1 = cmdline.find("+") pos2 = cmdline.find("-") if pos1 != -1 or pos2 != -1: pos = max(pos1,pos2) try: arg1 = int(cmdline[1:pos],16) arg2 = int(cmdline[pos+1:],16) if pos1 != -1: addr = arg1+arg2 self.entry.set_text("/%x+%x"%(addr,arg2)) else: addr = arg1-arg2 self.entry.set_text("/%x-%x"%(addr,arg2)) lnum = utils.find_line (doc,addr) cnum = addr - doc.lines[lnum][0] except: print "Invalid offset" else: arg = cmdline[1:] try: addr = int(arg,16) lnum = utils.find_line (doc,addr) cnum = addr - doc.lines[lnum][0] except: print "Invalid offset" else: lnum = doc.curr cnum = doc.curc if lnum > 0: if cnum > 0: doc.fmt(lnum,[cnum]) lnum += 1 doc.curr = lnum doc.curc = 0 s = (doc.lines[lnum-1][1]+1)%4 doc.lines[lnum-1] = (doc.lines[lnum-1][0],s) # scroll down if went below screen if lnum > doc.offnum+doc.numtl-3: doc.offnum += doc.numtl/2 # scroll up if went above screen if lnum < doc.offnum: doc.offnum = lnum doc.expose(None,None)