BVB Source Codes

voltron Show frontend_tests.py Source code

Return Download voltron: download frontend_tests.py Source code - Download voltron Source code - Type:.py
  1. """
  2. These tests load an inferior into an LLDB instance and then issue API requests
  3. using the client.
  4.  
  5. Tests:
  6. Client -> Server -> LLDBAdaptor
  7.  
  8. Using an instantiated SBDebugger instance
  9. """
  10.  
  11. import tempfile
  12. import sys
  13. import json
  14. import time
  15. import logging
  16. import subprocess
  17. import time
  18.  
  19. from mock import Mock
  20. from nose.tools import *
  21.  
  22. import voltron
  23. from voltron.core import *
  24. from voltron.api import *
  25. from voltron.plugin import *
  26.  
  27. import platform
  28. if platform.system() == 'Darwin':
  29.     sys.path.append("/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python")
  30.  
  31. try:
  32.     import lldb
  33.  
  34.     from .common import *
  35.  
  36.     log = logging.getLogger("tests")
  37.  
  38.     def setup():
  39.         global server, client, target, pm, adaptor, methods
  40.  
  41.         log.info("setting up API tests")
  42.  
  43.         # set up voltron
  44.         voltron.setup_env()
  45.         pm = PluginManager()
  46.         plugin = pm.debugger_plugin_for_host('lldb')
  47.         adaptor = plugin.adaptor_class()
  48.         voltron.debugger = adaptor
  49.  
  50.         # start up a voltron server
  51.         server = Server()
  52.         # import pdb;pdb.set_trace()
  53.         server.start()
  54.  
  55.         time.sleep(0.1)
  56.  
  57.         # set up client
  58.         client = Client()
  59.  
  60.         # compile and load the test inferior
  61.         subprocess.call("cc -o tests/inferior tests/inferior.c", shell=True)
  62.         target = adaptor.host.CreateTargetWithFileAndArch("tests/inferior", lldb.LLDB_ARCH_DEFAULT)
  63.         main_bp = target.BreakpointCreateByName("main", target.GetExecutable().GetFilename())
  64.  
  65.     def teardown():
  66.         server.stop()
  67.         time.sleep(5)
  68.  
  69.     def test_state_no_target():
  70.         req = api_request('state')
  71.         res = client.send_request(req)
  72.         assert res.is_error
  73.         assert res.code == 4101
  74.  
  75.     def test_state_stopped():
  76.         process = target.LaunchSimple(None, None, os.getcwd())
  77.         req = api_request('state')
  78.         res = client.send_request(req)
  79.         assert res.status == 'success'
  80.         assert res.state == "stopped"
  81.         target.process.Destroy()
  82.  
  83.     def test_targets():
  84.         req = api_request('targets')
  85.         res = client.send_request(req)
  86.         assert res.status == 'success'
  87.         t = res.targets[0]
  88.         assert t["id"] == 0
  89.         assert t["arch"] == "x86_64"
  90.         assert t["file"].endswith("inferior")
  91.  
  92.     def test_registers():
  93.         process = target.LaunchSimple(None, None, os.getcwd())
  94.         req = api_request('registers')
  95.         res = client.send_request(req)
  96.         assert res.status == 'success'
  97.         assert len(res.registers) > 0
  98.         assert res.registers['rip'] != 0
  99.         target.process.Destroy()
  100.  
  101.     def test_memory():
  102.         process = target.LaunchSimple(None, None, os.getcwd())
  103.         res = client.perform_request('registers')
  104.         rsp = res.registers['rsp']
  105.         res = client.perform_request('memory', address=rsp, length=0x40)
  106.         assert res.status == 'success'
  107.         assert len(res.memory) > 0
  108.         res = client.perform_request('memory', address=rsp, length=0x40, deref=True)
  109.         assert res.status == 'success'
  110.         assert len(res.deref) > 0
  111.         target.process.Destroy()
  112.  
  113.     def test_stack():
  114.         process = target.LaunchSimple(None, None, os.getcwd())
  115.         req = api_request('stack', length=0x40)
  116.         res = client.send_request(req)
  117.         assert res.status == 'success'
  118.         assert len(res.memory) > 0
  119.         target.process.Destroy()
  120.  
  121.     def test_command():
  122.         process = target.LaunchSimple(None, None, os.getcwd())
  123.         req = api_request('command', command="reg read")
  124.         res = client.send_request(req)
  125.         assert res.status == 'success'
  126.         assert len(res.output) > 0
  127.         assert 'rax' in res.output
  128.         target.process.Destroy()
  129.  
  130.     def test_disassemble():
  131.         process = target.LaunchSimple(None, None, os.getcwd())
  132.         req = api_request('disassemble', count=16)
  133.         res = client.send_request(req)
  134.         assert res.status == 'success'
  135.         assert len(res.disassembly) > 0
  136.         assert 'push' in res.disassembly
  137.         req = api_request('disassemble', count=16, use_capstone=True)
  138.         res = client.send_request(req)
  139.         assert res.status == 'success'
  140.         assert len(res.disassembly) > 0
  141.         assert 'push' in res.disassembly
  142.         target.process.Destroy()
  143.  
  144.     def test_dereference():
  145.         process = target.LaunchSimple(None, None, os.getcwd())
  146.         res = client.perform_request('registers')
  147.         res = client.perform_request('dereference', pointer=res.registers['rsp'])
  148.         assert res.status == 'success'
  149.         assert res.output[0][0] == 'pointer'
  150.         assert res.output[-1][1] == 'start + 0x1'
  151.         target.process.Destroy()
  152.  
  153.     def test_breakpoints():
  154.         process = target.LaunchSimple(None, None, os.getcwd())
  155.         res = client.perform_request('breakpoints')
  156.         assert res.status == 'success'
  157.         assert len(res.breakpoints) == 1
  158.         assert res.breakpoints[0]['one_shot'] == False
  159.         assert res.breakpoints[0]['enabled']
  160.         assert res.breakpoints[0]['id'] == 1
  161.         assert res.breakpoints[0]['hit_count'] > 0
  162.         assert res.breakpoints[0]['locations'][0]['name'] == "inferior`main"
  163.         target.process.Destroy()
  164.  
  165.     def test_multi_request():
  166.         process = target.LaunchSimple(None, None, os.getcwd())
  167.         reg_res, dis_res = client.send_requests(api_request('registers'),
  168.                                                 api_request('disassemble', count=16))
  169.         assert reg_res.status == 'success'
  170.         assert len(reg_res.registers) > 0
  171.         assert reg_res.registers['rip'] != 0
  172.         assert dis_res.status == 'success'
  173.         assert len(dis_res.disassembly) > 0
  174.         assert 'push' in dis_res.disassembly
  175.         target.process.Destroy()
  176.  
  177. except:
  178.     print("No LLDB")
  179.  
downloadfrontend_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
pfff - Tools for code analysis, visualizations, or style-... 2017-04-27
facebook-sdk - Python SDK for Facebook's Graph API ... 2017-04-27
EventEmitter - Evented JavaScript for the browser 2017-04-26
elasticsearch-rails - Elasticsearch integrations for ActiveModel/Record ... 2017-04-26
CircularReveal - Lollipop ViewAnimationUtils.createCircularReveal f... 2017-04-26
psdash - A linux system information web dashboard using psu... 2017-04-26
grunt-contrib-watch - Run tasks whenever watched files change. ... 2017-04-26
UltimateAndroid - UltimateAndroid is a rapid development framework f... 2017-04-26
parallax.js - Simple parallax scrolling effect inspired by Spoti... 2017-04-26
poco - POCO C++ Libraries - Cross-platform C++ libraries ... 2017-04-26

 Back to top