Exemplo n.º 1
0
    def test_search(self):
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes6.constraints')
        results = api.search_record(self.memory_handler, self.node,
                                    my_constraints)
        # 2 from test1
        # 3 from test_pointer_to_list
        # the rest have bad values in constrainged fields
        self.assertEqual(len(results), 2 + 3)
        # FIXME: that is a weird idea, that allocations are ordered that way
        (node1, offset1), (node2, offset2) = results[:2]
        self.assertEqual(node1.val1, 0xdeadbeef)
        self.assertEqual(node1.val2, 0xffffffff)
        self.assertEqual(node2.val1, 0xdeadbabe)
        self.assertEqual(node2.val2, 0xffffffff)

        # FIXME there is a circular reference in json.
        #with self.assertRaises(ValueError):
        #    api.output_to_json(self.memory_handler, results)
        #self.assertEqual(node2s['val1'], 0xdeadbabe)
        #self.assertEqual(node2s['val2'], 0xffffffff)
        model = self.memory_handler.get_model()
        #import code
        #code.interact(local=locals())
        x = api.output_to_pickle(self.memory_handler, results)
        rest = pickle.loads(x)
        return
Exemplo n.º 2
0
    def test_search(self):
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes6.constraints')
        results = api.search_record(self.memory_handler, self.node, my_constraints)
        # 2 from test1
        # 3 from test_pointer_to_list
        # the rest have bad values in constrainged fields
        self.assertEqual(len(results), 2 + 3)
        # FIXME: that is a weird idea, that allocations are ordered that way
        (node1, offset1), (node2, offset2) = results[:2]
        self.assertEqual(node1.val1, 0xdeadbeef)
        self.assertEqual(node1.val2, 0xffffffff)
        self.assertEqual(node2.val1, 0xdeadbabe)
        self.assertEqual(node2.val2, 0xffffffff)

        # FIXME there is a circular reference in json.
        #with self.assertRaises(ValueError):
        #    api.output_to_json(self.memory_handler, results)
        #self.assertEqual(node2s['val1'], 0xdeadbabe)
        #self.assertEqual(node2s['val2'], 0xffffffff)
        model = self.memory_handler.get_model()
        #import code
        #code.interact(local=locals())
        x = api.output_to_pickle(self.memory_handler, results)
        rest = pickle.loads(x)
        return
Exemplo n.º 3
0
def refresh(args):
    """
    Default function for the refresh command line option.
    Try to map a Structure from a specific offset in memory.
    Returns it in pickled or text format.

    See the command line --help .
    """
    # we need an int
    memory_address = args.addr
    # get the memory handler adequate for the type requested
    memory_handler = _get_memory_handler(args)
    # print output on stdout
    rtype = _get_output_style(args)
    # check the validity of the address
    heap = memory_handler.is_valid_address_value(memory_address)
    if not heap:
        log.error("the address is not accessible in the memoryMap")
        raise ValueError("the address is not accessible in the memoryMap")
    # get the structure name
    modulename, sep, classname = args.struct_name.rpartition('.')
    module = memory_handler.get_model().import_module(modulename)
    struct_type = getattr(module, classname)
    # load the record
    result = api.load_record(memory_handler, struct_type, memory_address)
    results = [result]
    if args.validate:
        my_constraints = None
        if args.constraints_file:
            handler = constraints.ConstraintsConfigHandler()
            my_constraints = handler.read(args.constraints_file.name)
        validation = api.validate_record(memory_handler, result[0],
                                         my_constraints)
    if args.interactive:
        import code
        code.interact(local=locals())
    # output handling
    ret = None
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    print ret
    if args.validate:
        print 'Validated', validation
    return
Exemplo n.º 4
0
def get_output(memory_handler, results, rtype):
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        # useful in interactive mode
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    return ret
Exemplo n.º 5
0
def get_output(memory_handler, results, rtype):
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        # useful in interactive mode
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    return ret
Exemplo n.º 6
0
def refresh(args):
    """
    Default function for the refresh command line option.
    Try to map a Structure from a specific offset in memory.
    Returns it in pickled or text format.

    See the command line --help .
    """
    # we need an int
    memory_address = args.addr
    # get the memory handler adequate for the type requested
    memory_handler = _get_memory_handler(args)
    # print output on stdout
    rtype = _get_output_style(args)
    # check the validity of the address
    heap = memory_handler.is_valid_address_value(memory_address)
    if not heap:
        log.error("the address is not accessible in the memoryMap")
        raise ValueError("the address is not accessible in the memoryMap")
    # get the structure name
    modulename, sep, classname = args.struct_name.rpartition('.')
    module = memory_handler.get_model().import_module(modulename)
    struct_type = getattr(module, classname)
    # load the record
    result = api.load_record(memory_handler, struct_type, memory_address)
    results = [result]
    if args.validate:
        my_constraints = None
        if args.constraints_file:
            handler = constraints.ConstraintsConfigHandler()
            my_constraints = handler.read(args.constraints_file.name)
        validation = api.validate_record(memory_handler, result[0], my_constraints)
    if args.interactive:
        import code
        code.interact(local=locals())
    # output handling
    ret = None
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    print ret
    if args.validate:
        print 'Validated', validation
    return
Exemplo n.º 7
0
def search_cmdline(args):
    """ Internal cmdline mojo. """
    # get the memory handler adequate for the type requested
    memory_handler = _get_memory_handler(args)
    # print output on stdout
    rtype = _get_output_style(args)
    # try to load constraints
    # mapper
    if args.constraints_file:
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read(args.constraints_file.name)
    else:
        my_constraints = None
    # get the structure name
    modulename, sep, classname = args.struct_name.rpartition('.')
    module = memory_handler.get_model().import_module(modulename)
    struct_type = getattr(module, classname)
    # do the search
    results = api.search_record(memory_handler,
                                struct_type,
                                my_constraints,
                                extended_search=args.extended_search)
    if args.interactive:
        import code
        code.interact(local=locals())
    # output handling
    ret = None
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    print ret
    return
Exemplo n.º 8
0
    def test_search(self):
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes6.constraints')
        results = haystack.search_record(self.memory_handler, self.node,
                                         my_constraints)
        self.assertEquals(len(results), 2)
        (node1, offset1), (node2, offset2) = results
        self.assertEquals(node1.val1, 0xdeadbeef)
        self.assertEquals(node1.val2, 0xffffffff)
        self.assertEquals(node2.val1, 0xdeadbabe)
        self.assertEquals(node2.val2, 0xffffffff)

        # FIXME there is a circular reference in json.
        #with self.assertRaises(ValueError):
        #    haystack.output_to_json(self.memory_handler, results)
        #self.assertEquals(node2s['val1'], 0xdeadbabe)
        #self.assertEquals(node2s['val2'], 0xffffffff)
        model = self.memory_handler.get_model()
        #import code
        #code.interact(local=locals())
        x = api.output_to_pickle(self.memory_handler, results)
        rest = pickle.loads(x)
        return
Exemplo n.º 9
0
def search_cmdline(args):
    """ Internal cmdline mojo. """
    # get the memory handler adequate for the type requested
    memory_handler = _get_memory_handler(args)
    # print output on stdout
    rtype = _get_output_style(args)
    # try to load constraints
    # mapper
    if args.constraints_file:
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read(args.constraints_file.name)
    else:
        my_constraints = None
    # get the structure name
    modulename, sep, classname = args.struct_name.rpartition('.')
    module = memory_handler.get_model().import_module(modulename)
    struct_type = getattr(module, classname)
    # do the search
    results = api.search_record(memory_handler, struct_type, my_constraints, extended_search=args.extended_search)
    if args.interactive:
        import code
        code.interact(local=locals())
    # output handling
    ret = None
    if rtype == 'string':
        ret = api.output_to_string(memory_handler, results)
    elif rtype == 'python':
        ret = api.output_to_python(memory_handler, results)
    elif rtype == 'json':
        ret = api.output_to_json(memory_handler, results)
    elif rtype == 'pickled':
        ret = api.output_to_pickle(memory_handler, results)
    else:
        raise ValueError('unknown output format')
    print ret
    return