Example #1
0
def main():
    arg_parser = ArgumentParser()
    arg_parser.add_argument(
        '--rom',
        help=
        'Named set of ROM files (space_invaders, lunar_rescue, balloon_bomber)'
    )
    arg_parser.add_argument('--filename', help='Single ROM file')
    arg_parser.add_argument('--state', help='Save state file')
    args = arg_parser.parse_args()

    rom = args.rom
    filename = args.filename
    if not rom or filename:
        rom = 'space_invaders'
    state = args.state

    if state:
        emu = Emulator.load(state)
    elif rom:
        emu = Emulator(mapname=rom)
    else:
        emu = Emulator(path=filename)

    emu.run()
Example #2
0
def main():
    arg_parser = ArgumentParser()
    arg_parser.add_argument('--filename', help='ROM file')
    arg_parser.add_argument('--state', help='Save state file')
    args = arg_parser.parse_args()

    filename = args.filename if args.filename else 'invaders.rom'
    state = args.state

    if state:
        emu = Emulator.load(state)
    else:
        emu = Emulator(path=filename)

    emu.run()
def launch():
    if request.headers.get('authorization', None) != settings.LAUNCH_AUTH_HEADER:
        abort(403)
    if len(emulators) >= settings.EMULATOR_LIMIT:
        abort(503)
    uuid = uuid4()
    if '/' in request.form['platform'] or '/' in request.form['version']:
        abort(400)
    emu = Emulator(
        request.form['token'],
        request.form['platform'],
        request.form['version'],
        tz_offset=(int(request.form['tz_offset']) if 'tz_offset' in request.form else None),
        oauth=request.form.get('oauth', None)
    )
    emulators[uuid] = emu
    emu.last_ping = now()
    emu.run()
    return jsonify(uuid=uuid, ws_port=emu.ws_port, vnc_display=emu.vnc_display, vnc_ws_port=emu.vnc_ws_port)
def launch():
    if request.headers.get('authorization', None) != settings.LAUNCH_AUTH_HEADER:
        abort(403)
    if len(emulators) >= settings.EMULATOR_LIMIT:
        abort(503)
    uuid = uuid4()
    if '/' in request.form['platform'] or '/' in request.form['version']:
        abort(400)
    emu = Emulator(
        request.form['token'],
        request.form['platform'],
        request.form['version'],
        tz_offset=(int(request.form['tz_offset']) if 'tz_offset' in request.form else None),
        oauth=request.form.get('oauth', None)
    )
    emulators[uuid] = emu
    emu.last_ping = now()
    emu.run()
    return jsonify(uuid=uuid, ws_port=emu.ws_port, vnc_display=emu.vnc_display, vnc_ws_port=emu.vnc_ws_port)
Example #5
0
    def analyse(self):
        ip = self.arch.instruction_pointer
        sp = self.arch.stack_pointer
        emu = Emulator(self.arch)

        emu.map_code(self.address, self.code)

        stack = get_random_page(self.arch)
        stack_data = randoms(self.arch.page_size)

        emu.setup_stack(
                stack,
                self.arch.page_size,
                stack_data
            )

        init_regs = {}

        for reg in self.arch.regs:
            if reg in (ip, sp): continue
            val = self.arch.unpack(randoms(self.arch.bits >> 3))
            emu[reg] = val
            init_regs[val] = reg

        emu.run(self.address, len(self.code))

        for reg in self.arch.regs:
            self.regs[reg] = ("junk", )
            val = emu[reg]
            if init_regs.get(val, None):
                self.regs[reg] = ("mov", init_regs[val])
                continue
            offset = gen_find(self.arch.pack(val), stack_data)
            if offset != -1:
                self.regs[reg] = ("stack", offset)

        if self.regs[sp][0] == "junk":
            self.move = emu[self.arch.stack_pointer] - stack
            self.regs[sp] = ("add", self.move)

        self.analysed = True
Example #6
0
def evaluate(agent,nb_ite):
    
train = np.asarray([10,100,1000])
score = np.zeros(train.shape)
eval_loop = 100
Fmax=1
game = ContinuousCatcher()
random_agent = RandomAgent(1)
agent = QAgent(10,Fmax,game.gamma())
init_emul = Emulator(agent=random_agent)
init_history = init_emul.run()
agent.train(init_history)

i = 0
for nb_train in range(train[-1]):
    if nb_train == train[i]:
        evaluate(agent)
Example #7
0
class Application(object):
    OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
    OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
    OAUTH_REDIRECT_URI = "authentification/google"
    OAUTH_API_BASE_URL = "https://www.googleapis.com/"
    OAUTH_SCOPES = [
        'https://www.googleapis.com/auth/glass.location',
        'https://www.googleapis.com/auth/glass.timeline',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
    ]

    def __init__(self, 
                name="",
                client_id=None,
                client_secret=None,
                emulator=False,
                debug=True,
                template_folder='templates'):
        self.name = name
        self.emulator = emulator
        self.debug = debug
        self.web = flask.Flask(self.name,
            static_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'emulator'),
            static_url_path='/emulator')
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.emulator_service = Emulator(app=self)
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(name=self.name,
                                  client_id=client_id,
                                  client_secret=client_secret,
                                  access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
                                  authorize_url=self.OAUTH_AUTHORIZE_URL,
                                  base_url=self.OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s/glass/oauth/callback" % (self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.OAUTH_SCOPES),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code': flask.request.args.get('code', ''),
            'redirect_uri': self.oauth_redirect_uri,
            'grant_type': 'authorization_code'
        }, decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        self.subscriptions.call_endpoint("login", user)

        return token

    def run(self, host="http://localhost", port=8080, debug=None):
        """
        Start the application server
        """
        if self.emulator:
            self.emulator_service.run()

        self.port = port
        self.host = host
        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize', self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback', self._oauth_callback)

        self.web.debug = debug or self.debug

        # Run webserver
        self.web.run(port=self.port)
Example #8
0
File: app.py Project: zed9/glass.py
class Application(object):
    OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
    OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
    OAUTH_REDIRECT_URI = "authentification/google"
    OAUTH_API_BASE_URL = "https://www.googleapis.com/"
    OAUTH_SCOPES = [
        'https://www.googleapis.com/auth/glass.location',
        'https://www.googleapis.com/auth/glass.timeline',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
    ]

    def __init__(self,
                 name="",
                 client_id=None,
                 client_secret=None,
                 emulator=False,
                 debug=True,
                 template_folder='templates'):
        self.name = name
        self.emulator = emulator
        self.debug = debug
        self.web = flask.Flask(self.name,
                               static_folder=os.path.join(
                                   os.path.dirname(os.path.abspath(__file__)),
                                   'emulator'),
                               static_url_path='/emulator')
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.emulator_service = Emulator(app=self)
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(
            name=self.name,
            client_id=client_id,
            client_secret=client_secret,
            access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
            authorize_url=self.OAUTH_AUTHORIZE_URL,
            base_url=self.OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s/glass/oauth/callback" % (self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.OAUTH_SCOPES),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code':
            flask.request.args.get('code', ''),
            'redirect_uri':
            self.oauth_redirect_uri,
            'grant_type':
            'authorization_code'
        },
                                            decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        self.subscriptions.call_endpoint("login", user)

        return token

    def run(self, host="http://localhost", port=8080, debug=None):
        """
        Start the application server
        """
        if self.emulator:
            self.emulator_service.run()

        self.port = port
        self.host = host
        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize',
                              self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback',
                              self._oauth_callback)

        self.web.debug = debug or self.debug

        # Run webserver
        self.web.run(port=self.port)
Example #9
0
from emulator import Emulator

# ROM = './test_rom/cpu_instr/08.gb'
ROM = './test_rom/games/Tetris.gb'
emu = Emulator(ROM, skipBios=False, nostalgic=False)
try:
    emu.run()
except Exception as e:
    raise e