Exemple #1
0
class GdbPluginTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def setup_avatar_gdb_server(self):

        self.avatar = avatar2.Avatar(arch=avatar2.archs.X86_64)
        self.gdb_target = self.avatar.add_target(avatar2.GDBTarget,
                                                 gdb_port=AV_GDB_PORT)

        self.avatar.init_targets()
        self.avatar.load_plugin('gdbserver')
        self.sk = self.avatar.spawn_gdb_server(self.gdb_target, PORT, True,
                                               XML_PATH)

    def setup_env(self, binary):

        self.process = subprocess.Popen(
            ['gdbserver', '--once',
             '127.0.0.1:%d' % AV_GDB_PORT, binary],
            stderr=subprocess.PIPE)

        out = str(self.process.stderr.readline())
        self.assertEqual(binary in out, True, out)
        out = str(self.process.stderr.readline())
        self.assertEqual(str(AV_GDB_PORT) in out, True, out)

        # create avatar instance offering the gdbserver
        self.setup_avatar_gdb_server()

        self.gdb = GDBProtocol(arch=avatar2.archs.X86_64)
        self.gdb.remote_connect(port=PORT)

    def wait_stopped(self):
        # As we do not have access to avatar synchronizing target states
        # on this level, we apply this little hack to synchronize the target
        while True:
            ret, out = self.gdb.console_command('info program')
            if 'Program stopped' in out:
                break
            time.sleep(SLEEP_TIME)

    def tearDown(self):
        self.sk.shutdown()
        self.avatar.shutdown()
        self.gdb.shutdown()
        self.process.terminate()
Exemple #2
0
class GdbProtocolTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def setup_env(self, binary, unix_socket=False):

        self.process = subprocess.Popen(
            ['gdbserver', '--once',
             '127.0.0.1:%d' % PORT, binary],
            stderr=subprocess.PIPE)

        out = str(self.process.stderr.readline())
        self.assertEqual(binary in out, True, out)
        out = str(self.process.stderr.readline())
        self.assertEqual(str(PORT) in out, True, out)

        self.gdb = GDBProtocol(arch=avatar2.archs.X86_64)

        if unix_socket is True:
            socket_path = '/tmp/test_socket'
            unix2tcp(socket_path, "127.0.0.1", PORT)
            self.gdb.remote_connect_unix(socket_path)

        else:
            self.gdb.remote_connect(port=PORT)

        # Base addresses can change across kernel versions due to PIE binaries
        self.base_address = self.gdb.get_symbol("main")[1] & ~0xfff

    def wait_stopped(self):
        # As we do not have access to avatar synchronizing target states
        # on this level, we apply this little hack to synchronize the target
        while True:
            ret, out = self.gdb.console_command('info program')
            if 'Program stopped' in out:
                break
            time.sleep(SLEEP_TIME)

    def tearDown(self):
        self.gdb.shutdown()
        self.process.terminate()