ffilter.py

Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2006 Cristian L. Vlasceanu
00003 #
00004 # Permission is hereby granted, free of charge, to any person
00005 # obtaining a copy of this software and associated documentation
00006 # files (the "Software"), to deal in the Software without
00007 # restriction, including without limitation the rights to use,
00008 # copy, modify, merge, publish, distribute, sublicense, and/or
00009 # sell copies of the Software, and to permit persons to whom
00010 # the Software is furnished to do so, subject to the following
00011 # conditions:
00012 # 
00013 # The above copyright notice and this permission notice shall be
00014 # included in all copies or substantial portions of the Software.
00015 # 
00016 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00017 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00018 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00019 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00023 # OR OTHER DEALINGS IN THE SOFTWARE.
00024 # 
00025 # NOTE: The above applies solely to Python source code provided 
00026 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00027 #
00028 import gtk
00029 import zero
00030 
00031 
00032 class ELF(object):
00033         def __init__(self, app, filter):
00034                 self.filter = filter
00035                 self.__app = app
00036                 if filter:
00037                         filter.add_custom(      gtk.FILE_FILTER_FILENAME, 
00038                                                                 self.on_filter, 
00039                                                                 None)
00040 
00041 
00042         def __get_hdr(filename):
00043                 try:
00044                         if filename:
00045                                 return zero.get_elf_header(filename)
00046                 except:
00047                         pass
00048                 return None
00049         __get_hdr = staticmethod(__get_hdr)
00050 
00051 
00052         def update_preview(self, preview, filename):
00053                 hdr = ELF.__get_hdr(filename)
00054                 if hdr:
00055                         preview.set_spacing(5)
00056                         label = gtk.Label(
00057                                 "%s %s %s" % (hdr.klass(), hdr.machine(), hdr.type()))
00058                         preview.pack_start(label, False)
00059                         if hdr.type() == zero.Elf_Hdr.Type.Executable:
00060                                 frame = gtk.Frame("Command Line Arguments")
00061                                 preview.pack_end(frame, False)
00062                                 combo = gtk.ComboBoxEntry()
00063                                 combo.set_size_request(300, -1)
00064                                 frame.add(combo)
00065                                 btn = gtk.Button("Edit En_vironment...")
00066                                 preview.pack_end(btn, False)
00067                         else:
00068                                 pass ### todo: handle core files ###
00069                         preview.show_all()
00070                         return True
00071                 return False
00072 
00073 
00074         def on_filter(self, finfo, data):
00075                 hdr = ELF.__get_hdr(finfo[0])
00076                 if hdr:
00077                         type = hdr.type()
00078                         if (type == zero.Elf_Hdr.Type.Executable or 
00079                                 type == zero.Elf_Hdr.Type.Core):
00080                                 return True
00081                 return False
00082 
00083 
00084         def open(self, filename):
00085                 hdr = ELF.__get_hdr(filename)
00086                 if hdr:
00087                         if hdr.type() == zero.Elf_Hdr.Type.Executable:
00088                                 #todo: pass args, environment
00089                                 self.__app.load_exec(filename)
00090                         else:
00091                                 self.__app.load_core(filename, None)
00092                         return True
00093                 return False
00094