-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
98 lines (88 loc) · 3.36 KB
/
Copy pathMain.cs
File metadata and controls
98 lines (88 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Copyright (C) 2009 Vadim Chekan
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
using System;
using System.Collections.Generic;
using System.IO;
using Mono.Cecil;
using CodeQL;
using SysConsole=System.Console;
using CodeQL.DataSources;
using CodeQL.Queries;
namespace CodeQL.Console
{
class MainClass
{
static List<string> _files = new List<string>();
static Action _action = null;
static string _unparsed = null;
static NDesk.Options.OptionSet _options;
public static int Main(string[] args)
{
log4net.Config.BasicConfigurator.Configure();
log4net.LogManager.GetLogger(typeof(MainClass).FullName).Debug("Started");
_options = new NDesk.Options.OptionSet().
Add("file=", o => _files.Add(o) ).
Add("print", o => _action = Print ).
Add("console", o => { _action = new CodeConsole().Run; }).
Add("scan", o => _action = () => {new BinScanner().AddFiles(_files).Scan(); }).
Add("translate", o => _action = () => new SqlTranslator().Select(_unparsed)).
Add("help|h|?", o => _action = () => { _options.WriteOptionDescriptions(SysConsole.Error); });
var remains = _options.Parse(args);
if(remains != null && remains.Count > 0)
_unparsed = string.Join(" ", remains.ToArray());
if(_action == null) {
_options.WriteOptionDescriptions(SysConsole.Error);
return 1;
}
_action();
SysConsole.WriteLine("Done");
return 0;
}
static void Print() {
new SolutionParser().AddFiles(_files).Walk(
(file,asm) => SysConsole.WriteLine("{0}:{1}", file, asm.Name.Name),
type => SysConsole.WriteLine(" {0}",type.Name),
att => SysConsole.WriteLine(" {0}", att),
ctor => SysConsole.WriteLine(" .ctor:{0}", ctor),
evt => SysConsole.WriteLine(" event:{0}",evt),
field => SysConsole.WriteLine(" field:{0}", field),
generic => SysConsole.WriteLine(" generic:{0}",generic),
iface => SysConsole.WriteLine(" interface:{0}",iface),
method => SysConsole.WriteLine(" method:{0}()", method),
nestedType => SysConsole.WriteLine(" nested type:{0}", nestedType),
prop => SysConsole.WriteLine(" prop:{0}",prop)
);
}
/*
* Use cases:
* How many public classes is there in solution?
* How many total classes is there is solution?
* The same as 2 above, but grouped by assembly
* All above but exclude System.*, Windows.*
* Include MyCompany.* only
* How many public methods
* Total
* Per assembly
* Draw class hierarchy (text, png) (optional with a root)
* Select classes with attribute X
* Select methods/properties which are called just once.
* Select empty catches
* Select count/(grouped by) of compiler generated classes/members/functions, etc.
*/
}
}