100000 Find_Imports 0 100000 true 0 CSharp false false 1 Corp 1 CSharp_Exploitable_Path Comment rootComment = new Comment(); Func<string,LinePragma, Comment> BuildComment = (importName, LP) => { var comment = new Comment(importName, importName, rootComment, LP); comment.ResolveShortName(importName); return comment; }; CxList imports = All.FindByType(typeof(Import)); foreach(CxList node in imports){ try{ Import import = node.TryGetCSharpGraph<Import>(); var name = import.Namespace; var commentToAdd = BuildComment(name, import.LinePragma); result.Add(commentToAdd.NodeId, commentToAdd); }catch(Exception e){} } 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<MethodInvokeExpr>(); CxList ctors = All.FindByType<ObjectCreateExpr>(); CxList typeRefs = All.FindByType(typeof(TypeRef)); CxList declarators = All.FindByType(typeof(Declarator)); CxList genericTypes = All.FindByType(typeof(GenericTypeRef)); CxList definitions = All.FindByTypes( typeof(MethodDecl), typeof(ClassDecl), typeof(ConstructorDecl), typeof(Declarator), typeof(ParamDecl), typeof(ConstantDecl), typeof(FieldDecl), typeof(AccessorDecl), typeof(PropertyDecl), typeof(DelegateDecl), typeof(DestructorDecl), typeof(EventDecl), typeof(InterfaceDecl), typeof(MemberDecl), typeof(StructDecl), typeof(VariableDecl) ); Func<string, string, string[], LinePragma, int> AddToResults = (objectName, methodName, methodParams,LP) => { string signature = objectName + methodName + "||(" + string.Join("||,", methodParams) + "||)"; Comment comment = new Comment(methodName, methodName, rootComment, LP); comment.ResolveShortName(signature); result.Add(comment.NodeId, comment); return 1; }; // Imports Func<Param, string> GetParamType = (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"; }; foreach(CxList method in allMethods){ if (definitions.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 = definitions.FindDefinition(target); CxList objectCreate = ctors.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(); } if (objectName.StartsWith("CxOrphanClass_")) { foundSignature = true; objectName = "object"; } string signature = foundSignature ? objectName + "||." : ""; AddToResults(signature, methodName, methodParams.ToArray(), graph.LinePragma); } 1