I am trying to make an interactive tutorial. It uses radare2 with r2pipe as its reverse engineering toolkit. I want my users to be able to use the visual mode through r2pipe. In order for the visual mode to work I've found that I need to enable scr.interactive. When I do that everything breaks down and I can no longer interact with the r2pipe session.

Here's my python code:

import r2pipe
import os
class RadareSession():
    def __init__(self, id):
        self.__id = id
        self.__pipe = r2pipe.open()

    def execute(self, cmd):
        #TODO: sterilize the command
        return self.__pipe.cmd(cmd)

    def __del__(self):
        pass # TODO: close the radare session

class SessionManager():
    def __init__(self, radare_path):
        os.environ['PATH'] = os.environ['PATH'] + f";{radare_path}"
        self.__sessions = {}

    def create_radare_session(self):
        self.__sessions[id] = RadareSessions(id)

    def end_radare_session(self, id):
        pass # return true or false

    def __getitem__(self, key): # SessionManager[key]
        # Raise TypeError if key is not a known type
        # Raise KeyError if key is not in the dictionary

    def __setitem__(self, key):
        raise Exception("Not allowed to set session manager sessions. Use create_radare_session.")

    def __delitem__(self, key):
        # call the del method of the appropriate radare session
if __name__ == '__main__':
    s = SessionManager("D:\\h\\openradare\\openradare\\radare2-install\\bin")

I want the execute function of RadareSession to be interactive. Thank you for you time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.