예제 #1
0
    def test_hasRef(self):

        model.keepRef(1, int, 0xcafecafe)
        model.keepRef(2, float, 0xcafecafe)
        model.keepRef(3, str, 0xcafecafe)

        self.assertTrue(model.hasRef(int, 0xcafecafe))
        self.assertTrue(model.hasRef(float, 0xcafecafe))
        self.assertTrue(model.hasRef(str, 0xcafecafe))
        self.assertFalse(model.hasRef(unicode, 0xcafecafe))
        self.assertFalse(model.hasRef(int, 0xdeadbeef))
예제 #2
0
  def test_hasRef(self):

    model.keepRef(1, int, 0xcafecafe)
    model.keepRef(2, float, 0xcafecafe)
    model.keepRef(3, str, 0xcafecafe)

    self.assertTrue( model.hasRef(int,0xcafecafe))
    self.assertTrue( model.hasRef(float,0xcafecafe))
    self.assertTrue( model.hasRef(str,0xcafecafe))
    self.assertFalse( model.hasRef(unicode,0xcafecafe))
    self.assertFalse( model.hasRef(int,0xdeadbeef))
예제 #3
0
  def test_keepRef(self):
    self.assertNotEqual( self.mappings, None )
      
    for fname, ftype in self.heap_obj.getFields():
      attr = getattr(self.heap_obj, fname)
      if isCStringPointer(ftype):
        # ignore that - attr_addr = getaddress(attr.ptr)
        continue
      elif isPointerType(ftype):
        attr_addr = getaddress(attr)
      else:
        continue
      if attr_addr == 0:
        continue
      self.assertTrue( utils.is_valid_address_value(attr_addr, self.mappings), '%s: 0x%x is not valid'%(fname, attr_addr))
      # the book should register struct type, not pointer to strut type
      attr_type = model.get_subtype(ftype)
      # look in the books
      saved = model.getRefByAddr( attr_addr )
      _class, _addr, _obj = saved[0]

      self.assertEquals( attr_addr, _addr)
      self.assertEquals( attr_type, _class, '%s != %s' %(type(ftype), type(_class)))
      self.assertTrue( model.hasRef( model.get_subtype(ftype), attr_addr))
    
    return      
예제 #4
0
    def test_keepRef(self):
        self.assertNotEqual(self.mappings, None)

        for fname, ftype in self.heap_obj.getFields():
            attr = getattr(self.heap_obj, fname)
            if isCStringPointer(ftype):
                # ignore that - attr_addr = getaddress(attr.ptr)
                continue
            elif isPointerType(ftype):
                attr_addr = getaddress(attr)
            else:
                continue
            if attr_addr == 0:
                continue
            self.assertTrue(
                utils.is_valid_address_value(attr_addr, self.mappings),
                '%s: 0x%x is not valid' % (fname, attr_addr))
            # the book should register struct type, not pointer to strut type
            attr_type = model.get_subtype(ftype)
            # look in the books
            saved = model.getRefByAddr(attr_addr)
            _class, _addr, _obj = saved[0]

            self.assertEquals(attr_addr, _addr)
            self.assertEquals(attr_type, _class,
                              '%s != %s' % (type(ftype), type(_class)))
            self.assertTrue(model.hasRef(model.get_subtype(ftype), attr_addr))

        return
예제 #5
0
 def toPyObject(self):
   ''' 
   Returns a Plain Old python object as a perfect copy of this ctypes object.
   array would be lists, pointers, inner structures, and circular 
   reference should be handled nicely.
   '''
   # get self class.
   #log.debug("%s %s %s_py"%(self.__class__.__module__, sys.modules[self.__class__.__module__], self.__class__.__name__) )
   my_class = getattr(sys.modules[self.__class__.__module__],"%s_py"%(self.__class__.__name__) )
   my_self = my_class()
   #keep ref
   if hasRef(my_class, ctypes.addressof(self) ):
     return getRef(my_class, ctypes.addressof(self) )
   # we are saving us in a partially resolved state, to keep from loops.
   keepRef(my_self, my_class, ctypes.addressof(self) )
   for field,typ in self.getFields():
     attr = getattr(self,field)
     member = self._attrToPyObject(attr,field,typ)
     setattr(my_self, field, member)
   # save the original type (me) and the field
   setattr(my_self, '_ctype_', type(self))
   return my_self
예제 #6
0
  def test_delRef(self):
    model.keepRef(1, int, 0xcafecafe)
    model.keepRef(2, float, 0xcafecafe)
    model.keepRef(3, str, 0xcafecafe)

    self.assertTrue( model.hasRef(int,0xcafecafe))
    self.assertTrue( model.hasRef(float,0xcafecafe))
    self.assertTrue( model.hasRef(str,0xcafecafe))

    model.delRef(str, 0xcafecafe)
    self.assertTrue( model.hasRef(int,0xcafecafe))
    self.assertTrue( model.hasRef(float,0xcafecafe))
    self.assertFalse( model.hasRef(str,0xcafecafe))

    model.delRef(str, 0xcafecafe)
    self.assertTrue( model.hasRef(int,0xcafecafe))
    self.assertTrue( model.hasRef(float,0xcafecafe))
    self.assertFalse( model.hasRef(str,0xcafecafe))

    model.delRef(int, 0xcafecafe)
    self.assertFalse( model.hasRef(int,0xcafecafe))
    self.assertTrue( model.hasRef(float,0xcafecafe))
    self.assertFalse( model.hasRef(str,0xcafecafe))

    model.delRef(float, 0xcafecafe)
    self.assertFalse( model.hasRef(int,0xcafecafe))
    self.assertFalse( model.hasRef(float,0xcafecafe))
    self.assertFalse( model.hasRef(str,0xcafecafe))
예제 #7
0
    def test_delRef(self):
        model.keepRef(1, int, 0xcafecafe)
        model.keepRef(2, float, 0xcafecafe)
        model.keepRef(3, str, 0xcafecafe)

        self.assertTrue(model.hasRef(int, 0xcafecafe))
        self.assertTrue(model.hasRef(float, 0xcafecafe))
        self.assertTrue(model.hasRef(str, 0xcafecafe))

        model.delRef(str, 0xcafecafe)
        self.assertTrue(model.hasRef(int, 0xcafecafe))
        self.assertTrue(model.hasRef(float, 0xcafecafe))
        self.assertFalse(model.hasRef(str, 0xcafecafe))

        model.delRef(str, 0xcafecafe)
        self.assertTrue(model.hasRef(int, 0xcafecafe))
        self.assertTrue(model.hasRef(float, 0xcafecafe))
        self.assertFalse(model.hasRef(str, 0xcafecafe))

        model.delRef(int, 0xcafecafe)
        self.assertFalse(model.hasRef(int, 0xcafecafe))
        self.assertTrue(model.hasRef(float, 0xcafecafe))
        self.assertFalse(model.hasRef(str, 0xcafecafe))

        model.delRef(float, 0xcafecafe)
        self.assertFalse(model.hasRef(int, 0xcafecafe))
        self.assertFalse(model.hasRef(float, 0xcafecafe))
        self.assertFalse(model.hasRef(str, 0xcafecafe))