Esempio n. 1
0
def parse(data: dict):
    """Parse the data in the proper displaying format

    Arguments:
        data {dict} -- content that is to be displayed
    """
    def form(val):
        """To format the "code" that is being printed

        The code section had `\n` which kinda breaks
        the flow when printed on terminal so we replace `\n` with `\n\t`

        Arguments:
            val {[str]} -- commands with \n

        Returns:
            [str] -- commands with \n\t
        """
        return val.replace("\n", "\n\t")

    sections = data["functions"]

    for sec in sections:
        category = sections[sec]

        for cat in category:
            if "description" in cat:
                print("# " + colors(cat['description'], 93))
            print("Code:\t" + colors(form(cat['code']), 92))
            print("Type:\t" + colors(sec, 91))
            print("\n")
Esempio n. 2
0
def main():
    df = utils.dataframe('dataset_train.csv')
    colors = utils.colors()

    df = df.drop(
        columns=['Index', 'Hogwarts House', 'First Name', 'Last Name'])
    df['Best Hand'] = df['Best Hand'].replace(to_replace=['Left', 'Right'],
                                              value=[1, 2])
    df['Year'] = df['Birthday'].apply(lambda x: int(x[0:4]))
    df['Month'] = df['Birthday'].apply(lambda x: int(x[5:7]))
    df['Day'] = df['Birthday'].apply(lambda x: int(x[8:10]))
    df['Birthday'] = df['Birthday'].apply(lambda x: time.mktime(
        datetime.datetime.strptime(x, "%Y-%m-%d").timetuple()))

    nb_columns = 0
    for column in df:
        nb_columns += 1

    i = 1
    for column in df:
        plt.subplot(4, math.ceil(nb_columns / 4 + 1), i)
        i += 1
        plt.hist(df[column],
                 bins=bin(df[column]),
                 color=colors[column],
                 label=column,
                 alpha=0.75,
                 edgecolor='black',
                 linewidth=0.5)
        plt.legend(loc='upper right')
    plt.show()
Esempio n. 3
0
 def colordict(self, ticket):
     for field in ticket.fields:
         if field['name'] == self.field:
             assert 'options' in field
             _colors = colors(len(field['options']), hexcode=True)
             return dict(zip(field['options'], _colors))
             
     raise AssertionError("Ticket field %s not found" % self.field)
Esempio n. 4
0
def gtfobins(bin_name: str):
    """Search binaries from GTFOBins within command line

    Arguments:
        bin_name {[type]} -- Name of the binary to get info about

    """

    bins = get_bins()

    if bin_name in bins:
        print(colors("[+] Binary found: " + bin_name, 92))
        r = requests.get(RAW_URL.format(bin_name)).text
        data = list(yaml.load_all(r, Loader=yaml.SafeLoader))[0]

        parse(data)
    else:
        print(colors("[!] Binary not found on GTFObins: " + bin_name, 91))
Esempio n. 5
0
def lolbas(name: str):
    """Search binaries from LOLBAS within command line

    Arguments:
        name {[type]} -- Name of the exe to get info about

    Keyword Arguments:
        cmd {str} -- get only the code section (default: {False})
    """

    exes = get_exe()
    if name in exes.keys():
        url = RAW_URL + exes[name] + '.md'
        r = requests.get(url).text
        data = list(yaml.load_all(r, Loader=yaml.SafeLoader))[0]
        parse(data)
    else:
        print(colors("[!] Binary not found on LOLBAS", 91))
        #TODO: Match user input and make suggestion for search
        print(colors("[!] Make sure to provide name with proper extension",
                     91))
Esempio n. 6
0
def main():
    #matplotlib.use('webagg')
    iterable = [
        'Astronomy',
        'Herbology',
        'Ancient Runes',
        'Divination',
    ]
    plt.style.use('dark_background')

    colors_house = utils.colors_house()

    df = utils.dataframe('dataset_train.csv')
    colors = utils.colors()

    df_house = df['Hogwarts House']
    df = df.drop(columns=[
        'Index',
        'First Name',
        'Last Name',
        'Arithmancy',
        'Defense Against the Dark Arts',
        'Muggle Studies',
        'History of Magic',
        'Potions',
        'Care of Magical Creatures',
        'Flying',
        'Charms',
        'Transfiguration',
    ])

    allIterables = list(itertools.combinations(iterable, 2))
    nb_columns = 0
    for column in allIterables:
        nb_columns += 1

    i = 1
    for el in allIterables:
        plt.subplot(math.ceil(nb_columns / 3 + 1), 3, i)
        i += 1
        plt.scatter(df[el[0]],
                    df[el[1]],
                    c=df['Hogwarts House'].map(colors_house),
                    alpha=0.25,
                    label=[el[0][:10], el[1][:10]],
                    marker='o',
                    s=2)
        plt.xticks([])
        plt.yticks([])
        plt.legend(loc='upper right', fontsize=5)
    plt.show()
Esempio n. 7
0
def parse(data):
    """Parse and print the commands

    The yml file contains the following fields: Description, Command,
    Category, Privileges, OperatingSystem, UseCase, MitreID, MItreLink.

    If any more data has to be printed then we can just do that.

    For easy reference see the following yml file: RAW_URL/Libraries/Ieadvpack.md

    Arguments:
        data {list} -- list of dictionary having everything a command
        yml file contains
    """

    # TODO: Figure out a way to improve this printing
    cmd = data['Commands']

    for c in cmd:
        print("# " + colors(c['Description'], 93) + "\n")
        print("CMD:\t\t" + colors(c["Command"], 92))
        print("Category:\t" + colors(c["Category"], 91))
        print("Privileges:\t" + colors(c["Privileges"], 91))
        print("\n")
Esempio n. 8
0
def main():
	iterable = [
		"Birthday",
		"Best Hand",
		"Arithmancy",
		"Astronomy",
		"Herbology",
		"Defense Against the Dark Arts",
		"Divination",
		"Muggle Studies",
		"Ancient Runes",
		"History of Magic",
		"Transfiguration",
		"Potions",
		"Care of Magical Creatures",
		"Charms",
		"Flying",
		"Year",
		"Month",
		"Day"
	]

	df = utils.dataframe('dataset_train.csv')
	colors = utils.colors()

	df = df.drop(columns=['Index', 'Hogwarts House', 'First Name', 'Last Name'])
	df['Best Hand'] = df['Best Hand'].replace(to_replace=['Left', 'Right'], value=[1, 2])
	df['Year'] = df['Birthday'].apply(lambda x: int(x[0:4]))
	df['Month'] = df['Birthday'].apply(lambda x: int(x[5:7]))
	df['Day'] = df['Birthday'].apply(lambda x: int(x[8:10]))
	df['Birthday'] = df['Birthday'].apply(lambda x: time.mktime(datetime.datetime.strptime(x, "%Y-%m-%d").timetuple()))


	allIterables = list(itertools.combinations(iterable, 2))

	nb_columns = 0
	for column in allIterables:
		nb_columns += 1

	i = 1
	for el in allIterables:
		plt.subplot(7, math.ceil(nb_columns / 7 + 1), i)
		i += 1
		plt.scatter(df[el[0]], df[el[1]], color=utils.combine_hex_values(colors[el[0]], colors[el[1]]), alpha=0.25, label=[el[0], el[1]], s=3)
		plt.xticks([])
		plt.yticks([])
		plt.legend(loc='upper right', fontsize=5)
	plt.show()
Esempio n. 9
0
    def plot_graph(self):
        from utils import colors

        pos = nx.spring_layout(self.G)
        color_list = colors(len(self.people_idx))
        plt.title("Connected components in the Chinese Whispers Graph")
        wcc = nx.connected_component_subgraphs(self.G)
        lab = ["Person {}".format(x) for x in self.people_idx.keys()]
        for index, sg in enumerate(wcc):
            nx.draw_networkx(sg,
                             pos=pos,
                             edge_color=color_list[index],
                             node_color=color_list[index])
        for i in range(len(lab)):
            plt.scatter([], [],
                        c=color_list[i],
                        alpha=0.3,
                        s=100,
                        label=lab[i])
        plt.legend(title="Clusters")
        plt.show()
Esempio n. 10
0
    def doIt(self):

        error, reason = self.check_parameters()
        if error:
            raise ValueError(reason)

        if self.sequence is None or (self.output is None and self.preview is False):
            raise Exception(ValueError, "Missing in sequence or output file")
        self.inExtension = self.sequence.split('.')[-1]

        if self.start is None or self.end is None:
            sequence = SequenceAnalyser(self.sequence)
            info = sequence.info()
            if info.get('frames') == []:
                raise ValueError("No frames found for this sequence")
            if self.start is None:
                self.start = info.get('start')
            if self.end is None:
                self.end = info.get('end')


        if self.inExtension in ['mov', 'mp4']:
            self.originalMovie = self.sequence
            self.sequence = self._convertMovieToSequence('/tmp')
        self.graph = Tuttle.tuttle.Graph()

        last_reader_node, td = self._prepareSequence()

        if not self.font_size:
            self.font_size = utils.estimateFontSize(self.outWidth)
            pprint("--> Using font size %d" % self.font_size)


        # Merge needs entry in the same channel layout / bit depth
        pprint(" 001-Creating tuttle.constant (doIt)")
        HUD_constant = self.createConstant(size=self.resolution, color=utils.colors('black', False))
        last_network_node = HUD_constant
        # Create Texts Nodes
        something_in_HUD = False
        offsetH = 10.0
        offsetV = 10.0



        if self.text_over:
            offsetH += (self.outWidth - self.sequence_width)/2
            offsetV += (self.outHeight - self.sequence_height)/2


        for elt in ['topleft', 'topcenter','topright', 'bottomleft', 'bottomcenter', 'bottomright']:
            if eval('self.text_%s' % elt) is not None:
                val = elt
                text = eval('self.text_%s' % elt)
                pprint("--> Burning %s at %s" % (text, val))

                text_node = self.createText(val, text, offset=(offsetH, offsetV))
                last_network_node = self.createMerge(text_node, last_network_node)
                something_in_HUD = True

        # Create a counter a counter
        if self.counter is True:
            something_in_HUD = True
            val = self.counter_align
            text = '"(" + str(tuttleArgs().time) + ")"'
            pprint("--> Burning frame counter at %s" % val)
            if self.counter_total is True:
                text = '"(" + str(tuttleArgs().time) + " / %d)"' % (self.end or int(td.max))
            text_node = self.createText(val, text, expression=True, offset=(offsetH, offsetV))
            last_network_node = self.createMerge(text_node, last_network_node)


        #Create a date
        if self.date is True:
            something_in_HUD = True
            val = self.date_align
            text = time.strftime('%Y-%m-%d', time.localtime())
            pprint("--> Burning date at %s" % val)
            text_node = self.createText(val, text, offset=(offsetH, offsetV))
            last_network_node = self.createMerge(text_node, last_network_node)

        if something_in_HUD is False:
            # write a blank as text bruned(workaround) in case
            val = 'bottomright'
            text = " "
            text_node = self.createText(val, text, offset=(offsetH, offsetV))
            last_network_node = self.createMerge(text_node, last_network_node)
            something_in_HUD = True


        # merge HUD on top of sequence
        if last_network_node is not None:
            offsetBh = (self.outWidth - self.sequence_width)/2
            offsetBv = (self.outHeight - self.sequence_height)/2
            pprint(" 002-Creating tuttle.merge (doIt)")
            image_merge = self.createMerge(last_network_node, last_reader_node, rod='A', type='over', offsetB=(offsetBh, offsetBv))
            last_network_node = image_merge

        else:
            last_network_node = last_reader_node

        #check and set audio file
        if self.audiofile:
            if not os.path.isfile(self.audiofile):
                self.audiofile = None
                print "Cannot found the sound file"
            elif self.preview is True:
                self.audiofile = None
            elif self.render_movie is False:
                self.audiofile = None
            else:
                pass


        # Set options and writer node
        #start = self.start or int(td.min)
        #end = self.end or int(td.max)
        co = Tuttle.tuttle.ComputeOptions(self.start, self.end)

        self.tmpmov = '/tmp/qt_%s.mov' % time.strftime("%d_%m_%Y_%H_%M_%S", time.localtime())
        if self.output is None or self.preview is True:
            co = Tuttle.tuttle.ComputeOptions(self.start, self.start) #just preview the first frame
            pprint(" 003-Creating tuttle.viewer (doIt)")
            writer = self.graph.createNode("tuttle.viewer")
        else:
            writer = self._getWriter()
        self.graph.connect((last_network_node, writer))
        pprint("Writing out sequence...")
        if self.debug is True:
            co.setVerboseLevel(Tuttle.tuttle.eVerboseLevelInfo)
        co.setContinueOnMissingFile(True)

        if os.path.exists(self.output):
            try:
                os.remove(self.output)
                pprint("%s already exists. It will be overwritten" % self.output)
            except:
                print "%s already exists. Cannot remove it. permissions not set correctly. tuttleBurner will fail" % self.output
        #try:
        #write to /tmp
        if self.render_movie:
            pprint("Writing to %s" % self.tmpmov)
        self.graph.compute(writer, co)
        if self.render_movie:
            pprint("End Writing %s" % self.tmpmov)

        if self.render_movie:
            if os.path.exists(self.tmpmov):
                pprint("Copy file from %s to %s" % (self.tmpmov, self.output))
                shutil.copyfile(self.tmpmov, self.output)
            if os.path.exists(self.output):
                os.remove(self.tmpmov)
                pprint("Removing %s" % self.tmpmov)
            else:
                pprint("Keeping %s since %s doesnt exists" % (self.tmpmov, self.output))



        if self.output and os.path.exists(self.output):
            os.chmod(self.output, 0664)
        print self.output
        print "Job done !"
        #except:
        #    print "Rendering failed. Job aborted !"
        if self.audiofile:
            movWithSound = '/tmp/qt_%s.mov' % time.strftime("%d_%m_%Y_%H_%M_%S", time.localtime())
            cmd = 'ffmpeg -i %s -i %s -map 0 -map 1 -codec copy -shortest -y %s' % (self.output, self.audiofile, movWithSound)
            pprint(cmd)
            proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
            outdata = proc.communicate()

            cmd = 'mv %s %s' % (movWithSound, self.output)
            pprint(cmd)
            proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
            outdata = proc
Esempio n. 11
0
    def __init__(self,
                 sequence=None,
                 output=None,
                 audiofile=None,
                 text_topleft=None,
                 text_topcenter=None,
                 text_topright=None,
                 text_bottomleft=None,
                 text_bottomcenter=None,
                 text_bottomright=None,
                 counter=None,
                 counter_total=None,
                 counter_align=None,
                 date=None,
                 date_align=None,
                 resolution=None,
                 background_color=None,
                 crop_color=None,
                 font_name=None,
                 font_size=None,
                 font_color=None,
                 text_over=None,
                 start=None,
                 end=None,
                 framerate=None,
                 codec=None,
                 quality=None,
                 preview=None,
                 debug=None
                 ):
        
        #this is because dont want a self.pprint inside the class ;o)
        global pprint
        pprint = self._pprint
        self.debug = debug or False
        #define default values
        default = {'codec': 'h264',
                   'framerate': 24,
                   'date': False,
                   'date_align': 'topright',
                   'counter': False,
                   'counter_total': False,
                   'counter_align': 'bottomcenter',
                   'text_topleft': '',
                   'text_topcenter': '',
                   'text_topright': '',
                   'text_bottomleft': '',
                   'text_bottomcenter': '',
                   'text_bottomright': '',
                   'font_name': 'liberation_sans',
                   'font_color': 'white',
                   'resolution': (1920,1080),
                   'background_color': 'black',
                   'crop_color': 'darkgrey',
                   'text_over': False,
                   'preview': False,
                   'quality': 'high',

                   
        }
        self.default = default
        #parameters
        self.sequence = sequence
        self.output = output
        self.audiofile = audiofile
        self.start = start #No default, evaluated from sequence
        self.end = end #No default, evaluated from sequence

        self.text_topleft = self._set_param("text_topleft", text_topleft)
        self.text_topcenter = self._set_param("text_topcenter", text_topcenter)
        self.text_topright = self._set_param("text_topright", text_topright)
        self.text_bottomleft = self._set_param("text_bottomleft", text_bottomleft)
        self.text_bottomcenter = self._set_param("text_bottomcenter", text_bottomcenter)
        self.text_bottomright = self._set_param("text_bottomright", text_bottomright)
        self.date = self._set_param("date", date)
        self.date_align = self._set_param("date_align", date_align)
        self.counter = self._set_param("counter", counter)
        self.counter_total = self._set_param("counter_total", counter_total)
        self.counter_align = self._set_param("counter_align", counter_align)
        self.font_name = self._set_param("font_name", font_name)
        self.font_size = font_size #No default, let the app estimate the good size
        self.font_color = utils.colors(self._set_param("font_color", font_color))
        self.resolution = self._set_param("resolution", resolution)
        self.background_color = utils.colors(self._set_param("background_color", background_color))
        self.crop_color = utils.colors(self._set_param("crop_color", crop_color))
        self.text_over = self._set_param("text_over", text_over)
        self.framerate = self._set_param("framerate", framerate)
        self.codec = self._set_param("codec", codec)# or default['codec']
        self.quality = self._set_param("quality", quality)
        self.preview = self._set_param("preview", preview)



        #other app vars
        self.render_movie = False
        if output.split('.')[-1] in ['mov', 'mp4', 'mpeg', 'mpg', 'mjpeg', 'mjpg']:
            self.render_movie = True

        self.sequence_resolution = None
        self.sequence_width = None
        self.sequence_height = None

        self.outWidth = None
        self.outHeight = None

        self.graph = None

        self.originalMovie = None
        self.tmpmov = None
Esempio n. 12
0
def main():
    #matplotlib.use('webagg')
    '''
		'Arithmancy',
		'Astronomy',
		'Herbology',
		'Defense Against the Dark Arts',
		'Divination',
		'Muggle Studies',
		'Ancient Runes',
		'History of Magic',
		'Transfiguration',
		'Potions',
		'Care of Magical Creatures':,
		'Charms',
		'Flying',
	'''
    iterable = [
        'Astronomy',
        'Herbology',
        'Ancient Runes',
        'Divination',
    ]
    plt.style.use('dark_background')

    colors_house = utils.colors_house()

    df = utils.dataframe('dataset_train.csv')
    colors = utils.colors()

    df_house = df['Hogwarts House']

    allIterables = list(itertools.combinations(iterable, 2))
    nb_columns = 0
    for column in allIterables:
        nb_columns += 1

    i = 1
    for el in allIterables:
        plt.subplot(math.ceil(nb_columns / 3 + 1), 3, i)
        i += 1
        plt.scatter(df[el[0]],
                    df[el[1]],
                    c=df['Hogwarts House'].map(colors_house),
                    alpha=0.25,
                    label=[el[0][:10], el[1][:10]],
                    marker='o',
                    s=2)
        df_errors = df.loc[[
            184, 200, 255, 339, 443, 445, 456, 504, 515, 618, 681, 704, 815,
            820, 824, 915, 941, 1078, 1098, 1113, 1191, 1282, 1419, 1435, 1444,
            1446, 1448, 1515, 1525, 1596
        ]]
        plt.scatter(df_errors[el[0]],
                    df_errors[el[1]],
                    c=df_errors['Hogwarts House'].map(colors_house),
                    marker='x')
        plt.xticks([])
        plt.yticks([])
        plt.legend(loc='upper right', fontsize=5)
    plt.show()

    print()