Changeset 3500

Show
Ignore:
Timestamp:
08/17/08 13:20:57 (5 years ago)
Author:
nopper
Message:

rewriting UMPA backend

Location:
branch/PacketManipulator
Files:
1 added
5 modified
1 moved

Legend:

Unmodified
Added
Removed
  • branch/PacketManipulator/PM/Backend/Scapy/packet.py

    r3457 r3500  
    4848    def summary(self): 
    4949        return self.root.summary() 
    50         ret = "" 
    51         for r in self.root: 
    52             ret += self.root._elt2sum(r) 
    53         return ret 
    5450 
    5551    def get_time(self): 
  • branch/PacketManipulator/PM/Backend/UMPA/__init__.py

    r3456 r3500  
    2323from umpa import protocols 
    2424from umpa.packets import Packet 
    25 from umpa.protocols import Protocol 
     25from umpa.protocols._protocols import Protocol 
    2626from umpa.protocols._fields import * 
    2727 
     
    6262    return glob 
    6363 
     64gprotos = load_gprotocols() 
     65 
     66############################################################################### 
     67# Protocols functions 
     68############################################################################### 
    6469def get_protocols(): 
    65     """ 
    66     @return a list of type [(Protocol, name)] 
    67     """ 
    6870    return gprotos 
     71 
     72def get_proto_class_name(protok): 
     73    return protok.__name__ 
     74 
     75def get_proto_name(proto_inst): 
     76    return get_proto_class_name(proto_inst.__class__) 
    6977 
    7078def get_proto(proto_name): 
     
    8088    return None 
    8189 
    82 def get_proto_class_name(protok): 
    83     return protok.__name__ 
    84  
    85 def get_proto_name(proto_inst): 
    86     return get_proto_class_name(proto_inst.__class__) 
    87  
    88 # Fields section 
     90def get_proto_layer(proto): 
     91    return proto.layer 
     92 
     93def get_proto_fields(proto_inst): 
     94    return proto_inst.get_fields() 
     95 
     96############################################################################### 
     97# Packet functions 
     98############################################################################### 
     99 
     100def get_packet_protos(packet): 
     101    for proto in packet.root.protos: 
     102        yield proto 
     103 
     104def get_packet_raw(metapack): 
     105    return metapack.root.get_raw() 
     106 
     107############################################################################### 
     108# Fields functions 
     109############################################################################### 
     110 
     111def get_field_desc(field): 
     112    return field.__doc__ 
    89113 
    90114def get_field_name(field): 
     
    119143    return field.bits 
    120144 
    121 def get_field_offset(proto, field): 
     145def get_field_offset(packet, proto, field): 
    122146    return proto.get_offset(field) 
    123147 
     
    128152    return [(v, k) for (k, v) in field.enumerable.items()] 
    129153 
     154def is_field_autofilled(field): 
     155    return field.auto 
     156 
     157############################################################################### 
     158# Flag fields functions 
     159############################################################################### 
     160 
     161def set_keyflag_value(proto, flag, key, value): 
     162    return flag.get()[key].set(value) 
     163 
    130164def get_keyflag_value(proto, flag, key): 
    131165    return flag.get()[key].get() 
    132  
    133 def set_keyflag_value(proto, flag, key, value): 
    134     return flag.get()[key].set(value) 
    135  
    136 def is_field_autofilled(field): 
    137     return field.auto 
    138  
    139 def get_field_desc(field): 
    140     return field.__doc__ 
    141166 
    142167def get_flag_keys(flag_inst): 
     
    144169        yield key 
    145170 
    146 def get_field_key(proto_inst, field_inst): 
    147     for key in proto_inst.__class__.get_fields_keys(): 
    148         if field_inst == getattr(proto_inst, key, None): 
    149             return key 
    150  
    151     return None 
    152  
    153 def get_proto_fields(proto_inst): 
    154     return proto_inst.get_fields() 
    155  
    156 def get_packet_protos(packet): 
    157     for proto in packet.root.protos: 
    158         yield proto 
    159  
    160 def get_proto_layer(proto): 
    161     return proto.layer 
    162  
    163 def get_packet_raw(metapack): 
    164     return metapack.root.get_raw() 
    165  
    166 # Checking stuff 
     171############################################################################### 
     172# Checking functions 
     173############################################################################### 
    167174 
    168175def is_field(field): 
     
    178185    return isinstance(obj, klass) 
    179186 
    180  
    181187class MetaPacket: 
    182188    def __init__(self, proto=None): 
    183         self.root = Packet(proto) 
    184  
    185     def include(self, proto): 
    186         self.root.include(proto) 
    187  
    188 from Backend import VirtualIFace 
     189        self.root = Packet(proto, strict=False) 
     190 
     191    def insert(self, proto, layer): 
     192        # Only append for the moment 
     193        if layer == -1: 
     194            self.root.include(proto.root.protos[0]) 
     195            return True 
     196 
     197        return False 
     198 
     199    def get_protocol_str(self): 
     200        return get_proto_name(self.root) 
     201 
     202    def summary(self): 
     203        # We need to ask for a method here 
     204        return "%s packet" % self.get_protocol_str() 
     205 
     206    def get_time(self): 
     207        # We need to ask for a method here 
     208        return "N/A" 
     209 
     210    def get_dest(self): 
     211        # We need to ask for a method here 
     212        return "N/A" 
     213 
     214    def get_source(self): 
     215        # We need to ask for a method here 
     216        return "N/A" 
     217 
     218############################################################################### 
     219# Functions used by dialogs but not defined 
     220############################################################################### 
    189221 
    190222def find_all_devs(): 
    191     "@return a list of avaiable devices to sniff from" 
    192223    return [] 
    193  
    194  
    195 gprotos = load_gprotocols() 
    196224 
    197225PMField = Field 
  • branch/PacketManipulator/PM/Gui/Core/FallbackPaned.py

    r3499 r3500  
    7272        label.show_all() 
    7373 
    74         print "Adding widget", widget, "to", pos 
     74        #print "Adding widget", widget, "to", pos 
    7575 
    7676        if pos == gtk.POS_RIGHT or pos == gtk.POS_LEFT: 
  • branch/PacketManipulator/PM/Gui/Tabs/ProtocolSelectorTab.py

    r3457 r3500  
    4848                     self.__on_sort_ascending, 
    4949                     self.__on_sort_layer) 
    50          
    51         for stock, cb in zip(stocks, callbacks): 
    52             action = gtk.Action('', '', '', stock) 
     50 
     51        tooltips = (_('Sort descending'), 
     52                    _('Sort ascending'), 
     53                    _('Sort by layer')) 
     54         
     55        for tooltip, stock, cb in zip(tooltips, stocks, callbacks): 
     56            action = gtk.Action(None, None, tooltip, stock) 
    5357            item = action.create_tool_item() 
    5458            item.connect('clicked', cb) 
  • branch/PacketManipulator/PM/PacketManipulator

    r3467 r3500  
    1919# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
    2020 
     21import os 
     22import sys 
     23import signal 
     24 
    2125try: 
     26    if os.getenv('PM_DEVELOPMENT', False): 
     27        raise ImportError 
     28 
    2229    import psyco 
    2330    psyco.profile() 
     
    2633except ImportError: 
    2734    print "No psyco no party! :(" 
    28  
    29 import os 
    30 import sys 
    31 import signal 
    3235 
    3336# used by exception hook 
  • branch/PacketManipulator/PacketManipulator

    r3466 r3500  
    2222 
    2323# Probably this won't work on win32 
     24os.putenv('PM_DEVELOPMENT', '1') 
    2425os.putenv('PYTHONPATH', '%s%s%s' % (os.getcwd(), os.pathsep, os.getenv('PYTHONPATH', ''))) 
    2526os.system('PM/PacketManipulator')