Skip to content

Common

FileExt

Set some index to file types supported by the tool

Source code in src/utils/common.py
class FileExt:
    '''
    Set some index to file types supported by the tool
    '''
    NonText     = 0
    Text        = 1
    C           = 2
    Java        = 3
    ShellScript = 4
    Python      = 5
    Perl        = 6
    PHP         = 7
    Ruby        = 8

djb2_hash(string)

djb2 hash (http://www.cse.yorku.ca/~oz/hash.html)

Parameters:

Name Type Description Default
string String

the string to be hashed

required
Return

hash (String): hash value

Source code in src/utils/common.py
def djb2_hash(string):
    '''
    djb2 hash (http://www.cse.yorku.ca/~oz/hash.html)

    Args:
        string (String): the string to be hashed
    Return:
        hash (String): hash value
    '''
    hash = 5381
    for c in string:
        hash = ((hash << 5) + hash) + ord(c)
        hash &= 0xFFFFFFFF
    return hash

file_type(file_path)

Guess a file type based upon a file extension (mimetypes module)

Parameters:

Name Type Description Default
file_path String

the file path

required
Return

magic_ext

Source code in src/utils/common.py
def file_type(file_path):
    '''
    Guess a file type based upon a file extension (mimetypes module)

    Args:
        file_path (String): the file path
    Return:
        magic_ext
    '''
    try:
        return magic_cookie.from_file(file_path)
    except AttributeError:
        return magic_cookie.file(file_path)

fnv1a_hash(string)

FNV-1a 32bit hash (http://isthe.com/chongo/tech/comp/fnv/)

Parameters:

Name Type Description Default
string String

the string to be hashed

required
Return

hash (String): hash value

Source code in src/utils/common.py
def fnv1a_hash(string):
    '''
    FNV-1a 32bit hash (http://isthe.com/chongo/tech/comp/fnv/)

    Args:
        string (String): the string to be hashed
    Return:
        hash (String): hash value
    '''
    hash = 2166136261
    for c in string:
        hash ^= ord(c)
        hash *= 16777619
        hash &= 0xFFFFFFFF
    return hash

sdbm_hash(string)

sdbm hash (http://www.cse.yorku.ca/~oz/hash.html)

Parameters:

Name Type Description Default
string String

the string to be hashed

required
Return

hash (String): hash value

Source code in src/utils/common.py
def sdbm_hash(string):
    '''
    sdbm hash (http://www.cse.yorku.ca/~oz/hash.html)

    Args:
        string (String): the string to be hashed
    Return:
        hash (String): hash value
    '''
    hash = 0
    for c in string:
        hash = ord(c) + (hash << 6) + (hash << 16) - hash
        hash &= 0xFFFFFFFF
    return hash