BVB Source Codes

voltron Show lldb_cli_tests.py Source code

Return Download voltron: download lldb_cli_tests.py Source code - Download voltron Source code - Type:.py
  1. """
  2. Tests that test voltron in the lldb cli driver
  3.  
  4. Tests:
  5. Client -> Server -> LLDBAdaptor
  6.  
  7. Inside an LLDB CLI driver instance
  8. """
  9. from __future__ import print_function
  10.  
  11. import tempfile
  12. import sys
  13. import json
  14. import time
  15. import logging
  16. import pexpect
  17. import os
  18. import tempfile
  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 LLDB 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.     time.sleep(10)
  50.  
  51.  
  52. def teardown():
  53.     read_data()
  54.     p.terminate(True)
  55.     time.sleep(2)
  56.  
  57.  
  58. def start_debugger(do_break=True):
  59.     global p, client
  60.  
  61.     if sys.platform == 'darwin':
  62.         p = pexpect.spawn('lldb')
  63.     else:
  64.         p = pexpect.spawn('lldb-3.4')
  65.  
  66.         # for travis
  67.         (f, tmpname) = tempfile.mkstemp('.py')
  68.         os.write(f, six.b('\n'.join([
  69.             "import sys",
  70.             "sys.path.append('/home/travis/virtualenv/python3.5.0/lib/python3.5/site-packages')",
  71.             "sys.path.append('/home/travis/virtualenv/python3.4.3/lib/python3.4/site-packages')",
  72.             "sys.path.append('/home/travis/virtualenv/python3.3.6/lib/python3.3/site-packages')",
  73.             "sys.path.append('/home/travis/virtualenv/python2.7.10/lib/python2.7/site-packages')"])))
  74.         p.sendline("command script import {}".format(tmpname))
  75.  
  76.     print("pid == {}".format(p.pid))
  77.     p.sendline("settings set target.x86-disassembly-flavor intel")
  78.     p.sendline("command script import voltron/entry.py")
  79.     time.sleep(2)
  80.     p.sendline("file tests/inferior")
  81.     time.sleep(2)
  82.     p.sendline("voltron init")
  83.     time.sleep(1)
  84.     p.sendline("process kill")
  85.     p.sendline("break delete 1")
  86.     if do_break:
  87.         p.sendline("b main")
  88.     p.sendline("run loop")
  89.     read_data()
  90.     client = Client()
  91.  
  92.  
  93. def stop_debugger():
  94.     p.terminate(True)
  95.  
  96.  
  97. def read_data():
  98.     try:
  99.         while True:
  100.             data = p.read_nonblocking(size=64, timeout=1)
  101.             print(data.decode('UTF-8'), end='')
  102.     except:
  103.         pass
  104.  
  105.  
  106. def restart(do_break=True):
  107.     # stop_debugger()
  108.     # start_debugger(do_break)
  109.     p.sendline("process kill")
  110.     p.sendline("break delete -f")
  111.     if do_break:
  112.         p.sendline("b main")
  113.     p.sendline("run loop")
  114.  
  115.  
  116. def test_bad_request():
  117.     req = client.create_request('version')
  118.     req.request = 'xxx'
  119.     res = client.send_request(req)
  120.     assert res.is_error
  121.     assert res.code == 0x1002
  122.     time.sleep(2)
  123.  
  124.  
  125. def test_version():
  126.     req = client.create_request('version')
  127.     res = client.send_request(req)
  128.     assert res.api_version == 1.1
  129.     assert 'lldb' in res.host_version
  130.  
  131.  
  132. def test_registers():
  133.     global registers
  134.     restart()
  135.     time.sleep(1)
  136.     read_data()
  137.     res = client.perform_request('registers')
  138.     registers = res.registers
  139.     assert res.status == 'success'
  140.     assert len(registers) > 0
  141.     if 'rip' in registers:
  142.         assert registers['rip'] != 0
  143.     else:
  144.         assert registers['eip'] != 0
  145.  
  146.  
  147. def test_memory():
  148.     restart()
  149.     time.sleep(1)
  150.     res = client.perform_request('memory', address=registers['rip'], length=0x40)
  151.     assert res.status == 'success'
  152.     assert len(res.memory) > 0
  153.  
  154.  
  155. def test_state_stopped():
  156.     restart()
  157.     time.sleep(1)
  158.     res = client.perform_request('state')
  159.     assert res.is_success
  160.     assert res.state == "stopped"
  161.  
  162.  
  163. def test_targets():
  164.     restart()
  165.     time.sleep(1)
  166.     res = client.perform_request('targets')
  167.     assert res.is_success
  168.     assert res.targets[0]['state'] == "stopped"
  169.     assert res.targets[0]['arch'] == "x86_64"
  170.     assert res.targets[0]['id'] == 0
  171.     assert res.targets[0]['file'].endswith('tests/inferior')
  172.  
  173.  
  174. def test_stack():
  175.     restart()
  176.     time.sleep(1)
  177.     res = client.perform_request('stack', length=0x40)
  178.     assert res.status == 'success'
  179.     assert len(res.memory) > 0
  180.  
  181.  
  182. def test_command():
  183.     restart()
  184.     time.sleep(1)
  185.     res = client.perform_request('command', command="reg read")
  186.     assert res.status == 'success'
  187.     assert len(res.output) > 0
  188.     assert 'rax' in res.output
  189.  
  190.  
  191. def test_disassemble():
  192.     restart()
  193.     time.sleep(1)
  194.     res = client.perform_request('disassemble', count=0x20)
  195.     assert res.status == 'success'
  196.     assert len(res.disassembly) > 0
  197.     assert 'push' in res.disassembly
  198.  
  199.  
  200. def test_dereference():
  201.     restart()
  202.     time.sleep(1)
  203.     res = client.perform_request('registers')
  204.     res = client.perform_request('dereference', pointer=res.registers['rsp'])
  205.     assert res.status == 'success'
  206.     assert res.output[0][0] == 'pointer'
  207.     assert 'start' in res.output[-1][1] or 'main' in res.output[-1][1]
  208.  
  209.  
  210. def test_breakpoints():
  211.     restart(True)
  212.     time.sleep(1)
  213.     res = client.perform_request('breakpoints')
  214.     assert res.status == 'success'
  215.     # assert len(res.breakpoints) == 1
  216.     assert res.breakpoints[0]['one_shot'] == False
  217.     assert res.breakpoints[0]['enabled']
  218.     # assert res.breakpoints[0]['id'] == 1
  219.     assert res.breakpoints[0]['hit_count'] > 0
  220.     assert res.breakpoints[0]['locations'][0]['name'] == "inferior`main"
  221.  
  222.  
  223. # def test_multi():
  224. #     global r1, r2
  225. #     restart(True)
  226. #     time.sleep(1)
  227. #     r1, r2 = None, None
  228.  
  229. #     def send_req():
  230. #         global r1, r2
  231. #         r1, r2 = client.send_requests(api_request('targets', block=True), api_request('registers', block=True))
  232. #         print "sent requests"
  233.  
  234. #     t = threading.Thread(target=send_req)
  235. #     t.start()
  236. #     time.sleep(5)
  237. #     p.sendline("stepi")
  238. #     time.sleep(5)
  239. #     t.join()
  240. #     print r1
  241. #     print r2
  242. #     assert r1.is_success
  243. #     assert r1.targets[0]['state'] == "stopped"
  244. #     assert r1.targets[0]['arch'] == "x86_64"
  245. #     assert r1.targets[0]['id'] == 0
  246. #     assert r1.targets[0]['file'].endswith('tests/inferior')
  247. #     assert r2.status == 'success'
  248. #     assert len(r2.registers) > 0
  249. #     assert r2.registers['rip'] != 0
  250.  
  251.  
  252. def test_capabilities():
  253.     restart(True)
  254.     res = client.perform_request('version')
  255.     assert res.capabilities == ['async']
  256.  
  257.  
  258. def test_backtrace():
  259.     restart(True)
  260.     time.sleep(1)
  261.     res = client.perform_request('backtrace')
  262.     print(res)
  263.     assert res.frames[0]['name'] == "inferior`main + 0"
  264.     assert res.frames[0]['index'] == 0
  265.  
downloadlldb_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
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top