BVB Source Codes

voltron Show memory.py Source code

Return Download voltron: download memory.py Source code - Download voltron Source code - Type:.py
  1. import voltron
  2. import logging
  3. import six
  4. import struct
  5.  
  6. from voltron.api import *
  7.  
  8. log = logging.getLogger('api')
  9.  
  10.  
  11. class APIMemoryRequest(APIRequest):
  12.     """
  13.    API read memory request.
  14.  
  15.    {
  16.        "type":         "request",
  17.        "request":      "memory",
  18.        "data": {
  19.            "target_id":0,
  20.            "address":  0x12341234,
  21.            "length":   0x40
  22.        }
  23.    }
  24.  
  25.    `target_id` is optional. If not present, the currently selected target
  26.    will be used.
  27.  
  28.    `address` is the address at which to start reading.
  29.  
  30.    `length` is the number of bytes to read.
  31.  
  32.    `register` is the register containing the address at which to start reading.
  33.  
  34.    `command` is the debugger command to execute to calculate the address at
  35.    which to start reading.
  36.  
  37.    `deref` is a flag indicating whether or not to dereference any pointers
  38.    within the memory region read.
  39.  
  40.    `offset` is an offset to add to the address at which to start reading.
  41.    """
  42.     _fields = {
  43.         'target_id': False,
  44.         'address': False,
  45.         'length': False,
  46.         'words': False,
  47.         'register': False,
  48.         'command': False,
  49.         'deref': False,
  50.         'offset': False
  51.     }
  52.  
  53.     target_id = 0
  54.  
  55.     @server_side
  56.     def dispatch(self):
  57.         try:
  58.             target = voltron.debugger.target(self.target_id)
  59.  
  60.             # if 'words' was specified, get the addr_size and calculate the length to read
  61.             if self.words:
  62.                 self.length = self.words * target['addr_size']
  63.  
  64.             # calculate the address at which to begin reading
  65.             if self.address:
  66.                 addr = self.address
  67.             elif self.command:
  68.                 output = voltron.debugger.command(self.command)
  69.                 if output:
  70.                     for item in reversed(output.split()):
  71.                         log.debug("checking item: {}".format(item))
  72.                         try:
  73.                             addr = int(item)
  74.                             break
  75.                         except:
  76.                             try:
  77.                                 addr = int(item, 16)
  78.                                 break
  79.                             except:
  80.                                 pass
  81.             elif self.register:
  82.                 regs = voltron.debugger.registers(registers=[self.register])
  83.                 addr = list(regs.values())[0]
  84.             if self.offset:
  85.                 if self.words:
  86.                     addr += self.offset * target['addr_size']
  87.                 else:
  88.                     addr += self.offset
  89.  
  90.             # read memory
  91.             memory = voltron.debugger.memory(address=int(addr), length=int(self.length), target_id=int(self.target_id))
  92.  
  93.             # deref pointers
  94.             deref = None
  95.             if self.deref:
  96.                 fmt = ('<' if target['byte_order'] == 'little' else '>') + {2: 'H', 4: 'L', 8: 'Q'}[target['addr_size']]
  97.                 deref = []
  98.                 for chunk in zip(*[six.iterbytes(memory)] * target['addr_size']):
  99.                     chunk = ''.join([six.unichr(x) for x in chunk]).encode('latin1')
  100.                     p = list(struct.unpack(fmt, chunk))[0]
  101.                     if p > 0:
  102.                         try:
  103.                             deref.append(voltron.debugger.dereference(pointer=p))
  104.                         except:
  105.                             deref.append([])
  106.                     else:
  107.                         deref.append([])
  108.  
  109.             res = APIMemoryResponse()
  110.             res.address = addr
  111.             res.memory = six.u(memory)
  112.             res.bytes = len(memory)
  113.             res.deref = deref
  114.         except TargetBusyException:
  115.             res = APITargetBusyErrorResponse()
  116.         except NoSuchTargetException:
  117.             res = APINoSuchTargetErrorResponse()
  118.         except Exception as e:
  119.             msg = "Exception getting memory from debugger: {}".format(repr(e))
  120.             log.exception(msg)
  121.             res = APIGenericErrorResponse(msg)
  122.  
  123.         return res
  124.  
  125.  
  126. class APIMemoryResponse(APISuccessResponse):
  127.     """
  128.    API read memory response.
  129.  
  130.    {
  131.        "type":         "response",
  132.        "status":       "success",
  133.        "data": {
  134.            "memory":   "ABCDEF" # base64 encoded memory
  135.        }
  136.    }
  137.    """
  138.     _fields = {
  139.         'address': True,
  140.         'memory': True,
  141.         'bytes': True,
  142.         'deref': False
  143.     }
  144.     _encode_fields = ['memory']
  145.  
  146.     address = None
  147.     memory = None
  148.     bytes = None
  149.     deref = None
  150.  
  151.  
  152. class APIReadMemoryPlugin(APIPlugin):
  153.     request = 'memory'
  154.     request_class = APIMemoryRequest
  155.     response_class = APIMemoryResponse
  156.  
downloadmemory.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