def getAmountOfData(index, amount, files):
    data = []
    for i in range(index * amount, (index + 1) * amount):
        if i < len(files):
            fileData = jsonf.getData(files[i])
            data.append(fileData)
    return data
def getMethodDictionary(path):
    """
	Load the dictionary, which is located at 'path'
	:param path: path to the location of the dictionary
	:type path: string
	:return: dictionary containing the method names of API traces
	:rtype: list
	"""
    dictionary = jsonf.getData(path)
    return dictionary
def createTSVForFolder(threshold, length, pathToFolder, pathToDictionary,
                       numberOfMalBehaviors):
    data = []
    # the numbering of the malicious behaviors starts at 1
    for i in range(1, numberOfMalBehaviors + 1):
        data.extend(
            jsonf.getData(pathToFolder + 'malBehavior_' + str(i) +
                          '/logMaliciousWithPath_' + str(length) + '.txt'))
    # insert only these files that are classified as 'malicious' regarding the threshold in the output file
    files = getMaliciousFiles(threshold, data, False)
    writeDataToTSVFile(files, length, threshold, pathToDictionary,
                       pathToFolder)
def updateNumericDictionaryOfMethods(pathToNewTraces, pathToDictionary):
    """
	Update the dictionary with the method names of API calls in the given traces
	:param pathToNewTraces: path to the folder containing the traces, for which the dictionary should be updated
	:param pathToDictionary: path to the location of the dictionary
	:type pathToNewTraces: string
	:type pathToDictionary: string
	:example:

	dictionaryMethods.updateNumericDictionaryOfMethods('../../input_data/piggybacked_malware/', '../../input_data/dictionary.txt')
	"""
    old_dict = jsonf.getData(pathToDictionary)
    updated_dict = update(pathToNewTraces, old_dict)
    jsonf.write(pathToDictionary, updated_dict)
    print('numeric dictionary of methods updated')
def getMaliciousFiles(pathToFile, threshold):
    data = jsonf.getData(pathToFile)
    files = hdata.getMaliciousFiles(threshold, data, True)
    return files
def getFilesForTSVFile(threshold, path):
    data = jsonf.getData(path)
    # include only files that are classified as 'malicious' regarding the threshold
    maliciousFiles = getMaliciousFiles(threshold, data, False)
    return maliciousFiles
def fetchSampleFixedLength(pathToElement, pathToDictionary, length):
    entries = jsonf.getData(pathToElement)
    sample = createSampleFromData(entries, pathToDictionary)
    # only consider the first 'x' methods of the sample in order to fix the length of the sample
    sample = sample[0:length]
    return sample