import csv
import logging


def get_function_signature(hex_signature):
    """
    Requests the function signature from the CSV file based on the hex_signature to get the text_signature

    Args:
      hex_signature: the 4-byte signature of the function as hex value (a string starting with 0x)

    Returns:
      signature of the function as text
    """

    # read csv, and split on ";" the line
    csv_file = csv.reader(open('data/fourbytes.csv', "r"), delimiter=";")

    # loop through csv list
    for row in csv_file:
        # if current rows 2nd value is equal to hex signature, function signature found
        if row[1][2:] == hex_signature[2:]:
            logging.info("got function signature: " + row[0])
            return row[0]

    # hex_signature is returned if no text signature was found in the csv file
    return hex_signature