def activate_new(self, action): return doc = hexview.HexView("new") doc.parent = self dnum = len(self.das) self.das[dnum] = doc label = gtk.Label('New') self.notebook.append_page(doc.table, label) self.notebook.show_tabs = True self.notebook.show_all()
def activate_open(self,parent=None,buf=None): if self.fname !='': fname = self.fname self.fname = '' elif buf == None: fname = self.file_open() else: fname = 'Clipboard' print(fname) if fname: lines = [] comments = {} if buf == None: f = open(fname,"rb") rbuf = f.read() if rbuf[:9] == "RE-LABv05": print('Re-Lab project file') # skip "signature" off = 35 k = "" while k != "Num of lines": off,k,v = self.rlp_unpack(rbuf,off) print(k,v) for i in range(v): l = struct.unpack("<I",rbuf[off:off+4])[0] off += 4 s = ord(rbuf[off]) lines.append((l,s)) off += 1 while k != "Num of comments": off,k,v = self.rlp_unpack(rbuf,off) print(k,v) for i in range(v): tl = ord(rbuf[off]) off += 1 txt = rbuf[off:off+tl] off += tl coff = struct.unpack("<I",rbuf[off:off+4])[0] off += 4 clen = struct.unpack("<I",rbuf[off:off+4])[0] off += 4 clr0 = ord(rbuf[off])/255 clr1 = ord(rbuf[off+1])/255 clr2 = ord(rbuf[off+2])/255 ct = ord(rbuf[off+3]) off += 4 comments[coff] = hexview.Comment(txt,coff,clen,(clr0,clr1,clr2),ct) while k != "Data BLOB": off,k,v = self.rlp_unpack(rbuf,off) print(k,v) buf = rbuf[off:] elif fname[len(fname)-3:] == "rlp": print('Probably old Re-Lab project file') llen = struct.unpack("<I",rbuf[0:4])[0] clen = struct.unpack("<I",rbuf[4:8])[0] off = 8 for i in range(llen): l1 = struct.unpack("<I",rbuf[off:off+4])[0] off += 4 l2 = ord(rbuf[off]) off += 1 if l2 > 1: off += 4 l2 = 1 lines.append((l1,l2)) for i in range(clen): c1 = struct.unpack("<I",rbuf[off:off+4])[0] off += 4 c2 = ord(rbuf[off]) off += 1 c3 = ord(rbuf[off]) off += 1 c4 = rbuf[off:off+c3] comments[c1+1] = hexview.Comment(c4,c1+1,c2,(1,0,0),0) off += c3 buf = rbuf[off:] else: buf = rbuf f.close() doc = hexview.HexView(buf,lines,comments) doc.parent = self doc.fname = fname dnum = len(self.das) self.das[dnum] = doc pos = fname.rfind('/') if pos !=-1: pname = fname[pos+1:] else: pname = fname label = gtk.Label(pname) ebox = gtk.EventBox() ebox.add(label) ebox.show_all() self.notebook.append_page(doc.table, ebox) self.notebook.set_tab_reorderable(doc.table, True) self.notebook.show_tabs = True self.notebook.show_all() self.notebook.set_current_page(-1) doc.hv.grab_focus() return