예제 #1
0
 def feature_mining(train_x, train_y):
     samples, tot_features = train_x.shape
     ind = 0
     while (ind < tot_features):
         path = "./feature_mining/" + str(ind) + ".png"
         Mirror.one_d(train_x[:, ind], train_y, path)
         ind = ind + 1
예제 #2
0
    def run(self):
        # Instantiate driver classes
        mir = Mirror(self.distribution, self.log)
        nv = Nvidia(self.distribution, self.log)
        ati = ATI(self.distribution, self.log)
        bc = Broadcom(self.distribution, self.log)
        pae = PAE(self.distribution, self.log)

        # First check for mirror
        for code in self.hwCodesWithStatusList:
            if code[0] == hwCodes[4]:
                if code[1] != packageStatus[2]:
                    mir.installMirror()

        # Now install the hardware drivers
        for code in self.hwCodesWithStatusList:
            # First check for mirror
            if code[0] != hwCodes[4]:
                if code[0] == hwCodes[0]:
                    if code[1] != packageStatus[2]:
                        nv.installNvidia()
                elif code[0] == hwCodes[1]:
                    if code[1] != packageStatus[2]:
                        ati.installATI()
                elif code[0] == hwCodes[2]:
                    if code[1] != packageStatus[2]:
                        bc.installBroadcom()
                elif code[0] == hwCodes[3]:
                    if code[1] != packageStatus[2]:
                        pae.installPAE()
    def saveMirrors(self):
        # Safe mirror settings
        replaceRepos = []
        # Get user selected mirrors
        model = self.tvMirrors.get_model()
        itr = model.get_iter_first()
        while itr is not None:
            sel = model.get_value(itr, 0)
            if sel:
                repo = model.get_value(itr, 2)
                url = model.get_value(itr, 3)
                # Get currently selected data
                for mirror in self.mirrors:
                    if mirror[0] and mirror[2] == repo and mirror[3] != url:
                        # Currently selected mirror
                        replaceRepos.append([mirror[3], url])
                        break
            itr = model.iter_next(itr)

        if not replaceRepos:
            # Check for dead mirrors
            model = self.tvMirrors.get_model()
            itr = model.get_iter_first()
            while itr is not None:
                sel = model.get_value(itr, 0)
                if sel:
                    repo = model.get_value(itr, 2)
                    url = model.get_value(itr, 3)
                    # Get currently selected data
                    for mirror in self.deadMirrors:
                        if mirror[1] == repo and mirror[2] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[2], url])
                            break
                itr = model.iter_next(itr)

        if replaceRepos:
            self.btnSaveMirrors.set_sensitive(False)
            self.btnCheckMirrorsSpeed.set_sensitive(False)
            cmd = "touch %s" % self.umglobal.umfiles["umrefresh"]
            system(cmd)

            m = Mirror()
            m.save(replaceRepos, self.excludeMirrors)
            self.ec.run(cmd="apt-get update", outputTreeView=self.tvMirrors)
            self.umglobal.getLocalInfo()
            self.mirrors = self.getMirrors()
            self.fillTreeViewMirrors()

            remove(self.umglobal.umfiles["umrefresh"])
            self.btnSaveMirrors.set_sensitive(True)
            self.btnCheckMirrorsSpeed.set_sensitive(True)
예제 #4
0
    def saveMirrors(self):
        # Safe mirror settings
        replaceRepos = []
        # Get user selected mirrors
        model = self.tvMirrors.get_model()
        itr = model.get_iter_first()
        while itr is not None:
            sel = model.get_value(itr, 0)
            if sel:
                repo = model.get_value(itr, 2)
                url = model.get_value(itr, 3)
                # Get currently selected data
                for mirror in self.mirrors:
                    if mirror[0] and mirror[2] == repo and mirror[3] != url:
                        # Currently selected mirror
                        replaceRepos.append([mirror[3], url])
                        break
            itr = model.iter_next(itr)

        if not replaceRepos:
            # Check for dead mirrors
            model = self.tvMirrors.get_model()
            itr = model.get_iter_first()
            while itr is not None:
                sel = model.get_value(itr, 0)
                if sel:
                    repo = model.get_value(itr, 2)
                    url = model.get_value(itr, 3)
                    # Get currently selected data
                    for mirror in self.deadMirrors:
                        if mirror[1] == repo and mirror[2] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[2], url])
                            break
                itr = model.iter_next(itr)

        if replaceRepos:
            self.btnSaveMirrors.set_sensitive(False)
            self.btnCheckMirrorsSpeed.set_sensitive(False)
            cmd = "touch %s" % self.umglobal.umfiles["umrefresh"]
            system(cmd)

            m = Mirror()
            m.save(replaceRepos, self.excludeMirrors)
            self.ec.run(cmd="apt-get update", outputTreeView=self.tvMirrors)
            self.umglobal.getLocalInfo()
            self.mirrors = self.getMirrors()
            self.fillTreeViewMirrors()

            remove(self.umglobal.umfiles["umrefresh"])
            self.btnSaveMirrors.set_sensitive(True)
            self.btnCheckMirrorsSpeed.set_sensitive(True)
예제 #5
0
 def prepare(self):
     """
     Prepare incoming request for handler
     """
     self.mirror = Mirror()
     logger.debug("MIRROR - Request\n%s", self.request.body)
     super(MirrorHandler, self).prepare()
예제 #6
0
class MirrorHandler(JsonHandler):
    """
    Handle requests
    """
    def prepare(self):
        """
        Prepare incoming request for handler
        """
        self.mirror = Mirror()
        logger.debug("MIRROR - Request\n%s", self.request.body)
        super(MirrorHandler, self).prepare()

    @tornado.web.asynchronous
    def post(self, *args, **kwargs):
        # 1 - Find operation
        try:
            operation = self.json_data['operation']
            origin = self.json_data['origin']
            mirror_name = self.json_data['mirror_name']
        except Exception as e:
            logger.debug("MIRROR VIEW - Error\n%s", e)
            self.write_error(500, message=e)
            self.finish()

        # 2 - Execute operation
        method = getattr(self, operation)
        result = method(origin, mirror_name)

    def cp(self, origin, mirror_name):
        """
        Lock keyboard
        """
        self.mirror.cp(origin, mirror_name)

        self.response = {}
        self.write_json()
        self.finish()

    def restore(self, origin, mirror_name):
        """
        Lock keyboard
        """
        self.mirror.restore(origin, mirror_name)

        self.response = {}
        self.write_json()
        self.finish()
예제 #7
0
    def run(self):
        hub = Hub(
            self.args.src,
            self.args.dst,
            self.args.dst_token,
            account_type=self.args.account_type,
            clone_style=self.args.clone_style,
            src_account_type=self.args.src_account_type,
            dst_account_type=self.args.dst_account_type,
        )
        src_type, src_account = self.args.src.split('/')

        # Using static list when static_list is set
        repos = self.static_list
        src_repos = repos if repos else hub.dynamic_list()

        total, success, skip = len(src_repos), 0, 0
        failed_list = []
        for src_repo in src_repos:
            # Set dst_repo to src_repo mapping or src_repo directly
            dst_repo = self.mappings.get(src_repo, src_repo)
            print("Map %s to %s" % (src_repo, dst_repo))
            if self.test_black_white_list(src_repo):
                print("Backup %s" % src_repo)
                try:
                    mirror = Mirror(
                        hub,
                        src_repo,
                        dst_repo,
                        cache=self.args.cache_path,
                        timeout=self.args.timeout,
                        force_update=self.args.force_update,
                    )
                    mirror.download()
                    mirror.create()
                    mirror.push()
                    success += 1
                except Exception as e:
                    print(e)
                    failed_list.append(src_repo)
            else:
                skip += 1
        failed = total - success - skip
        res = (total, skip, success, failed)
        print("Total: %s, skip: %s, successed: %s, failed: %s." % res)
        print("Failed: %s" % failed_list)
        if failed_list:
            sys.exit(1)
예제 #8
0
    def run(self):
        # Instantiate driver classes
        mir = Mirror(self.distribution, self.log)
        nv = Nvidia(self.distribution, self.log)
        ati = ATI(self.distribution, self.log)
        bc = Broadcom(self.distribution, self.log)
        pae = PAE(self.distribution, self.log)

        for code in self.hwCodesWithStatusList:
            if code[0] == hwCodes[0]:
                if code[1] == packageStatus[0]:
                    nv.removeNvidia()
            elif code[0] == hwCodes[1]:
                if code[1] == packageStatus[0]:
                    ati.removeATI()
            elif code[0] == hwCodes[2]:
                if code[1] == packageStatus[0]:
                    bc.removeBroadcom()
            elif code[0] == hwCodes[3]:
                if code[1] == packageStatus[0]:
                    pae.removePAE()
            if code[0] == hwCodes[4]:
                if code[1] != packageStatus[2]:
                    mir.removeMirror()
예제 #9
0
 def check_mirrors(self):
     """Check each mirror"""
     nb = len(self.mirrors)
     for i, mirror in enumerate(self.mirrors):
         print("({}/{}): {}".format(i + 1, nb, mirror["url"]))
         mirror = Mirror(mirror)
         if not mirror.country in self.countries:
             self.countries.append(mirror.country)
         mirror.get_state_file()
         mirror.read_state_file(self.hashes)
         mirror_status = {
             "url": mirror.url,
             "protocols": mirror.protocols,
             "country": mirror.country,
             "last_sync": mirror.last_sync,
             "branches": mirror.branches
         }
         self.states.append(mirror_status)
     self.logger.info("{} mirror(s) added".format(len(self.states)))
예제 #10
0
    def saveMirrors(self):
        # Safe mirror settings
        replaceRepos = []
        # Get user selected mirrors
        model = self.tvMirrors.get_model()
        itr = model.get_iter_first()
        while itr is not None:
            sel = model.get_value(itr, 0)
            if sel:
                repo = model.get_value(itr, 2)
                url = model.get_value(itr, 3)
                not_changed = ''
                # Get currently selected data
                for mirror in self.mirrors:
                    if mirror[0] and mirror[2] == repo:
                        if mirror[3] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[3], url])
                        else:
                            not_changed = url
                        break
                if url not in replaceRepos and url not in not_changed:
                    # Append the repositoriy to the sources file
                    replaceRepos.append(['', url])
            itr = model.iter_next(itr)

        if not replaceRepos:
            # Check for dead mirrors
            model = self.tvMirrors.get_model()
            itr = model.get_iter_first()
            while itr is not None:
                sel = model.get_value(itr, 0)
                if sel:
                    repo = model.get_value(itr, 2)
                    url = model.get_value(itr, 3)
                    # Get currently selected data
                    for mirror in self.deadMirrors:
                        if mirror[1] == repo and mirror[2] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[2], url])
                            break
                itr = model.iter_next(itr)

        if replaceRepos:
            self.btnSaveMirrors.set_sensitive(False)
            self.btnCheckMirrorsSpeed.set_sensitive(False)

            m = Mirror()
            ret = m.save(replaceRepos, self.excludeMirrors)
            if ret == '':
                self.ec.run(cmd="apt-get update",
                            outputTreeView=self.tvMirrors)
                self.umglobal.getLocalInfo()
                self.mirrors = self.getMirrors()
                self.fillTreeViewMirrors()
            else:
                self.log.write(ret, "UMPref.saveMirrors", "exception")

            self.btnSaveMirrors.set_sensitive(True)
            self.btnCheckMirrorsSpeed.set_sensitive(True)
        else:
            msg = _("There are no repositories to save.")
            MessageDialog(self.lblMirrors.get_label(), msg)
예제 #11
0
log_dir = "{home}/logs/".format(home=Path.home())

if not os.path.isdir(log_dir):
    print("no logging directory exists. Creating one...")
    os.makedirs(log_dir)

formatting = logging.Formatter(
    '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler = RotatingFileHandler(
    "{home}/logs/Spotify-pruner.log".format(home=Path.home()),
    maxBytes=1024 * 1024,
    backupCount=5)
handler.setFormatter(formatting)
logger = logging.Logger(name="API-calls")
logger.addHandler(handler)

p = Pruner()
m = Mirror()
if "prune" in sys.argv:
    p.prune_playlist()
    logger.info("playlist prune call completed")
if "image" in sys.argv:
    m.update_image()
    logger.info("image update call completed")
if "tracks" in sys.argv:
    m.update_tracks()
    logger.info("tracks update call completed")
if "title" in sys.argv:
    m.update_title()
    logger.info("title update call completed")
예제 #12
0
     pass
 elif event.key == pygame.K_3:
     print("Now using Eraser")
     ferramenta = Eraser(color)
     board.ferramenta = ferramenta
 elif event.key == pygame.K_4:
     print("Now using dualPencil1")
     ferramenta = DualPincel(color)
     board.ferramenta = ferramenta
 elif event.key == pygame.K_5:
     print("Now using dualPencil2")
     ferramenta = DualPincel2(color)
     board.ferramenta = ferramenta
 elif event.key == pygame.K_6:
     print("Now using Mirror")
     ferramenta = Mirror(color)
     board.ferramenta = ferramenta
 elif event.key == pygame.K_DELETE:
     board.board = [[0 for i in range(rows)]
                    for j in range(columns)]
     screen.fill((255, 255, 255))
     pygame.display.flip()
 # Código abaixo pode ser simplificado, com um único dicionário
 # É um pouco trabalhoso, mas mude se tiver paciência
 elif event.key == pygame.K_r:
     color = 2
 elif event.key == pygame.K_g:
     color = 3
 elif event.key == pygame.K_b:
     if color == 1:
         color = 4
예제 #13
0
def run_mirror(coord, transmission_protocol, identifier, sender_ipc_focus,
               receiver_ipc_focus, receiver_ipc_light, senders_ipc_mirrors,
               receivers_ipc_mirrors):
    mirror = Mirror(identifier=identifier, coord=coord)

    mirror.sender_focus_ = Sender(sender_ipc_focus,
                                  transmission_protocol,
                                  verbose=False)
    mirror.receiver_focus_ = Receiver(receiver_ipc_focus,
                                      transmission_protocol,
                                      verbose=False)

    mirror.receiver_light_src_ = Receiver(receiver_ipc_light,
                                          transmission_protocol,
                                          verbose=False)

    for i, ipc in senders_ipc_mirrors.items():
        mirror.senders_mirrors_[i] = Sender(ipc,
                                            transmission_protocol,
                                            verbose=False)
    for i, ipc in receivers_ipc_mirrors.items():
        mirror.receivers_mirrors_[i] = Receiver(ipc,
                                                transmission_protocol,
                                                verbose=False)

    if identifier == 0:
        mirror.run(is_first_to_adjust=True)
    else:
        mirror.run()
예제 #14
0
    def saveMirrors(self):
        # Safe mirror settings
        replaceRepos = []
        # Get user selected mirrors
        model = self.tvMirrors.get_model()
        itr = model.get_iter_first()
        while itr is not None:
            sel = model.get_value(itr, 0)
            if sel:
                repo = model.get_value(itr, 2)
                url = model.get_value(itr, 3)
                not_changed = ''
                # Get currently selected data
                for mirror in self.mirrors:
                    if mirror[0] and mirror[2] == repo:
                        if mirror[3] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[3], url])
                        else:
                            not_changed = url
                        break
                if url not in replaceRepos and url not in not_changed:
                    # Append the repositoriy to the sources file
                    replaceRepos.append(['', url])
            itr = model.iter_next(itr)

        if not replaceRepos:
            # Check for dead mirrors
            model = self.tvMirrors.get_model()
            itr = model.get_iter_first()
            while itr is not None:
                sel = model.get_value(itr, 0)
                if sel:
                    repo = model.get_value(itr, 2)
                    url = model.get_value(itr, 3)
                    # Get currently selected data
                    for mirror in self.deadMirrors:
                        if mirror[1] == repo and mirror[2] != url:
                            # Currently selected mirror
                            replaceRepos.append([mirror[2], url])
                            break
                itr = model.iter_next(itr)

        if replaceRepos:
            self.btnSaveMirrors.set_sensitive(False)
            self.btnCheckMirrorsSpeed.set_sensitive(False)

            m = Mirror()
            ret = m.save(replaceRepos, self.excludeMirrors)
            if ret == '':
                self.ec.run(cmd="apt-get update", outputTreeView=self.tvMirrors)
                self.umglobal.getLocalInfo()
                self.mirrors = self.getMirrors()
                self.fillTreeViewMirrors()
            else:
                self.log.write(ret, "UMPref.saveMirrors", "exception")

            self.btnSaveMirrors.set_sensitive(True)
            self.btnCheckMirrorsSpeed.set_sensitive(True)
        else:
            msg = _("There are no repositories to save.")
            MessageDialog(self.lblMirrors.get_label(), msg)
예제 #15
0
파일: run.py 프로젝트: blandfort/mirror
    from shards import CamShard
    from lenses import LogLens
    from blocks import CountdownBlock

    from config import MIRRORLOG, WINDOWLOG, SCREENSHOT_DIR, SCREENSHOT_RESOLUTION, TIMESTEP
    from config import DEVICE, EMOTIONLOG, FACE_DIR, EMOTION_MODEL_PATH

    emotion_shard = EmotionShard(logfile=EMOTIONLOG,
                                 device=DEVICE,
                                 model_path=EMOTION_MODEL_PATH)
    shards = [CamShard(), FaceShard(FACE_DIR, device=DEVICE), emotion_shard]
    #shards = [CamShard(), FaceShard(FACE_DIR, device=DEVICE)]

    # Viewing live
    mirror = Mirror(shards=shards,
                    lens=EmotionLens(),
                    timestep=.1,
                    logfile=MIRRORLOG)
    #mirror = Mirror(shards=shards, lens=LogLens(), timestep=.5, logfile=MIRRORLOG)
    #mirror = Mirror(shards=shards, lens=FaceswapLens(), timestep=.0, logfile=MIRRORLOG)
    mirror.run(memorize=False)

    # Logic to not remember everything in each step
    cam_block = CountdownBlock(blocking_shards=['webcam'],
                               classes=emotion_shard.classes,
                               frequencies={'neutral': 20})
    face_block = CountdownBlock(blocking_shards=['faces'],
                                classes=emotion_shard.classes,
                                frequencies={'neutral': 20})
    screenshot_block = CountdownBlock(blocking_shards=['screenshot'],
                                      classes=emotion_shard.classes,
                                      frequencies={'neutral': 50},
예제 #16
0
from mirror import Mirror
from polarizer import Polarizer
from waveplate import WavePlate
from incoherent import Incoherent
from compound_element import CompoundElement

if __name__ == '__main__':

    # create optical elements

    horizontal_polarizer = Polarizer()

    vertical_polarizer = Polarizer()
    vertical_polarizer.absolute_rotate(90)

    mirror1 = Mirror()

    compensator = WavePlate(degrees_retardance=360 * (18 / 560))

    # always present order for light wave coming from the right
    compound_item = CompoundElement([mirror1, compensator
                                     ])  # this object will be rotated

    # make incoherent, linearly polarized light. Horizontal/along x-axis
    light = Incoherent()
    linearly_polarized_light = numpy.matmul(horizontal_polarizer.mueller,
                                            light.stokes_vector)

    # just normalizing relative to newly-polarized beam's intensity
    linearly_polarized_light /= linearly_polarized_light[0]
예제 #17
0
def attack(
    input_dex_path,
    output_dex_path,
    weights_path,
    classificator_labels,
    perturbations_path=os.path.join(
        os.path.dirname(os.path.realpath(__file__)), 'perturbations'),
):
    success = False
    mirrorPy = Mirror()
    classificator = MalwareClassificator(
        6, 200) if classificator_labels is None else MalwareClassificator(
            6,
            200,
            family_labels=classificator_label_parse(classificator_labels))
    perturbation_manager = PerturbationsManager(perturbations_path)
    try:
        classificator.load_weights(weights_path)
        loaded_perturbations = perturbation_manager.get_all_perturbations()
        logger.info('perturbations loaded: {}'.format(','.join(
            perturbation.name for perturbation in loaded_perturbations)))

        obfuscation = Obfuscation(input_dex_path, output_dex_path)
        obfuscation.inflate()

        # TODO: move to working dir instead
        original_dex_image = mirrorPy.elaborate(input_dex_path,
                                                obfuscation.output_dex_dir)
        logger.info(
            'original dex image can be found at {}'.format(original_dex_image))

        prediction = classificator.predict(original_dex_image)
        logger.info('original dex image has been classified as: {}'.format(
            prediction if classificator_labels is None else classificator.
            get_label_from_prediction(prediction)))

        for perturbation in loaded_perturbations:
            if not success:
                perturbation.plugin_object.perturbate(obfuscation)

                obfuscation.produce_dex()
                # TODO: move to working dir instead
                obfuscated_dex_image = mirrorPy.elaborate(
                    obfuscation.output_dex_path, obfuscation.output_dex_dir)

                new_prediction = classificator.predict(obfuscated_dex_image)

                if not array_equal(prediction, new_prediction):
                    logger.debug(
                        'untargeted misclassification successful via {}: {} -> {}'
                        .format(perturbation.name, prediction, new_prediction))

                    success = True
                else:
                    logger.debug(
                        '{} perturbation is not strong enough: {}'.format(
                            perturbation.name,
                            new_prediction if classificator_labels is None else
                            classificator.get_label_from_prediction(
                                new_prediction)))

        if success:
            logger.info(
                'successful misclassified dex at {} recognized as {}'.format(
                    obfuscation.output_dex_path,
                    new_prediction if classificator_labels is None else
                    classificator.get_label_from_prediction(new_prediction)))
        else:
            logger.error(
                'miscassification failed, you need to write a stronger perturbation'
            )
    except Exception as e:
        logger.error(e)
        exit(1)