Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some features added (get_symbol, file, download) #32

Merged
merged 7 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions avatar2/protocols/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def shutdown(self):
self._gdbmi.exit()
self._gdbmi = None

def _sync_request(self, request, rexpect):
def _sync_request(self, request, rexpect, timeout=5):
""" Generic method to send a syncronized request

:param request: the request as list
Expand All @@ -300,7 +300,7 @@ def _sync_request(self, request, rexpect):

self._gdbmi.write(req, read_response=False, timeout_sec=0)
try:
response = self._communicator.get_sync_response(token)
response = self._communicator.get_sync_response(token, timeout=timeout)
ret = True if response['message'] == rexpect else False
except:
response = None
Expand Down Expand Up @@ -744,6 +744,26 @@ def stop(self):
resp)
return ret

def set_file(self, elf=''):
"""Load an ELF file
:returns: True on success"""
ret, resp = self._sync_request(["-file-exec-and-symbols", elf], GDB_PROT_DONE)

self.log.debug(
"Attempted to load elf file. Received response: %s" %
resp)
return ret

def download(self):
"""Download code to target
:returns: True on success"""
ret, resp = self._sync_request(["-target-download"], GDB_PROT_DONE, timeout=60)

self.log.debug(
"Attempted to download code to target. Received response: %s" %
resp)
return ret

def set_endianness(self, endianness='little'):
req = ['-gdb-set', 'endian', '%s' % endianness]
ret, resp = self._sync_request(req, GDB_PROT_DONE)
Expand Down Expand Up @@ -779,7 +799,7 @@ def get_symbol(self, symbol):
regex = re.compile("(0x[0-9a-f]*)[ .]")
resp = regex.findall(resp)
if len(resp) == 1:
resp = long(resp[0], 16)
resp = int(resp[0], 16)
else:
resp = -1
ret = False
Expand Down
40 changes: 40 additions & 0 deletions avatar2/targets/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,46 @@ def step(self, blocking=True):
"""
return self.protocols.execution.step()

@watch('TargetSetFile')
@action_valid_decorator_factory(TargetStates.STOPPED, 'execution')
def set_file(self, elf):
"""
Load an ELF file

:param elf: ELF file to load
:returns: True on success else False
"""
if not hasattr(self.protocols.execution, 'set_file'):
self.log.error('Protocol "' + type(self.protocols.execution).__name__ + '" does not support "set_file"')
return False

return self.protocols.execution.set_file(elf)

@watch('TargetDownload')
@action_valid_decorator_factory(TargetStates.STOPPED, 'execution')
def download(self):
"""
Download the loaded code to the Target

:returns: True on success else False
"""
if not hasattr(self.protocols.execution, 'download'):
self.log.error('Protocol "' + type(self.protocols.execution).__name__ + '" does not support "download"')
return False

return self.protocols.execution.download()

@watch('TargetGetSymbol')
@action_valid_decorator_factory(TargetStates.STOPPED, 'memory')
def get_symbol(self, symbol):
"""
Get the address of a symbol

:param symbol: The name of a symbol whose address is wanted
:returns: (True, Address) on success else False
"""
return self.protocols.memory.get_symbol(symbol)

@watch('TargetWriteMemory')
@action_valid_decorator_factory(TargetStates.STOPPED, 'memory')
def write_memory(self, address, size, value, num_words=1, raw=False):
Expand Down
5 changes: 4 additions & 1 deletion avatar2/watchmen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ class WatchedTypes(object):
'TargetCont',
'TargetStop',
'TargetStep',
'TargetGetSymbol',
'TargetWriteMemory',
'TargetReadMemory',
'TargetRegisterWrite',
'TargetRegisterRead',
'TargetSetBreakpoint',
'TargetSetWatchPoint',
'TargetRemovebreakpoint',
'TargetWait'
'TargetWait',
'TargetSetFile',
'TargetDownload'
]

def __init__(self):
Expand Down