#-----------------------------------------------------------------------------
# Three-Pronged Approach to Exploring the Limits of Static Malware Analyses:  
# Callsite Parameter Cardinality (CPC) Counting: get_cpc_accuracy.py                 
#                                                                               
# Compares the dictionary computed by cpc-tool to the ones generated by
# cpc_extract and tells their accuracy
#                                                                               
# <NAME> (<EMAIL>)                                       
#                                                                               
#-----------------------------------------------------------------------------
from __future__ import print_function
import sys


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print("Need at least 2 file arguments. Ground truth first.")
        sys.exit()

    wrong = list()
    truth = dict()
    test = dict()
    with open(sys.argv[1], 'r') as g:
        for line in g:
            tokens = line.split(" ")
            truth[tokens[0]] = tokens[1]
    g.close()

    right_count = 0
    wrong_count = 0
    with open(sys.argv[2], 'r') as f:
        for line in f:
            tokens = line.split(" ")
            try:
                if int(truth[tokens[0]]) == int(tokens[1]):
                    right_count += 1
                else:
                    wrong_count += 1
                    entry = ""
                    entry = tokens[0] + "=" + truth[tokens[0]].strip() + " !="\
                            + tokens[1].strip()
                    wrong.append(entry)
            except KeyError:
                pass
    f.close()

    percent = float(right_count)/float(right_count+wrong_count)

    print("%s %f accuracy for %d functions" %
          (sys.argv[2],percent,right_count+wrong_count))

    for entry in wrong:
        print(entry)

#-----------------------------------------------------------------------------
# Three-Pronged Approach to Exploring the Limits of Static Malware Analyses:  
# Callsite Parameter Cardinality (CPC) Counting: get_cpc_accuracy.py                 
#                                                                               
# Compares the dictionary computed by cpc-tool to the ones generated by
# cpc_extract and tells their accuracy
#                                                                               
# <NAME> (<EMAIL>)                                       
#                                                                               
#-----------------------------------------------------------------------------
from __future__ import print_function
import sys


if __name__ == '__main__':
    if len(sys.argv) < 3:
        print("Need at least 2 file arguments. Ground truth first.")
        sys.exit()

    wrong = list()
    truth = dict()
    test = dict()
    with open(sys.argv[1], 'r') as g:
        for line in g:
            tokens = line.split(" ")
            truth[tokens[0]] = tokens[1]
    g.close()

    right_count = 0
    wrong_count = 0
    with open(sys.argv[2], 'r') as f:
        for line in f:
            tokens = line.split(" ")
            try:
                if int(truth[tokens[0]]) == int(tokens[1]):
                    right_count += 1
                else:
                    wrong_count += 1
                    entry = ""
                    entry = tokens[0] + "=" + truth[tokens[0]].strip() + " !="\
                            + tokens[1].strip()
                    wrong.append(entry)
            except KeyError:
                pass
    f.close()

    percent = float(right_count)/float(right_count+wrong_count)

    print("%s %f accuracy for %d functions" %
          (sys.argv[2],percent,right_count+wrong_count))

    for entry in wrong:
        print(entry)

#----------------------------------------------------------------------------- # Three-Pronged Approach to Exploring the Limits of Static Malware Analyses: # Callsite Parameter Cardinality (CPC) Counting: get_cpc_accuracy.py # # Compares the dictionary computed by cpc-tool to the ones generated by # cpc_extract and tells their accuracy # # <NAME> (<EMAIL>) # #-----------------------------------------------------------------------------