/// <summary> /// Starts the part 2 of analysis to find out the package and relationship dependency /// </summary> public void analyzePartII() { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; foreach (object file in files) { if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzerRelationships builderreln = new BuildCodeAnalyzerRelationships(semi); CodeAnalysis.Parser parser = builderreln.build(); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } }
/// <summary> /// This is the method where we create the code anlayser object. /// There will be only one code analyser object for all the files. /// It uses the parser module to find the relationship analysis. /// Once the results are generated, it will be stored in the centralised /// repo. We use this centralised repo from other module to know /// the type and dependency analysis. /// </summary> /// <param name="serverName"></param> public void analyze(string serverName) { Console.Write("\n CODE ANALYZER"); Console.Write("\n ======================\n"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; try { foreach (object file in files) { Console.Write("\n\n Processing file {0}\n", file as string); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); Repository repo = Repository.getInstance(); repo.CurrentFileName = file.ToString(); Elem elem = getDefaultElemData(file.ToString(), serverName); repo.locations.Add(elem); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); } } catch (Exception) { Console.WriteLine("Error in the data. Exception thrown, pls check the input"); } }
/* * Method to parse through list of user input files and parse * for all user defined types */ public static void parseUserDefinedTypes(List <string> files) { if (files.Count == 0) { return; } foreach (String file in files) { Console.Write("Parsing for all user defined types"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file.ToString()); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); //test against the detect class rule try { //use the existing parser to test rule while (semi.getSemi()) { int index = isClassExpression(semi); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // local semiExp with tokens for type and name local.displayNewLines = false; local.Add(semi[index]).Add(semi[index + 1]); userDefinedSet.Add(semi[index + 1]); } } } catch (Exception ex) { Console.Write("\n\n {0}", ex.Message); } } // return userDefinedSet; }
public virtual Parser build() { Parser parser = new Parser(); // decide what to show AAction.displaySemi = true; AAction.displayStack = false; // this is default so redundant // action used for namespaces, classes, and functions PushStack push = new PushStack(repo); // capture namespace info DetectNamespace detectNS = new DetectNamespace(); detectNS.add(push); parser.add(detectNS); // capture class info DetectClass detectCl = new DetectClass(); detectCl.add(push); parser.add(detectCl); // capture function info DetectFunction detectFN = new DetectFunction(); detectFN.add(push); parser.add(detectFN); // handle entering anonymous scopes, e.g., if, while, etc. DetectAnonymousScope anon = new DetectAnonymousScope(); anon.add(push); parser.add(anon); // handle leaving scopes DetectLeavingScope leave = new DetectLeavingScope(); PopStack pop = new PopStack(repo); leave.add(pop); parser.add(leave); // parser configured return parser; }
//read the list of files, one by one and calls BuildCodeAnalyzer and parser functions public void analyze() { Console.Write("\n CODE ANALYZER"); Console.Write("\n ======================\n"); CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; foreach (object file in files) { Console.Write("\n\n Processing file {0}\n", file as string); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } Console.Write("\n Type and Function Analysis"); Console.Write("\n ----------------------------\n"); BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); if (relationshipflag) { semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzerRelationships builderreln = new BuildCodeAnalyzerRelationships(semi); parser = builderreln.build(); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } semi.close(); } }
/* This method is used to call the relationship and complexity analysis * for each file in the input set */ public void analyze() { CSsemi.CSemiExp semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; /* These are the supported file formats in this tool. If input file is not in this format, * then analysis will not be done*/ string[] supportedFileFormatList = { ".cs", ".c", ".cpp", ".java", ".txt", ".bat" }; foreach (object file in files) { string fileExtension = Path.GetExtension(file.ToString()); bool supportedFileFormat = false; foreach (string currentFileExtension in supportedFileFormatList) { if (fileExtension == currentFileExtension) { supportedFileFormat = true; } } if (!supportedFileFormat) { Console.WriteLine("\nThe file {0} is of unsupported format", file.ToString()); continue; } if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); CodeAnalysis.Parser parser = builder.build(); Repository repo = Repository.getInstance(); Elem elem = getDefaultElemData(file.ToString()); repo.locations.Add(elem); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } semi.close(); //Only when the user specifies the /R option, we do relationship analysis if (findRelationship) { semi = new CSsemi.CSemiExp(); semi.displayNewLines = false; if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return; } BuildCodeAnalyzerForRelationshipTypes builderreln = new BuildCodeAnalyzerForRelationshipTypes(semi); parser = builderreln.build(); try { while (semi.getSemi()) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } } semi.close(); } }
public virtual Parser build() { Parser parser = new Parser(); DetectScopeChange detectSC = new DetectScopeChange(parser.ScopeStack()); IAction print = new PrintScope(); detectSC.add(print); parser.add(detectSC); return parser; }
public virtual Parser build() { Parser parser = new Parser(); Print print = new Print(); DetectNamespace detectNS = new DetectNamespace(); detectNS.add(print); parser.add(detectNS); DetectClass detectCl = new DetectClass(); detectCl.add(print); parser.add(detectCl); /////////////////////////////////////////////////// // If you wanted to show member functions you // might do that something like this: // DetectFunction detectFN = new DetectFunction(parser.ScopeStack()); // PrintFunction printFunction = new PrintFunction(); // detectFN.add(printFunction); // parser.add(detectFN); return parser; }
public virtual Parser build() { Parser parser = new Parser(); // decide what to show AAction.displaySemi = true; AAction.displayStack = false; // this is default so redundant // action used for namespaces, classes, and functions PushStack push = new PushStack(repo); // capture inheritance info DetectInheritance detectIn = new DetectInheritance(); detectIn.add(push); parser.add(detectIn); // capture aggregated info DetectAggregation detectAg = new DetectAggregation(); detectAg.add(push); parser.add(detectAg); DetectComposition detectCs = new DetectComposition(); detectCs.add(push); parser.add(detectCs); DetectUsing detectUs = new DetectUsing(); detectUs.add(push); parser.add(detectUs); // parser configured return parser; }
public virtual Parser build() { Parser parser = new Parser(); AAction.displaySemi = true; AAction.displayStack = false; // this is default so redundant PushStack push = new PushStack(repo); DetectNamespace detectNS = new DetectNamespace(); detectNS.add(push); parser.add(detectNS); DetectClass detectCl = new DetectClass(); detectCl.add(push); parser.add(detectCl); DetectFunction detectFN = new DetectFunction(); detectFN.add(push); parser.add(detectFN); DetectScope detectScop = new DetectScope(); detectScop.add(push); parser.add(detectScop); DetectScopeWithoutBraces detectScopWB = new DetectScopeWithoutBraces(); detectScopWB.add(push); parser.add(detectScopWB); DetectAnonymousScope anon = new DetectAnonymousScope(); anon.add(push); parser.add(anon); DetectLeavingScopeWithoutBraces leaveWB = new DetectLeavingScopeWithoutBraces(); PopStack popWB = new PopStack(repo); leaveWB.add(popWB); parser.add(leaveWB); DetectLeavingScope leave = new DetectLeavingScope(); PopStack pop = new PopStack(repo); leave.add(pop); parser.add(leave); return parser; }
public virtual Parser build() { Parser parser = new Parser(); // decide what to show AAction.displaySemi = false; AAction.displayStack = false; // this is default so redundant // action used for inheritance, aggregation, composition and using PushStackRelationship push = new PushStackRelationship(repo); // capture Inheritance info DetectInheritance detectNS = new DetectInheritance(); detectNS.add(push); parser.add(detectNS); // capture class info DetectClass detectCl = new DetectClass(); detectCl.add(push); parser.add(detectCl); // capture Aggr info DetectAggregation detectAG = new DetectAggregation(); detectAG.add(push); parser.add(detectAG); // capture Composition info DetectComposition detectCP = new DetectComposition(); detectCP.add(push); parser.add(detectCP); // capture Using info DetectUsing detectUs = new DetectUsing(); detectUs.add(push); parser.add(detectUs); // parser configured return parser; }
public virtual Parser build_relation() { Parser parser_rel = new Parser(); // decide what to show AAction.displaySemi = false; AAction.displayStack = false; // this is default so redundant //// action used for namespaces, classes, and functions PushStack_relation push_rel = new PushStack_relation(repo); // capture inheritence info DetectInheritance detectIn = new DetectInheritance(); detectIn.add(push_rel); parser_rel.add(detectIn); // capture inheritence info DetectAggregation detectAg = new DetectAggregation(); detectAg.add(push_rel); parser_rel.add(detectAg); // capture using info DetectUsing detectUs = new DetectUsing(); detectUs.add(push_rel); parser_rel.add(detectUs); // capture using info DetectComposition detectCm = new DetectComposition(); detectCm.add(push_rel); parser_rel.add(detectCm); // capture inheritence info DetectClassRelation detectCl = new DetectClassRelation(); detectCl.add(push_rel); parser_rel.add(detectCl); // parser configured return parser_rel; }
public virtual Parser build() { Parser parser = new Parser(); AAction.displaySemi = false; AAction.displayStack = false; // this is default so redundant PushStack push = new PushStack(repo); // capture namespace info DetectNamespace detectNS = new DetectNamespace(); detectNS.add(push); parser.add(detectNS); // capture struct info DetectStruct detectSt = new DetectStruct(); detectSt.add(push); parser.add(detectSt); // capture enum info DetectEnum detectEn = new DetectEnum(); detectEn.add(push); parser.add(detectEn); // capture delegate info DetectDelegate detectDl = new DetectDelegate(); detectDl.add(push); parser.add(detectDl); // capture class info DetectClass detectCl = new DetectClass(); detectCl.add(push); parser.add(detectCl); // capture function info DetectFunction detectFN = new DetectFunction(); detectFN.add(push); parser.add(detectFN); // handle entering anonymous scopes, e.g., if, while, etc. DetectAnonymousScope anon = new DetectAnonymousScope(); anon.add(push); parser.add(anon); // capture array info DetectArray detectArr = new DetectArray(); detectArr.add(push); parser.add(detectArr); // handle leaving scopes DetectLeavingScope leave = new DetectLeavingScope(); PopStack pop = new PopStack(repo); leave.add(pop); parser.add(leave); // capture bracelessscope info DetectBraceLess detectBL = new DetectBraceLess(); detectBL.add(push); parser.add(detectBL); // parser configured return parser; }