100000 Find_Imports 0 100000 true 0 CSharp false false 1 Corp 1 CSharp_Exploitable_Path Comment rootComment = new Comment(); CxList imports = All.FindByType(typeof(Import)); // @TODO add more HashSet<string> builtinNamespaces = new HashSet<string> {"System.Reflection","System"}; foreach(CxList node in imports){ Import import = node.TryGetCSharpGraph<Import>(); string name = import.Namespace; //if (builtinNamespaces.Contains(name)){ // continue; //} AddToResults(name, import.LinePragma); } void AddToResults(string importName, LinePragma LP) { Comment comment = new Comment(importName, importName, rootComment, LP); comment.ResolveShortName(importName); result.Add(comment.NodeId, comment); } 1 100001 Find_Unresolved_Methods 0 100000 true 0 CSharp false false 1 Corp 1 CSharp_Exploitable_Path Comment rootComment = new Comment(); CxList allMethods = All.FindByType(typeof(MethodInvokeExpr)); CxList ctors = All.FindByType(typeof(ObjectCreateExpr)); CxList typeRefs = All.FindByType(typeof(TypeRef)); CxList declarators = All.FindByType(typeof(Declarator)); CxList genericTypes = All.FindByType(typeof(GenericTypeRef)); foreach(CxList method in allMethods){ if (All.FindDefinition(method).Count != 0){ continue; } MethodInvokeExpr graph = method.TryGetCSharpGraph<MethodInvokeExpr>(); List<string> methodParams = new List<string>(); foreach(Param parameter in graph.Parameters){ methodParams.Add(GetParamType(parameter)); } CxList target = method.GetTargetOfMembers(); CxList def = All.FindDefinition(target); CxList objectCreate = ctors.GetByAncs(def); CxList typeRef = typeRefs.GetByAncs(def); CxList declar = declarators.GetByAncs(def); Expression methObject = method.TryGetCSharpGraph<Expression>(); string methodName = method.GetName(); bool foundSignature = false; string name = ""; string objectName = ""; if (methObject is ObjectCreateExpr) { foundSignature = true; name = methodName; // In case of ctor, method and class names match objectName = methodName; } else if (objectCreate.Count > 0) { // When refering to Object Create Expression foundSignature = true; name = objectCreate.GetName(); objectName = objectCreate.GetName(); } else if (typeRef.Count > 0) { // When refering to Type Ref foundSignature = true; name = typeRef.GetName(); objectName = typeRef.GetName(); } else if (declar.Count > 0) { // When refering to Declarators Declarator declarator = declar.TryGetCSharpGraph<Declarator>(); LinePragma lpDecl = declarator.LinePragma; CxList relevantTypes = All.NewCxList(); relevantTypes.Add(genericTypes,typeRefs,ctors); CxList typeName = relevantTypes.FindByPosition(lpDecl.FileName, lpDecl.Line); typeName -= typeName.FindByShortName("?"); if (typeName.Count > 0) { foundSignature = true; name = typeName.GetName(); objectName = typeName.GetName(); } } if (objectName.StartsWith("CxOrphanClass_")) { foundSignature = true; objectName = "object"; } if(foundSignature){ AddToResults(objectName + "||.", methodName, methodParams.ToArray(), graph.LinePragma); } else{ AddToResults("", methodName, methodParams.ToArray(), graph.LinePragma); } } void AddToResults(string objectName, string methodName, string[] methodParams, LinePragma LP) { string signature = objectName + methodName + "||(" + string.Join("||,", methodParams) + "||)"; Comment comment = new Comment(methodName, methodName, rootComment, LP); comment.ResolveShortName(signature); result.Add(comment.NodeId, comment); } // Imports string GetParamType(Param param){ if (param.Value is LambdaExpr){ return "lambda"; } if (param.Value is BooleanLiteral) { return "boolean"; } if (param.Value is CharLiteral) { return "char"; } if (param.Value is IntegerLiteral) { return "int"; } if (param.Value is RealLiteral) { return "real"; // float or double } if (param.Value is StringLiteral) { return "string"; } return "object"; } 1