def _aggregateFields(self): #if not self.pointerResolved: # raise ValueError('I should be resolved') self._dirty = True self._fields.sort() myfields = [] signature = self.getSignature() pencoder = pattern.PatternEncoder(signature, minGroupSize=3) patterns = pencoder.makePattern() #txt = self.getSignature(text=True) #log.warning('signature of len():%d, %s'%(len(txt),txt)) #p = pattern.findPatternText(txt, 2, 3) #log.debug(p) #log.debug('aggregateFields came up with pattern %s'%(patterns)) # pattern is made on FieldType, #so we need to dequeue self.fields at the same time to enqueue in myfields for nb, fieldTypesAndSizes in patterns: #print 'fieldTypesAndSizes:',fieldTypesAndSizes if nb == 1: fieldType = fieldTypesAndSizes[0] # its a tuple field = self._fields.pop(0) myfields.append(field) # single el #log.debug('simple field:%s '%(field) ) elif len(fieldTypesAndSizes ) > 1: # array of subtructure DEBUG XXX TODO log.debug('substructure with sig %s' % (fieldTypesAndSizes)) myelements = [] for i in range(nb): fields = [ self._fields.pop(0) for i in range(len(fieldTypesAndSizes)) ] # nb-1 left #otherFields = [ self.fields.pop(0) for i in range((nb-1)*len(fieldTypesAndSizes)) ] # need global ref to compare substructure signature to other anonstructure firstField = FieldType.makeStructField( self, fields[0].offset, fields) myelements.append(firstField) array = makeArrayField(self, myelements) myfields.append(array) #log.debug('array of structure %s'%(array)) elif len(fieldTypesAndSizes) == 1: #make array of elements or log.debug('found array of %s' % (self._fields[0].typename.basename)) fields = [self.fields.pop(0) for i in range(nb)] array = makeArrayField(self, fields) myfields.append(array) #log.debug('array of elements %s'%(array)) else: # TODO DEBUG internal struct raise ValueError('fields patterns len is incorrect %d' % (len(fieldTypesAndSizes))) log.debug('done with aggregateFields') self._fields = myfields #print 'final', self.fields return
def _findSubStructures(self): if not self._pointerResolved: raise ValueError('I should be resolved') self._dirty = True self._fields.sort() myfields = [] signature = self.getTypeSignature() pencoder = pattern.PatternEncoder(signature, minGroupSize=2) patterns = pencoder.makePattern() txt = self.getTypeSignature(text=True) p = pattern.findPatternText(txt, 1, 2) log.debug('substruct typeSig: %s' % txt) log.debug('substruct findPatterntext: %s' % p) log.debug('substruct came up with pattern %s' % (patterns)) # pattern is made on FieldType, #so we need to dequeue self.fields at the same time to enqueue in myfields for nb, fieldTypes in patterns: if nb == 1: field = self._fields.pop(0) myfields.append(field) # single el #log.debug('simple field:%s '%(field) ) elif len(fieldTypes) > 1: # array of subtructure DEBUG XXX TODO log.debug('fieldTypes:%s' % fieldTypes) log.debug('substructure with sig %s' % (''.join([ft.sig[0] for ft in fieldTypes]))) myelements = [] for i in range(nb): fields = [ self._fields.pop(0) for i in range(len(fieldTypes)) ] # nb-1 left #otherFields = [ self.fields.pop(0) for i in range((nb-1)*len(fieldTypesAndSizes)) ] # need global ref to compare substructure signature to other anonstructure firstField = FieldType.makeStructField( self, fields[0].offset, fields) myelements.append(firstField) array = makeArrayField(self, myelements) myfields.append(array) #log.debug('array of structure %s'%(array)) elif len(fieldTypes ) == 1: #make array of elements obase on same base type log.debug('found array of %s' % (self._fields[0].typename.basename)) fields = [self._fields.pop(0) for i in range(nb)] array = makeArrayField(self, fields) myfields.append(array) #log.debug('array of elements %s'%(array)) else: # TODO DEBUG internal struct raise ValueError('fields patterns len is incorrect %d' % (len(fieldTypes))) log.debug('done with findSubstructure') self._fields = myfields #print 'final', self.fields return
def _aggregateFields(self): # if not self.resolvedPointers: # raise ValueError('I should be resolved') self._dirty = True self._fields.sort() myfields = [] signature = self.getSignature() pencoder = pattern.PatternEncoder(signature, minGroupSize=3) patterns = pencoder.makePattern() # txt = self.getSignature(text=True) # log.warning('signature of len():%d, %s'%(len(txt),txt)) # p = pattern.findPatternText(txt, 2, 3) # log.debug(p) # log.debug('aggregateFields came up with pattern %s'%(patterns)) # pattern is made on FieldType, # so we need to dequeue self.fields at the same time to enqueue in # myfields for nb, fieldTypesAndSizes in patterns: # print 'fieldTypesAndSizes:',fieldTypesAndSizes if nb == 1: fieldType = fieldTypesAndSizes[0] # its a tuple field = self._fields.pop(0) myfields.append(field) # single el # log.debug('simple field:%s '%(field) ) # array of subtructure DEBUG XXX TODO elif len(fieldTypesAndSizes) > 1: log.debug("substructure with sig %s" % (fieldTypesAndSizes)) myelements = [] for i in range(nb): fields = [self._fields.pop(0) for i in range(len(fieldTypesAndSizes))] # nb-1 left # otherFields = [ self.fields.pop(0) for i in range((nb-1)*len(fieldTypesAndSizes)) ] # need global ref to compare substructure signature to # other anonstructure firstField = FieldType.makeStructField(self, fields[0].offset, fields) myelements.append(firstField) array = makeArrayField(self, myelements) myfields.append(array) # log.debug('array of structure %s'%(array)) elif len(fieldTypesAndSizes) == 1: # make array of elements or log.debug("found array of %s" % (self._fields[0].typename.basename)) fields = [self.fields.pop(0) for i in range(nb)] array = makeArrayField(self, fields) myfields.append(array) # log.debug('array of elements %s'%(array)) else: # TODO DEBUG internal struct raise ValueError("fields patterns len is incorrect %d" % (len(fieldTypesAndSizes))) log.debug("done with aggregateFields") self._fields = myfields # print 'final', self.fields return
def _findSubStructures(self): if not self.resolvedPointers: raise ValueError("I should be resolved") self._dirty = True self._fields.sort() myfields = [] signature = self.getTypeSignature() pencoder = pattern.PatternEncoder(signature, minGroupSize=2) patterns = pencoder.makePattern() txt = self.getTypeSignature(text=True) p = pattern.findPatternText(txt, 1, 2) log.debug("substruct typeSig: %s" % txt) log.debug("substruct findPatterntext: %s" % p) log.debug("substruct came up with pattern %s" % (patterns)) # pattern is made on FieldType, # so we need to dequeue self.fields at the same time to enqueue in # myfields for nb, fieldTypes in patterns: if nb == 1: field = self._fields.pop(0) myfields.append(field) # single el # log.debug('simple field:%s '%(field) ) elif len(fieldTypes) > 1: # array of subtructure DEBUG XXX TODO log.debug("fieldTypes:%s" % fieldTypes) log.debug("substructure with sig %s" % ("".join([ft.sig[0] for ft in fieldTypes]))) myelements = [] for i in range(nb): fields = [self._fields.pop(0) for i in range(len(fieldTypes))] # nb-1 left # otherFields = [ self.fields.pop(0) for i in range((nb-1)*len(fieldTypesAndSizes)) ] # need global ref to compare substructure signature to # other anonstructure firstField = FieldType.makeStructField(self, fields[0].offset, fields) myelements.append(firstField) array = makeArrayField(self, myelements) myfields.append(array) # log.debug('array of structure %s'%(array)) # make array of elements obase on same base type elif len(fieldTypes) == 1: log.debug("found array of %s" % (self._fields[0].typename.basename)) fields = [self._fields.pop(0) for i in range(nb)] array = makeArrayField(self, fields) myfields.append(array) # log.debug('array of elements %s'%(array)) else: # TODO DEBUG internal struct raise ValueError("fields patterns len is incorrect %d" % (len(fieldTypes))) log.debug("done with findSubstructure") self._fields = myfields # print 'final', self.fields return
def _aggZeroesBetweenIntArrays(self): if len(self._fields) < 3: return self._dirty=True myfields = sorted(self._fields) i = 0 while ( i < len(myfields) - 3 ): prev = myfields[i] field = myfields[i+1] next = myfields[i+2] if prev.isArray() and next.isArray() and field.isZeroes() and ( fieldtypes.isIntegerType(prev.basicTypename) and fieldtypes.isIntegerType(next.basicTypename) ): # we have zeroes in the middle fieldLen = len(field) nbWord = fieldLen//Config.WORDSIZE if (fieldLen % Config.WORDSIZE == 0) and nbWord < 4: # more than 3 word zerroes it is probably another buffer # concat prev, field and next arrays to get on array newFields = prev.elements+[field] field.checkSmallInt() # force it in a small integer if nbWord > 1: for offsetadd in range(Config.WORDSIZE, Config.WORDSIZE*nbWord, Config.WORDSIZE): newFields.append(self._addField(field.offset+offsetadd, FieldType.SMALLINT, Config.WORDSIZE, False)) newFields.extend(next.elements) # make an array for newFields and insert it in place of prev+field+next # pop prev, newfields and next, and put them in an array #print 'aggZeroes', i, len(newFields)#, ','.join([f.toString('') for f in newFields]) drop = [ myfields.pop(i) for x in range(3) ] #prev, array = makeArrayField(self, newFields ) myfields.insert(i, array) # i+=1 self._fields = myfields return
def cutInThree(): log.debug('cutting in three %d %d %d'%(ind, nbSeen, val)) # cut array in three index = self._fields.index(_arrayField) oldArray = self._fields.pop(index) # cut it from self.fields # cut the field in 3 parts ( ?zerroes, val, list) # add the rest if len(_arrayField.elements[ind+1:]) > 1: # add zerroes in front self._fields.insert(index, makeArrayField(self, _arrayField.elements[ind+1:]) ) elif len(_arrayField.elements[ind+1:]) == 1: # add zero field self._fields.insert(index, _arrayField.elements[ind+1]) # add the value self._fields.insert(index, _arrayField.elements[ind]) # add zerroes in front if ind > 1: self._fields.insert(index, makeArrayField(self, _arrayField.elements[:ind]) ) elif ind == 1: # add zero field self._fields.insert(index, _arrayField.elements[0])
def cutInThree(): log.debug('cutting in three %d %d %d' % (ind, nbSeen, val)) # cut array in three index = self._fields.index(_arrayField) oldArray = self._fields.pop(index) # cut it from self.fields # cut the field in 3 parts ( ?zerroes, val, list) # add the rest if len(_arrayField.elements[ind + 1:]) > 1: # add zerroes in front self._fields.insert( index, makeArrayField(self, _arrayField.elements[ind + 1:])) elif len(_arrayField.elements[ind + 1:]) == 1: # add zero field self._fields.insert(index, _arrayField.elements[ind + 1]) # add the value self._fields.insert(index, _arrayField.elements[ind]) # add zerroes in front if ind > 1: self._fields.insert( index, makeArrayField(self, _arrayField.elements[:ind])) elif ind == 1: # add zero field self._fields.insert(index, _arrayField.elements[0])
def _aggZeroesBetweenIntArrays(self): if len(self._fields) < 3: return self._dirty = True myfields = sorted(self._fields) i = 0 while (i < len(myfields) - 3): prev = myfields[i] field = myfields[i + 1] next = myfields[i + 2] if prev.isArray() and next.isArray() and field.isZeroes() and ( fieldtypes.isIntegerType(prev.basicTypename) and fieldtypes.isIntegerType(next.basicTypename)): # we have zeroes in the middle fieldLen = len(field) nbWord = fieldLen // Config.WORDSIZE if ( fieldLen % Config.WORDSIZE == 0 ) and nbWord < 4: # more than 3 word zerroes it is probably another buffer # concat prev, field and next arrays to get on array newFields = prev.elements + [field] field.checkSmallInt() # force it in a small integer if nbWord > 1: for offsetadd in range(Config.WORDSIZE, Config.WORDSIZE * nbWord, Config.WORDSIZE): newFields.append( self._addField(field.offset + offsetadd, FieldType.SMALLINT, Config.WORDSIZE, False)) newFields.extend(next.elements) # make an array for newFields and insert it in place of prev+field+next # pop prev, newfields and next, and put them in an array #print 'aggZeroes', i, len(newFields)#, ','.join([f.toString('') for f in newFields]) drop = [myfields.pop(i) for x in range(3)] #prev, array = makeArrayField(self, newFields) myfields.insert(i, array) # i += 1 self._fields = myfields return