<file_sep>#!/bin/bash
export $(cut -d= -f1 $1)
<file_sep>#!/bin/bash
# gen_breakpoints - Creates a list of breakpoints for all functions in an ELF file.
# Input: non-stripped ELF file.

FILE="$1"

nm -C $FILE | egrep ' [TtW] ' > ${FILE}_breakpoints.txt 
sed -i -e 's/^/# 0x/' -e 's/\# \(0x[0-9a-f]*\).*/\0\nbreak \*\1/' ${FILE}_breakpoints.txt

mv ${FILE}_breakpoints.txt .

<file_sep>#!/bin/bash

sed -i '/<return>/d' $1

<file_sep>#!/bin/bash
# Create a list of the function names and also a list of breakpoints of these functions to be used in GDB

FILE="$1"

nm $FILE | egrep ' [TW] ' > ${FILE}FunctionIndex 
sed -i -e 's/^/0x/' ${FILE}FunctionIndex

nm $FILE | egrep ' [TW] ' | grep -Eo '^[^ ]+' > ${FILE}ListOfBreakpoints
sed -i -e 's/^/break *0x/' ${FILE}ListOfBreakpoints
sed -i '/break/a  commands\n    continue\n  end' ${FILE}ListOfBreakpoints

mv ${FILE}ListOfBreakpoints .
mv ${FILE}FunctionIndex .
<file_sep>#!/bin/bash
function ngp-connect() {
    if [ "$#" -eq 0 ] ; then
        NGP_IP=10.10.92.63
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    else
        NGP_IP="$1" 
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    fi
    sshpass -p $NGP_PW ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oStrictHostKeyChecking=no root@$NGP_IP -p $SSH_PORT
}

function kngp-connect() {
    if [ "$#" -eq 0 ] ; then
        NGP_IP=10.10.92.63
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    else
        NGP_IP="$1" 
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    fi
    sshpass -p $NGP_PW ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oStrictHostKeyChecking=no root@$NGP_IP -p $SSH_PORT
}

function ngp-connect-first() {
    if [ "$#" -eq 0 ] ; then
        NGP_IP=10.10.92.63
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    else
        NGP_IP="$1" 
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
    fi
    ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oStrictHostKeyChecking=no root@$NGP_IP -p $SSH_PORT
}
function ngp-cp-to() {
    if [ "$#" -eq 2 ] ; then
        NGP_IP=10.10.92.63
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
        FILE="$1"
        TO_PATH="$2"
    else
        NGP_IP="$1" 
        SSH_PORT=4022
        NGP_PW='<PASSWORD>'
        FILE="$2"
        TO_PATH="$3"
    fi
    sshpass -p $NGP_PW scp -P $SSH_PORT -oKexAlgorithms=+diffie-hellman-group1-sha1 $FILE root@$NGP_IP:$TO_PATH
}
<file_sep>#!/bin/bash
#insert the continue command afet the break point in order to get a full list of hitten breakpoints

FILE="$1"

sed -i -e 's/break \(\*0x[0-9a-f]*\).*/\0\n  commands\ncontinue\n  end/' $FILE


<file_sep>clean:
	-rm vmlinux*
	-rm list*
	-rm selected*
	-rm kernel_dump
	-rm hit*
	-rm ../img/gdb.txt

<file_sep>#! /usr/bin/python3
import sys

def has_a_function_of_interest(line, functions_of_interest):
    for function in functions_of_interest:
        assert(function)
        if function in line:
            return True

    return False

def select_breakpoints(functions_of_interest: list, breakpoints: list):
    selected_breakpoints = []
    interesting_function_found = False

    for i in range(len(breakpoints)):
        line = breakpoints[i]
        if '#' in line:
            if has_a_function_of_interest(line, functions_of_interest):
                interesting_function_found = True
                selected_breakpoints.append(line + '\n')
        elif 'break' in line:
            if interesting_function_found:
                selected_breakpoints.append(line + '\n')
            interesting_function_found = False

    return selected_breakpoints


def main(argv):
    if len(argv) < 3:
        print('Usage ./gen_breakpoints functions_of_interest.txt BREAKPOINTS.txt')
        return

    if 'functions_of_interest.txt' not in argv[1]:
        print('functions_of_interest.txt must be provided before BREAKPOINTS.txt and must have that name')
        return

    functions_of_interest_file = open(argv[1])
    functions_of_interest = functions_of_interest_file.read()
    functions_of_interest_file.close()
    functions_of_interest = functions_of_interest.split('\n')
    functions_of_interest = list(filter(None, functions_of_interest))

    breakpoints_file = open(argv[2], 'r')
    breakpoints = breakpoints_file.read()
    breakpoints_file.close()
    breakpoints = breakpoints.split('\n')

    selected_breakpoints = select_breakpoints(functions_of_interest, breakpoints)

    selected_breakpoints_file = open('selected_breakpoints.txt', 'w')
    selected_breakpoints_file.write(''.join(selected_breakpoints))
    selected_breakpoints_file.close()

if __name__ == '__main__':
    main(sys.argv)

<file_sep>#!/bin/bash
# translate_brakpoints_fcn.sh - takes gdb.txt ("set logging on") and from the addresses of the 
# hit functions it looks up the function name in vmlinux_breakpoints.txt
# Input: gdb.txt and file_breakpoints.txt

GDB="$1"
DICT="$2"
ADDR_COL=3

while read line; do
    if [[ "$line" == *"??"* ]] ; then
       echo "$line" | cut -d " " -f $ADDR_COL >> hit_breakpoints
    fi
done < $GDB

#sed -i '$ d' hit_breakpoints # Used to deal with last line in file

while read address; do 
    while read line; do
        if [[ "$line" == *"break"* ]]; then 
            :
        else
            if [[ "$line" == *"$address"* ]]  ; then
                # sed -i -e 's/'$address'/'$line'' $BP
                echo "$line" >> list_hit_breakpoints
            fi
        fi
    done < "$DICT"
done < hit_breakpoints

<file_sep>#!/bin/bash
function umg-connect() {
    UMG_PW='<PASSWORD>'
    if [ "$#" -eq 0 ] ; then
        UMG_IP=10.10.92.69
        SSH_PORT=4022
    else
        UMG_IP="$1" 
        SSH_PORT=4022
    fi
    sshpass -p $UMG_PW ssh -oStrictHostKeyChecking=no root@$UMG_IP -p $SSH_PORT
}

function umg-connect-first() {
    UMG_PW='<PASSWORD>'
    if [ "$#" -eq 0 ] ; then
        UMG_IP=10.10.92.69
        SSH_PORT=4022
    else
        UMG_IP="$1" 
        SSH_PORT=4022
    fi
    ssh -oStrictHostKeyChecking=no root@$UMG_IP -p $SSH_PORT
}
function umg-cp-to() {
    UMG_PW='<PASSWORD>'
    if [ "$#" -eq 2 ] ; then
        UMG_IP=10.10.92.69
        SSH_PORT=4022
        FILE="$1"
        TO_PATH="$2"
    else
        UMG_IP="$1" 
        SSH_PORT=4022
        FILE="$2"
        TO_PATH="$3"
    fi
    sshpass -p $UMG_PW scp -P $SSH_PORT $FILE root@$UMG_IP:$TO_PATH
}
<file_sep>#!/bin/bash
#
#
#

ctags -R --exclude=tools/testing/* .

<file_sep>#!/bin/bash
# set_disable_once.sh - Takes a list of breakpoints and disables every breakpoint once it is hit
# Input: list of breakpoints already in gdb format

FILE="$1"
n=0
sed -i -e 's/break \(\*0x[0-9a-f]*\).*/\0\n  commands\ndisable\ncontinue\n  end/' $FILE
while read line; do 
    string="disable"
    if [[ "$line" == "$string" ]] ; then
        n=$((++n))
        echo "$line" | sed -e 's/disable/disable '$n'/' >> selected_breakpoints_commands
    else
        echo "$line" >> selected_breakpoints_commands
    fi
done < $FILE
<file_sep>#!/bin/bash
#
#
#
# Usage: sudo ./do_all.sh vmlinux functions_of_interest.txt (yes)  - Args inside () are optional

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi


FILE="$1" # usually vmlinux in this script, but can also apply to any non-stripped ELF inside a virtual disk
LIST="$2" # functions_of_insterest.txt - Must be a file with this exact name with the function names
DISABLE="$3" # Yes if you want to set all the breakpoints to automatic mode

if [ "$#" -eq 3 ] ; then
    virt-copy-out -a ../alpine.qcow /root/lisha-dev/linux-3.18.20/${FILE} .
    echo "Got File From Virtual Disk"

    if [ -f "$FILE" ]; then
        echo "Generating Breakpoints"
        ./gen_breakpoints.sh $FILE

        echo "Filtering Breakpoints"
        ./gen_breakpoints.py $LIST ${FILE}_breakpoints.txt

        if [[ "$DISABLE" == "yes" ]] ; then
            echo "Adding Commands"
            ./set_disable_once.sh selected_breakpoints.txt
        fi
        
        echo "Generating Object Dump"
        objdump -S $FILE > objdump_list
    fi
fi
<file_sep>#!/bin/bash

printf "rbock:\n"
fortune

printf "\n\nnaka:\n"
fortune

printf "\n\ngfdamasio:\n"
fortune

printf "\n\nrafascar:\n"
fortune

printf "\n\nmeurer:\n"
fortune

printf "\n\narthur:\n"
fortune

printf "\n\nzeinacio:\n"
fortune
<file_sep>#!/usr/bin/python3

import sys
import binascii


def crc32(buf):
    """
    Generates the CRC32 for a given buffer

    :param buf: Bytes to be used when generating the checksum.
    :type buf: bytes
    :return: 4 bytes Big endian of the generated crc
    :rtype: bytes
    """
    return binascii.crc32(buf).to_bytes(4, byteorder='big', signed=False)


def add_crc32_to_file(path):
    """
    Generates the crc32 of the given file and appends to the end of it.

    :param path: Valid file path.
    :type path: str
    """
    with open(path, 'rb+') as file:
        buf = file.read()
        print("CALCULATED CRC IS:", crc32(buf))
        file.write(crc32(buf))


if __name__ == "__main__":
    if len(sys.argv) -1 < 1:
        print("Wrong args")
        sys.exit(1)
    else:
        add_crc32_to_file(sys.argv[1])
        sys.exit(0)
<file_sep>#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Module Description:


Example:


Todo:
    *Bot para avisar quando der 8 horas
    *Bot para avisar quando deu horário do almoço
    *Bot para avisar caso não tenha uma hora de intervalo durante o dia

"""

__author__ = "<NAME>"
__email__ = "<EMAIL>"


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import sys
import time
from datetime import datetime
from datetime import date
import calendar
import math


class bcolors:
    RED = "\033[1;31m"
    BLUE = "\033[1;34m"
    CYAN = "\033[1;36m"
    GREEN = "\033[0;32m"
    YELLOW = "\033[1;33m"
    RESET = "\033[0;0m"
    BOLD = "\033[;1m"
    REVERSE = "\033[;7m"
    B_YELLOW = "\033[0;43m"
    B_BLACK = "\033[0;40m"
    BLACK = "\033[0;30m"


def check_work_regular(work_intervals):
    for interval in work_intervals:
        if interval > 360:
            print("WORK TIME FOR DAY IS IRREGULAR, WORKED MORE THAN 6 STRAIGHT HOURS")
            return False
        else:
            return True


def check_pause_regular(pause_intervals):
    had_lunch_interval = False
    for interval in pause_intervals:
        if interval >= 60:
            had_lunch_interval = True
    return had_lunch_interval


def check_regular(work_intervals, pause_intervals):
    if sum(work_intervals) > 360:
        work = check_work_regular(work_intervals)
        pause = check_pause_regular(pause_intervals)
        return work and pause
    elif sum(work_intervals) == 0:
        return None
    else:
        return True


def get_work_intervals(time_list):
    work_intervals = []
    time_stamps = len(time_list)
    time_list = turn_into_datetime(time_list)
    if time_stamps == 0:
        return work_intervals

    elif time_stamps % 2 == 0:
        for i in range(0, time_stamps, 2):
            if i < time_stamps:
                work_intervals.append((time_list[i + 1] - time_list[i]).seconds / 60)

    elif time_stamps % 2 == 1:
        for i in range(0, time_stamps, 2):
            if i + 1 < time_stamps:
                work_intervals.append((time_list[i + 1] - time_list[i]).seconds / 60)
            else:
                now = datetime.today().strftime("%H:%M")
                now = turn_into_datetime(now)
                work_intervals.append((now - time_list[i]).seconds / 60)

    return work_intervals


def get_pause_intervals(time_list):
    pause_intervals = []
    time_stamps = len(time_list)
    time_list = turn_into_datetime(time_list)
    if time_stamps <=2:
        return pause_intervals
    pauses = math.ceil(time_stamps / 2)
    for i in range(0, pauses, 2):
        pause_intervals.append((time_list[i + 2] - time_list[i + 1]).seconds / 60)

    return pause_intervals


def turn_into_datetime(times):
    if type(times) is list:
        time_list = []
        for item in times:
            item = datetime.strptime(item, '%H:%M')
            time_list.append(item)
        return time_list
    else:
        times = datetime.strptime(times, '%H:%M')
        return times


def get_work_time_today(time_list):
    work_intervals = get_work_intervals(time_list)
    work_minutes_today = sum(work_intervals)
    return work_minutes_today


def get_pause_time_today(time_list):
    pause_intervals = get_pause_intervals(time_list)
    pause_minutes_today = sum(pause_intervals)
    return pause_minutes_today


def get_extra_hours(overview_table):
    for row in overview_table.splitlines():
        if 'SALDO' in row:
            extra_hours = row.split()[1]
            return extra_hours
    return "Not Found"


def get_list_of_dates(year, month):
    days_in_month = calendar.monthrange(year, month)[1]
    dates = [date(year, month, day) for day in range(1, days_in_month + 1)]
    dates_str_list = []
    for item in dates:
        dates_str_list.append(item.strftime("%d/%m/%Y"))

    return dates_str_list


def login_and_get_info():
    # browser = webdriver.Firefox()
    browser = webdriver.PhantomJS()

    browser.get('https://www.ahgora.com.br/externo/index/empresakhomp')
    assert ':: Ahgora Sistemas ::' in browser.title

    form = browser.find_element_by_id('boxLogin')

    elem = form.find_element_by_id('matricula')  # Find the search box
    elem.send_keys('305' + Keys.TAB)

    elem = browser.find_element_by_id('senha')  # Find the search box
    elem.send_keys('1226' + Keys.RETURN)
    time.sleep(4)

    print("Logged in as:")
    elems = browser.find_elements_by_xpath("//div[@class='col-xs-12 col-sm-9']/dl/dd")
    print(elems[0].text)

    browser.find_element_by_id('espelho_ponto_icon').click()

    time.sleep(5)

    elem = browser.find_element_by_id('titulo_mes')

    tables = browser.find_elements_by_xpath("//tbody")

    overview_table = tables[0].text
    time_table = tables[1].text
    time.sleep(1)
    tables = [overview_table, time_table]
    browser.quit()
    return tables


def get_time_list(time_table, date_of_interest):

    time_list = []
    for item in time_table.splitlines():
        if date_of_interest in item:
            if "KHOMP BATIDAS - KHOMP BATIDAS" in item:
                table_list = item.split("KHOMP BATIDAS - KHOMP BATIDAS")[1]
                table_list = table_list.split(" ")
                table_list.pop(0)
                for item in table_list:
                    if item == "Horas" or item == "Feriado:":
                        break
                    elif item == "Banco":
                        break
                    time_list.append(item.replace(",", ""))
            else:
                table_list = []

    return time_list


def main():
    curr_year = datetime.today().year
    curr_month = datetime.today().month
    list_of_dates = get_list_of_dates(curr_year, curr_month)
    today_str = datetime.today().strftime("%d/%m/%Y")

    tables = login_and_get_info()

    overview_table = tables[0]
    time_table = tables[1]
    print(bcolors.CYAN + "--------------------------------------------------")
    print("|     DATE     | WORK TIME | PAUSE TIME | STATUS |")
    print("--------------------------------------------------" + bcolors.RESET)
    for day in list_of_dates:
        time_list = get_time_list(time_table, day)

        work_time = get_work_time_today(time_list)
        pause_time = get_pause_time_today(time_list)

        work_hours = int(work_time / 60)
        work_minutes = int(work_time % 60)

        pause_hours = int(pause_time / 60)
        pause_minutes = int(pause_time % 60)

        work_intervals = get_work_intervals(time_list)
        pause_intervals = get_pause_intervals(time_list)

        ok_status = check_regular(work_intervals, pause_intervals)
        if ok_status:
            ok_status = bcolors.GREEN + str(ok_status) + bcolors.RESET
        elif ok_status is None:
            pass
        elif not ok_status:
            ok_status = bcolors.RED + str(ok_status) + bcolors.RESET

        if day == today_str:
            day = bcolors.YELLOW + day + bcolors.RESET

        print("|  %s  |   %02d:%02dh   |   %02d:%02dh   | %s |" % (day, work_hours, work_minutes, pause_hours, pause_minutes, ok_status))

        if day == today_str:
            sys.stdout.write(bcolors.RESET)

    extra_hours = get_extra_hours(overview_table)

    print(bcolors.CYAN + "--------------------------------------------------")
    print("|       You have in total %sh extra hours     |" %(extra_hours))
    print("--------------------------------------------------" + bcolors.RESET)


if __name__ == "__main__":
    main()
<file_sep>#!/bin/bash
# Generates the files used for debugging the kernel 
# The last argument is optional - if set to yes disables the breakpoints when
# they are hit
#
# Usage: ./gen_debug vmlinux functions_of_interest.txt (yes) 

FILE="$1" # Target ELF, in our case is vmlinux
LIST="$2" # functions_of_interest.txt - Must be the file with this exact name
DISABLE="$3" # yes, if the user wants to disable all of the breakpoints when hit
# which contains parts of function names that will be filtered

if [ "$#" -ge 2 ] ; then

    echo "Generating the Breakpoints from ELF"
    ./gen_breakpoints.sh $FILE

    echo "Filtering functions from file"
    ./gen_breakpoints.py $LIST vmlinux_breakpoints.txt

    echo "Generating Object Dump from ELF"
    objdump -S $FILE > kernel_dump

    if [ "$#" -eq 3 ] ; then

        if [[ "$DISABLE" == "yes" ]] ; then
            echo "Adding Commands to disable breakpoints after hit"
            ./set_disable_once.sh selected_breakpoints.txt
        fi

    fi
fi


<file_sep>#!/bin/bash
#
#
#
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then
    echo Wrong Usage Dummy
else
    if [ "$#" -ge 2 ] ; then
        DIR="$1"
        PATTERN="$2"
        grep -rnw $DIR -i -E -e $PATTERN;
    fi
    
    if [ "$#" -eq 1 ] ; then
        PATTERN="$1"
        grep -rnw ./ -i -E -e $1;
    fi
fi
