def init(): global _tolerance _tolerance = float(85) #must be at least 85% similar, not considering added things global _referencetypeweightfalse _referencetypeweightfalse = float(999999999999999) global _referencetypeweighttrue _referencetypeweighttrue = float(0) global _sharedweightfalse _sharedweightfalse = float(999999999999999) global _sharedweighttrue _sharedweighttrue = float(0) global _methodweightfalse _methodweightfalse = float(4) global _methodweighttrue _methodweighttrue = float(1) global _fieldweightfalse _fieldweightfalse = float(5) global _fieldweighttrue _fieldweighttrue = float(1.25) global _propertyweightfalse _propertyweightflase = float(5) global _propertyweighttrue _propertyweighttrue = float(1.25) global _objecttypeweightfalse _objecttypeweightfalse = float(28) global _objecttypeweighttrue _objecttypeweighttrue = float(5) global _typeweighttrue _typeweighttrue = float(2) global _typeweightfalse _typeweightfalse = float(2) global _paramweighttrue _paramweighttrue = float(1) global _paramweightfalse _paramweightfalse = float(1) global _sizeweightfalse #per each sizebenchmark _sizeweightfalse = float(0.3) global _sizeweighttrue #whole thing matches _sizeweighttrue = float(2) global _sizebenchmark _sizebenchmark = float(4) def typemodelsmatch(model1,model2,dosize = True): #make sure model1 is the unobfuscated one! #To do: method params, number of shared classes for class maxscore = _referencetypeweighttrue + _objecttypeweighttrue + _sharedweighttrue + (len(model1.get("Fields")) * _fieldweighttrue) + (len(model1.get("Methods")) * _methodweighttrue) + (len(model1.get("Properties")) * _propertyweighttrue) #calculate maximum score score = float(0) if dosize: #we may not always want to do size, as it may not be as reliable as the others maxscore = maxscore + 8 #start off at 8, and subtract nothing for a perfect score #Size #Size follows a different structure than most other methods size1 = (len(model1.get("Fields")) + len(model1.get("Methods")) + len(model1.get("Properties"))) #how many methods, fields, and propeties are there? size2 = (len(model2.get("Fields")) + len(model2.get("Methods")) + len(model2.get("Properties"))) #how many methods, fields, and propeties are there? score = 8 - (((abs(size2 - size1) / _sizebenchmark) * _sizeweightfalse)) #depending on the difference in size, this could have a small impact, or be very bad #ReferenceType if model1.get("ReferenceType") == model2.get("ReferenceType"): score = score + _referencetypeweighttrue else: return(False) #Reference type MUST match #IsShared if model1.get("Shared") == model2.get("Shared"): score = score + _sharedweighttrue else: return(False) #Is shared MUST match #Type if model1.get("Type") == model2.get("Type"): score = score + _objecttypeweighttrue #else: #score = score - _objecttypeweightfalse #Fields fields1 = list(model1.get("Fields")) fields2 = list(model2.get("Fields")) #if len(fields1) > len(fields2): #choose the bigger one to make sure we consider all of the fields. #templist = fields1 #templist2 = fields2 #else: #templist = fields2 #templist2 = fields1 templist = fields2 #it's very normal to add on things, but not as common to delete them. So, most of the fields in the unobfuscated (earlier) one #should also exist in the obfuscated one (newer) templist2 = fields1 for item in templist2: if item in templist: score = score + _fieldweighttrue templist = listremoveitem(item,templist) #else: #score = score - _fieldweightfalse #Methods methods1 = list(model1.get("Methods")) methods2 = list(model2.get("Methods")) #if len(methods1) > len(methods2): #choose the bigger one to make sure we consider all of the methods. #templist = methods1 #templist2 = methods2 #else: #templist = methods2 #templist2 = methods1 templist = methods2 #it's very normal to add on things, but not as common to delete them. So, most of the methods in the unobfuscated (earlier) one #should also exist in the obfuscated one (newer) templist2 = methods1 for item in templist2: if item in templist: score = score + _methodweighttrue templist = listremoveitem(item,templist) #else: #score = score - _methodweightfalse #Properties properties1 = list(model1.get("Properties")) properties2 = list(model2.get("Properties")) #if len(properties1) > len(properties2): #choose the bigger one to make sure we consider all of the properties. #templist = properties1 #templist2 = properties2 #else: #templist = properties2 #templist2 = properties1 templist = properties2 #it's very normal to add on things, but not as common to delete them. So, most of the properties in the unobfuscated (earlier) one #should also exist in the obfuscated one (newer) templist2 = properties1 for item in templist2: if item in templist: score = score + _propertyweighttrue templist = listremoveitem(item,templist) #else: #score = score - _propertyweightfalse #To do: method params, number of shared classes for class global matchscore #I'm too lazy to make it a return so I will just make it global xD matchscore = ((score / maxscore) * 100) return(not(((score / maxscore) * 100) < _tolerance)) #is percentage score not less than tolerated percent?