def test_find_ascii(self):
     self.assertEquals(
         (-1, -1), re_string.find_ascii(self.test1, 0, len(self.test1)))
     self.assertEquals(
         (0, 43), re_string.find_ascii(
             self.test4, 0, len(
                 self.test4)))
     self.assertEquals(
         (0, 4), re_string.find_ascii(
             self.test5, 0, len(
                 self.test5)))
     self.assertEquals(
         (0, 39), re_string.find_ascii(
             self.test5, 5, len(
                 self.test5) - 5))
     self.assertEquals(
         (-1, -1), re_string.find_ascii(self.test6, 0, len(self.test6)))
     self.assertEquals(
         (0, 42), re_string.find_ascii(
             self.test6, 1, len(
                 self.test6) - 1))
     self.assertEquals(
         (-1, -1), re_string.find_ascii(self.test10, 0, len(self.test10)))  # too small
     self.assertEquals(
         (0, 10), re_string.find_ascii(
             self.test10, 3, len(
                 self.test10) - 3))
Exemple #2
0
 def make_fields(self, _record, offset, size):
     # vaddr and offset should be aligned
     assert(offset % self._word_size == 0)
     # log.debug('checking String')
     fields = []
     _bytes = _record.bytes
     while size >= self._word_size:
         # print 're_string.find_ascii(bytes, %d, %d)'%(offset,size)
         index, ssize = re_string.find_ascii(_bytes, offset, size)
         if index == 0:
             _offset = offset + index
             if (ssize < size) and _bytes[offset + index + ssize] == '\x00':  # space for a \x00
                 ssize += 1
                 f = fieldtypes.Field('strnull_%d' % _offset, _offset, fieldtypes.STRINGNULL, ssize, False)
             else:
                 f = fieldtypes.Field('str_%d' % _offset, _offset, fieldtypes.STRING, ssize, False)
             # print repr(structure.bytes[f.offset:f.offset+f.size])
             fields.append(f)
             size -= ssize  # reduce unknown field
             offset += ssize
             if ssize % self._word_size:
                 rest = self._word_size - ssize % self._word_size
                 size -= rest  # goto next aligned
                 offset += rest
         else:
             size -= self._word_size  # reduce unkown field
             offset += self._word_size
     # look in head
     return fields
Exemple #3
0
 def make_fields(self, _record, offset, size):
     # vaddr and offset should be aligned
     assert (offset % self._word_size == 0)
     # log.debug('checking String')
     fields = []
     _bytes = _record.bytes
     while size >= self._word_size:
         # print 're_string.find_ascii(bytes, %d, %d)'%(offset,size)
         index, ssize = re_string.find_ascii(_bytes, offset, size)
         if index == 0:
             _offset = offset + index
             if (ssize <
                     size) and _bytes[offset + index +
                                      ssize] == '\x00':  # space for a \x00
                 ssize += 1
                 f = fieldtypes.Field('strnull_%d' % _offset, _offset,
                                      fieldtypes.STRINGNULL, ssize, False)
             else:
                 f = fieldtypes.Field('str_%d' % _offset, _offset,
                                      fieldtypes.STRING, ssize, False)
             # print repr(structure.bytes[f.offset:f.offset+f.size])
             fields.append(f)
             size -= ssize  # reduce unknown field
             offset += ssize
             if ssize % self._word_size:
                 rest = self._word_size - ssize % self._word_size
                 size -= rest  # goto next aligned
                 offset += rest
         else:
             size -= self._word_size  # reduce unkown field
             offset += self._word_size
     # look in head
     return fields
Exemple #4
0
 def make_fields(self, structure, offset, size):
   assert( offset%Config.WORDSIZE == 0 ) #vaddr and offset should be aligned
   #log.debug('checking String')
   fields = []
   bytes = structure.bytes
   while size >= Config.WORDSIZE:
     #print 're_string.find_ascii(bytes, %d, %d)'%(offset,size)
     index, ssize = re_string.find_ascii(bytes, offset, size)
     if index == 0:
       if (ssize < size) and bytes[offset+index+ssize]=='\x00': # space for a \x00
         ssize +=1
         f = Field(structure, offset+index, FieldType.STRINGNULL, ssize, False)  
       else:
         f = Field(structure, offset+index, FieldType.STRING, ssize, False)  
       #print repr(structure.bytes[f.offset:f.offset+f.size])
       fields.append(f)
       size -= ssize # reduce unknown field
       offset += ssize
       if ssize%Config.WORDSIZE:
         rest = Config.WORDSIZE - ssize%Config.WORDSIZE
         size -= rest # goto next aligned
         offset += rest
     else:
       size -= Config.WORDSIZE # reduce unkown field
       offset += Config.WORDSIZE
   # look in head
   return fields