BVB Source Codes

voltron Show gdb_cli_tests.py Source code

Return Download voltron: download gdb_cli_tests.py Source code - Download voltron Source code - Type:.py
  1. """
  2. Tests that test voltron in the gdb cli driver
  3.  
  4. Tests:
  5. Client -> Server -> GDBAdaptor
  6.  
  7. Inside a GDB instance
  8. """
  9.  
  10. from __future__ import print_function
  11.  
  12. import tempfile
  13. import sys
  14. import json
  15. import time
  16. import logging
  17. import pexpect
  18. import os
  19. import six
  20.  
  21. from mock import Mock
  22. from nose.tools import *
  23.  
  24. import voltron
  25. from voltron.core import *
  26. from voltron.api import *
  27. from voltron.plugin import PluginManager, DebuggerAdaptorPlugin
  28.  
  29. from .common import *
  30.  
  31. log = logging.getLogger('tests')
  32.  
  33. p = None
  34. client = None
  35.  
  36.  
  37. def setup():
  38.     global p, client, pm
  39.  
  40.     log.info("setting up GDB CLI tests")
  41.  
  42.     voltron.setup_env()
  43.  
  44.     # compile test inferior
  45.     pexpect.run("cc -o tests/inferior tests/inferior.c")
  46.  
  47.     # start debugger
  48.     start_debugger()
  49.  
  50.  
  51. def teardown():
  52.     read_data()
  53.     p.terminate(True)
  54.  
  55.  
  56. def start_debugger(do_break=True):
  57.     global p, client
  58.     p = pexpect.spawn('gdb')
  59.     p.sendline("python import sys;sys.path.append('/home/travis/virtualenv/python3.5.0/lib/python3.5/site-packages')")
  60.     p.sendline("python import sys;sys.path.append('/home/travis/virtualenv/python3.4.3/lib/python3.4/site-packages')")
  61.     p.sendline("python import sys;sys.path.append('/home/travis/virtualenv/python3.3.6/lib/python3.3/site-packages')")
  62.     p.sendline("python import sys;sys.path.append('/home/travis/virtualenv/python2.7.10/lib/python2.7/site-packages')")
  63.     p.sendline("source voltron/entry.py")
  64.     p.sendline("file tests/inferior")
  65.     p.sendline("set disassembly-flavor intel")
  66.     p.sendline("voltron init")
  67.     if do_break:
  68.         p.sendline("b main")
  69.     p.sendline("run loop")
  70.     read_data()
  71.  
  72.     time.sleep(5)
  73.  
  74.     client = Client()
  75.  
  76.  
  77. def stop_debugger():
  78.     # p.sendline("kill")
  79.     read_data()
  80.     p.terminate(True)
  81.  
  82.  
  83. def read_data():
  84.     try:
  85.         while True:
  86.             data = p.read_nonblocking(size=64, timeout=1)
  87.             print(data.decode('UTF-8'), end='')
  88.     except:
  89.         pass
  90.  
  91.  
  92. def restart_debugger(do_break=True):
  93.     stop_debugger()
  94.     start_debugger(do_break)
  95.  
  96.  
  97. def test_bad_request():
  98.     req = client.create_request('version')
  99.     req.request = 'xxx'
  100.     res = client.send_request(req)
  101.     assert res.is_error
  102.     assert res.code == 0x1002
  103.  
  104.  
  105. def test_version():
  106.     req = client.create_request('version')
  107.     res = client.send_request(req)
  108.     assert res.api_version == 1.1
  109.     assert 'gdb' in res.host_version
  110.  
  111.  
  112. def test_registers():
  113.     global registers
  114.     read_data()
  115.     res = client.perform_request('registers')
  116.     registers = res.registers
  117.     assert res.status == 'success'
  118.     assert len(registers) > 0
  119.     assert registers['rip'] != 0
  120.  
  121.  
  122. def test_memory():
  123.     res = client.perform_request('memory', address=registers['rip'], length=0x40)
  124.     assert res.status == 'success'
  125.     assert len(res.memory) > 0
  126.  
  127.  
  128. def test_state_stopped():
  129.     res = client.perform_request('state')
  130.     assert res.is_success
  131.     assert res.state == "stopped"
  132.  
  133.  
  134. def test_targets():
  135.     res = client.perform_request('targets')
  136.     assert res.is_success
  137.     assert res.targets[0]['state'] == "stopped"
  138.     assert res.targets[0]['arch'] == "x86_64"
  139.     assert res.targets[0]['id'] == 0
  140.     assert res.targets[0]['file'].endswith('tests/inferior')
  141.  
  142.  
  143. def test_stack():
  144.     res = client.perform_request('stack', length=0x40)
  145.     assert res.status == 'success'
  146.     assert len(res.memory) > 0
  147.  
  148.  
  149. def test_command():
  150.     res = client.perform_request('command', command="info reg")
  151.     assert res.status == 'success'
  152.     assert len(res.output) > 0
  153.     assert 'rax' in res.output
  154.  
  155.  
  156. def test_disassemble():
  157.     res = client.perform_request('disassemble', count=0x20)
  158.     assert res.status == 'success'
  159.     assert len(res.disassembly) > 0
  160.     assert 'DWORD' in res.disassembly
  161.  
  162.  
  163. def test_backtrace():
  164.     res = client.perform_request('backtrace')
  165.     print(res)
  166.     assert res.is_success
  167.     assert res.frames[0]['name'] == "main"
  168.     assert res.frames[0]['index'] == 0
  169.  
  170.  
  171. # def test_write_memory():
  172. #     value = six.b("AAAAAAAA")
  173. #     res = client.perform_request('write_memory', address=registers['rsp'], value=value)
  174. #     assert res.is_success
  175. #     res = client.perform_request('memory', address=registers['rsp'], length=len(value))
  176. #     assert res.memory == value
  177.  
downloadgdb_cli_tests.py Source code - Download voltron Source code
Related Source Codes/Software:
IGListKit - A data-driven UICollectionView framework for build... 2017-01-11
androidmvp - MVP Android Example 2017-01-11
svelte - The magical disappearing UI framework ... 2017-01-11
kcptun - A Simple UDP Tunnel Based On KCP 2017-01-11
poisontap - Exploits locked/password protected computers over ... 2017-01-10
ecma262 - Status, process, and documents for ECMA262 ... 2017-01-11
react-native-elements - React Native Elements UI Toolkit 2017-01-11
tensorflow-zh - Google new open source ai system TensorFlow Chines... 2017-01-11
forum - Blue light (the Lantern) the official BBS 2017-01-11
socketcluster - Highly scalable realtime framework ... 2017-01-11
mobile-chrome-apps - Chrome apps on Android and iOS 2017-02-20
pycrumbs - Bits and bytes of Python from the Internet 2017-02-20
drupal - Verbatim mirror of the git.drupal.org repository f... 2017-02-20
elasticsearch-head - A web front end for an elastic search cluster 2017-02-19
launchrocket - A Mac PrefPane to manage all your Homebrew-install... 2017-02-19
jquery-boilerplate - A jump-start for jQuery plugins development ... 2017-02-19
MVVMReactiveCocoa - GitBucket iOS A 2017-02-19
ios-webkit-debug-proxy - A DevTools proxy (Chrome Remote Debugging Protocol... 2017-02-19
jump.js - A modern smooth scrolling library. ... 2017-02-19
GoSublime - A Golang plugin collection for SublimeText **3**, ... 2017-02-19

 Back to top