Skip to content

Commit

Permalink
Add basic methods for eval functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
fmagin committed Jun 20, 2019
1 parent 3bbf873 commit 3584047
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ghidra_bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
CALL = "call"
IMPORT = "import"
DEL = "del"
EVAL= "eval"
EXPR = "expr"
RESULT = "result"
ERROR = "error"

Expand Down Expand Up @@ -802,6 +804,20 @@ def local_isinstance(self, args_dict):

return self.serialize_to_dict(result)


def remote_eval(self, eval_string):
command_dict = {CMD: EVAL, ARGS: self.serialize_to_dict(
{EXPR: eval_string})}
return self.deserialize_from_dict(self.send_cmd(command_dict))

def local_eval(self, args_dict):
args = self.deserialize_from_dict(args_dict)
try:
result = eval(args[EXPR])
return self.serialize_to_dict(result)
except Exception as e:
return self.serialize_to_dict(e)

def handle_command(self, message_dict):

response_dict = {VERSION: COMMS_VERSION_2,
Expand Down Expand Up @@ -829,6 +845,8 @@ def handle_command(self, message_dict):
response_dict[RESULT] = self.local_get_all(command_dict[ARGS])
elif command_dict[CMD] == ISINSTANCE:
response_dict[RESULT] = self.local_isinstance(command_dict[ARGS])
elif command_dict[CMD] == EVAL:
response_dict[RESULT] = self.local_eval(command_dict[ARGS])

self.logger.debug("Responding with {}".format(response_dict))
return json.dumps(response_dict).encode("utf-8")
Expand Down Expand Up @@ -908,6 +926,9 @@ def __init__(self, connect_to_host=DEFAULT_HOST, connect_to_port=DEFAULT_SERVER_
def remote_import(self, module_name):
return self.client.remote_import(module_name)

def remote_eval(self,eval_string):
return self.client.remote_eval(eval_string)

# TODO shutdown


Expand Down

0 comments on commit 3584047

Please sign in to comment.