BVB Source Codes

voltron Show lldb_api_tests.py Source code

Return Download voltron: download lldb_api_tests.py Source code - Download voltron Source code - Type:.py
  1. """
  2. Tests that exercise the LLDB backend directly by loading an inferior and then
  3. poking at it with the LLDBAdaptor class.
  4.  
  5. Tests:
  6. LLDBAdaptor
  7. """
  8.  
  9. import tempfile
  10. import sys
  11. import json
  12. import time
  13. import logging
  14. import subprocess
  15. import threading
  16.  
  17. from mock import Mock
  18. from nose.tools import *
  19.  
  20. import voltron
  21. from voltron.core import *
  22. from voltron.api import *
  23. from voltron.plugin import PluginManager, DebuggerAdaptorPlugin
  24.  
  25. import platform
  26. if platform.system() == 'Darwin':
  27.     sys.path.append("/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python")
  28.  
  29. try:
  30.     import lldb
  31.  
  32.     from common import *
  33.  
  34.     voltron.setup_env()
  35.  
  36.     log = logging.getLogger('tests')
  37.  
  38.     def setup():
  39.         global adaptor, dbg, target
  40.  
  41.         log.info("setting up LLDB API tests")
  42.  
  43.         # create an LLDBAdaptor
  44.         pm = PluginManager()
  45.         plugin = pm.debugger_plugin_for_host('lldb')
  46.         adaptor = plugin.adaptor_class()
  47.  
  48.         # compile and load the test inferior
  49.         subprocess.call("cc -o tests/inferior tests/inferior.c", shell=True)
  50.         target = adaptor.host.CreateTargetWithFileAndArch("tests/inferior", lldb.LLDB_ARCH_DEFAULT)
  51.         main_bp = target.BreakpointCreateByName("main", target.GetExecutable().GetFilename())
  52.  
  53.     def teardown():
  54.         time.sleep(2)
  55.  
  56.     def test_version():
  57.         assert 'lldb' in adaptor.version()
  58.  
  59.     def test_state_invalid():
  60.         try:
  61.             adaptor.state()
  62.             exception = False
  63.         except NoSuchTargetException:
  64.             exception = True
  65.         except:
  66.             exception = False
  67.         assert exception
  68.  
  69.     def test_targets_not_running():
  70.         t = adaptor.targets()[0]
  71.         assert t["state"] == "invalid"
  72.         assert t["arch"] == "x86_64"
  73.         assert t["id"] == 0
  74.         assert len(t["file"]) > 0
  75.         assert 'inferior' in t["file"]
  76.  
  77.     def test_targets_stopped():
  78.         process = target.LaunchSimple(None, None, os.getcwd())
  79.         t = adaptor.targets()[0]
  80.         assert t["state"] == "stopped"
  81.         process.Destroy()
  82.  
  83.     def test_registers():
  84.         process = target.LaunchSimple(None, None, os.getcwd())
  85.         regs = adaptor.registers()
  86.         assert regs is not None
  87.         assert len(regs) > 0
  88.         assert regs['rip'] != 0
  89.         process.Destroy()
  90.  
  91.     def test_stack_pointer():
  92.         process = target.LaunchSimple(None, None, os.getcwd())
  93.         sp = adaptor.stack_pointer()
  94.         assert sp != 0
  95.         process.Destroy()
  96.  
  97.     def test_program_counter():
  98.         process = target.LaunchSimple(None, None, os.getcwd())
  99.         pc_name, pc = adaptor.program_counter()
  100.         assert pc != 0
  101.         process.Destroy()
  102.  
  103.     def test_memory():
  104.         process = target.LaunchSimple(None, None, os.getcwd())
  105.         regs = adaptor.registers()
  106.         mem = adaptor.memory(address=regs['rip'], length=0x40)
  107.         assert len(mem) == 0x40
  108.         process.Destroy()
  109.  
  110.     def test_stack():
  111.         process = target.LaunchSimple(None, None, os.getcwd())
  112.         stack = adaptor.stack(length=0x40)
  113.         assert len(stack) == 0x40
  114.         process.Destroy()
  115.  
  116.     def test_disassemble():
  117.         process = target.LaunchSimple(None, None, os.getcwd())
  118.         output = adaptor.disassemble(count=0x20)
  119.         assert len(output) > 0
  120.         process.Destroy()
  121.  
  122.     def test_command():
  123.         process = target.LaunchSimple(None, None, os.getcwd())
  124.         output = adaptor.command("reg read")
  125.         assert len(output) > 0
  126.         assert 'rax' in output
  127.         process.Destroy()
  128.  
  129.     def test_dereference_main():
  130.         process = target.LaunchSimple(None, None, os.getcwd())
  131.         regs = adaptor.registers()
  132.         output = adaptor.dereference(regs['rip'])
  133.         assert ('symbol', 'main + 0x0') in output
  134.         process.Destroy()
  135.  
  136.     def test_dereference_rsp():
  137.         process = target.LaunchSimple(None, None, os.getcwd())
  138.         regs = adaptor.registers()
  139.         output = adaptor.dereference(regs['rsp'])
  140.         assert ('symbol', 'start + 0x1') in output
  141.         process.Destroy()
  142.  
  143.     def test_dereference_string():
  144.         process = target.LaunchSimple(None, None, os.getcwd())
  145.         regs = adaptor.registers()
  146.         output = adaptor.dereference(regs['rsp'] + 0x20)
  147.         assert 'inferior' in list(output[-1])[-1]
  148.         process.Destroy()
  149.  
  150.     def test_breakpoints():
  151.         process = target.LaunchSimple(None, None, os.getcwd())
  152.         bps = adaptor.breakpoints()
  153.         assert len(bps) == 1
  154.         assert bps[0]['one_shot'] == False
  155.         assert bps[0]['enabled']
  156.         assert bps[0]['id'] == 1
  157.         assert bps[0]['hit_count'] > 0
  158.         assert bps[0]['locations'][0]['name'] == "inferior`main"
  159.         process.Destroy()
  160.  
  161.     def test_capabilities():
  162.         assert adaptor.capabilities() == ['async']
  163.  
  164. except:
  165.     print("No LLDB")
downloadlldb_api_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