コード例 #1
0
ファイル: abouchet.py プロジェクト: Macdawr/python-haystack
def _output(outs, rtype ):
  """ Return results in the rtype format"""
  if len(outs) == 0:
    log.info('Found no occurence.')
    raise StopIteration
  if rtype == 'string':
    yield '['
    for ss, addr in outs:
      yield "# --------------- 0x%lx \n%s"% (addr, ss.toString() )
      pass
    yield ']'
    raise StopIteration    
  #else {'json', 'pickled'} : # cast in pyObject
  from haystack import basicmodel # TODO replace by instance method fincCtypesinpyobj
  ret = [ (ss.toPyObject(), addr) for ss, addr in outs]
  # last check to clean the structure from any ctypes Structure
  if basicmodel.findCtypesInPyObj(ret):
    raise HaystackError('Bug in framework, some Ctypes are still in the return results. Please Report test unit.')
  # finally 
  if rtype == 'python': # pyobj
    yield ret
  elif rtype == 'json': #jsoned
    yield json.dumps(ret, default=basicmodel.json_encode_pyobj ) #cirular refs kills it check_circular=False, 
  elif rtype == 'pickled': #pickled
    yield pickle.dumps(ret)
  raise StopIteration
コード例 #2
0
ファイル: abouchet.py プロジェクト: Macdawr/python-haystack
def searchIn(structName, mappings, targetMappings=None, maxNum=-1):
  """
    Search a structure in a specific memory mapping.
    
    if targetMappings is not specified, the search will occur in each memory mappings
     in mappings.
    
    :param structName the structure name.
    :param mappings the memory mappings list.
    :param targetMappings the list of specific mapping to look into.
    :param maxNum the maximum number of results expected. -1 for infinite.
  """
  from haystack import basicmodel # TODO replace by instance method
  log.debug('searchIn: %s - %s'%(structName,mappings))
  structType = getKlass(structName)
  finder = StructFinder(mappings, targetMappings)
  # find all possible structType instance
  outs=finder.find_struct( structType, maxNum=maxNum)
  # prepare outputs
  ret=[ (ss.toPyObject(),addr) for ss, addr in outs]
  if len(ret) >0:
    log.debug("%s %s"%(ret[0], type(ret[0]) )   )
  if basicmodel.findCtypesInPyObj(ret):
    log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ')
  return ret
コード例 #3
0
ファイル: abouchet.py プロジェクト: RanchoIce/python-haystack
def _show_output(instance, validated, rtype):
    """ Return results in the rtype format"""
    if not validated:
        str_fn = lambda x: str(x)
    else:
        str_fn = lambda x: x.toString()

    if rtype == 'string':
        return "(%s\n, %s)" % (str_fn(instance), validated)
    #else {'json', 'pickled', 'python'} : # cast in pyObject
    pyObj = instance.toPyObject()
    from haystack import basicmodel  # TODO replace by isntance method finctypesinpyobj
    # last check to clean the structure from any ctypes Structure
    if basicmodel.findCtypesInPyObj(pyObj):
        raise HaystackError(
            'Bug in framework, some Ctypes are still in the return results. Please Report test unit.'
        )
    # finally
    if rtype == 'python':  # pyobj
        return (pyObj, validated)
    elif rtype == 'json':  #jsoned
        return json.dumps((pyObj, validated),
                          default=basicmodel.json_encode_pyobj
                          )  #cirular refs kills it check_circular=False,
    elif rtype == 'pickled':  #pickled
        return pickle.dumps((pyObj, validated))

    raise ValueError('rtype should have a valid value')
コード例 #4
0
ファイル: abouchet.py プロジェクト: RanchoIce/python-haystack
def _output(outs, rtype):
    """ Return results in the rtype format"""
    if len(outs) == 0:
        log.info('Found no occurence.')
        raise StopIteration
    if rtype == 'string':
        yield '['
        for ss, addr in outs:
            yield "# --------------- 0x%lx \n%s" % (addr, ss.toString())
            pass
        yield ']'
        raise StopIteration
    #else {'json', 'pickled'} : # cast in pyObject
    from haystack import basicmodel  # TODO replace by instance method fincCtypesinpyobj
    ret = [(ss.toPyObject(), addr) for ss, addr in outs]
    # last check to clean the structure from any ctypes Structure
    if basicmodel.findCtypesInPyObj(ret):
        raise HaystackError(
            'Bug in framework, some Ctypes are still in the return results. Please Report test unit.'
        )
    # finally
    if rtype == 'python':  # pyobj
        yield ret
    elif rtype == 'json':  #jsoned
        yield json.dumps(ret, default=basicmodel.json_encode_pyobj
                         )  #cirular refs kills it check_circular=False,
    elif rtype == 'pickled':  #pickled
        yield pickle.dumps(ret)
    raise StopIteration
コード例 #5
0
ファイル: abouchet.py プロジェクト: RanchoIce/python-haystack
def searchIn(structName, mappings, targetMappings=None, maxNum=-1):
    """
    Search a structure in a specific memory mapping.
    
    if targetMappings is not specified, the search will occur in each memory mappings
     in mappings.
    
    :param structName the structure name.
    :param mappings the memory mappings list.
    :param targetMappings the list of specific mapping to look into.
    :param maxNum the maximum number of results expected. -1 for infinite.
  """
    from haystack import basicmodel  # TODO replace by instance method
    log.debug('searchIn: %s - %s' % (structName, mappings))
    structType = getKlass(structName)
    finder = StructFinder(mappings, targetMappings)
    # find all possible structType instance
    outs = finder.find_struct(structType, maxNum=maxNum)
    # prepare outputs
    ret = [(ss.toPyObject(), addr) for ss, addr in outs]
    if len(ret) > 0:
        log.debug("%s %s" % (ret[0], type(ret[0])))
    if basicmodel.findCtypesInPyObj(ret):
        log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ')
    return ret
コード例 #6
0
ファイル: abouchet.py プロジェクト: Macdawr/python-haystack
def _show_output(instance, validated, rtype ):
  """ Return results in the rtype format"""
  if not validated :
    str_fn = lambda x: str(x)
  else:
    str_fn = lambda x: x.toString()

  if rtype == 'string':
    return "(%s\n, %s)"% ( str_fn(instance), validated )
  #else {'json', 'pickled', 'python'} : # cast in pyObject
  pyObj = instance.toPyObject()
  from haystack import basicmodel # TODO replace by isntance method finctypesinpyobj
  # last check to clean the structure from any ctypes Structure
  if basicmodel.findCtypesInPyObj(pyObj):
    raise HaystackError('Bug in framework, some Ctypes are still in the return results. Please Report test unit.')
  # finally 
  if rtype == 'python': # pyobj
    return (pyObj, validated)
  elif rtype == 'json': #jsoned
    return json.dumps( (pyObj, validated), default=basicmodel.json_encode_pyobj ) #cirular refs kills it check_circular=False, 
  elif rtype == 'pickled': #pickled
    return pickle.dumps((pyObj, validated))
  
  raise ValueError('rtype should have a valid value')