Skip to content

Commit b65c47b

Browse files
authored
Address Roslyn Warnings. (microsoft#356)
1 parent 180ca66 commit b65c47b

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

Diff for: .editorconfig

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ dotnet_diagnostic.CA1307.severity = none
1111

1212
# CA1031: General Exceptions
1313
dotnet_diagnostic.CA1031.severity = none
14+
15+
# CA1707: Remove the underscores from type name AttackSurfaceAnalyzer.Types.RUN_TYPE.
16+
dotnet_diagnostic.CA1707.severity = none
17+
18+
# CA2227: Collection properties should be read only
19+
dotnet_diagnostic.CA2227.severity = none

Diff for: Asa/Startup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5555
RequestPath = new PathString("")
5656
});
5757
}
58-
catch(Exception e)
58+
catch(Exception)
5959
{
6060
Log.Debug("Had an issue setting static file path. Reverting to default.");
6161
app.UseStaticFiles();

Diff for: Lib/Collectors/WindowsFileSystemUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static Signature GetSignatureStatus(string Path)
2828
var sig = new Signature(authenticodeInfo);
2929
return sig;
3030
}
31-
catch(Exception e)
31+
catch(Exception)
3232
{
3333
}
3434
return null;

Diff for: Lib/Objects/FileMonitorObject.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace AttackSurfaceAnalyzer.Objects
55
{
66
public class FileMonitorObject : CollectObject
77
{
8-
public string Path;
9-
public string OldPath;
10-
public string Name;
11-
public string OldName;
12-
public CHANGE_TYPE ChangeType;
13-
public string ExtendedResults;
14-
public string NotifyFilters;
15-
public string Serialized;
16-
public string Timestamp;
8+
public string Path { get; set; }
9+
public string OldPath { get; set; }
10+
public string Name { get; set; }
11+
public string OldName { get; set; }
12+
public CHANGE_TYPE ChangeType { get; set; }
13+
public string ExtendedResults { get; set; }
14+
public string NotifyFilters { get; set; }
15+
public string Serialized { get; set; }
16+
public string Timestamp { get; set; }
1717

1818
public override string Identity
1919
{

Diff for: Lib/Objects/Run.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace AttackSurfaceAnalyzer.Objects
55
{
66
public class Run
77
{
8-
public RUN_TYPE Type;
9-
public string RunId;
10-
public string Timestamp;
11-
public string Version;
12-
public string Platform;
13-
public Dictionary<RESULT_TYPE, bool> ResultTypes;
8+
public RUN_TYPE Type { get; set; }
9+
public string RunId { get; set; }
10+
public string Timestamp { get; set; }
11+
public string Version { get; set; }
12+
public string Platform { get; set; }
13+
public Dictionary<RESULT_TYPE, bool> ResultTypes { get; set; }
1414
}
1515
}

Diff for: Lib/Objects/SerializableCertificate.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SerializableCertificate
77
{
88
public SerializableCertificate (X509Certificate2 certificate)
99
{
10-
Thumbprint = certificate.Thumbprint;
10+
Thumbprint = certificate?.Thumbprint;
1111
Subject = certificate.Subject;
1212
PublicKey = certificate.PublicKey.EncodedKeyValue.Format(true);
1313
NotAfter = certificate.NotAfter;

Diff for: Lib/Utils/DatabaseManager.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ public static class DatabaseManager
7474
private const string UPDATE_TELEMETRY = "replace into persisted_settings values ('telemetry_opt_out',@TelemetryOptOut)"; //lgtm [cs/literal-as-local]
7575
private const string CHECK_TELEMETRY = "select value from persisted_settings where setting='telemetry_opt_out'";
7676

77-
private const string SQL_TRUNCATE = "delete from file_system_monitored where run_id=@run_id";
7877
private const string SQL_INSERT = "insert into file_system_monitored (run_id, row_key, timestamp, change_type, path, old_path, name, old_name, extended_results, notify_filters, serialized) values (@run_id, @row_key, @timestamp, @change_type, @path, @old_path, @name, @old_name, @extended_results, @notify_filters, @serialized)";
7978

8079
private const string PRAGMAS = "PRAGMA main.auto_vacuum = 0; PRAGMA main.synchronous = OFF; PRAGMA main.journal_mode = DELETE;";
8180

8281
private const string INSERT_RUN_INTO_RESULT_TABLE_SQL = "insert into results (base_run_id, compare_run_id, status) values (@base_run_id, @compare_run_id, @status);";
8382
private const string UPDATE_RUN_IN_RESULT_TABLE = "update results set status = @status where (base_run_id = @base_run_id and compare_run_id = @compare_run_id)";
8483

85-
private const string SQL_GET_RUN = "select run_id from runs where run_id=@run_id";
8684

8785
private const string GET_COMPARISON_RESULTS = "select * from findings where comparison_id = @comparison_id and result_type=@result_type order by level des;";
8886
private const string GET_SERIALIZED_RESULTS = "select change_type, Serialized from file_system_monitored where run_id = @run_id";
@@ -92,7 +90,6 @@ public static class DatabaseManager
9290
private const string SQL_QUERY_ANALYZED = "select * from results where status = @status"; //lgtm [cs/literal-as-local]
9391

9492
private const string SQL_CHECK_IF_COMPARISON_PREVIOUSLY_COMPLETED = "select * from results where base_run_id=@base_run_id and compare_run_id=@compare_run_id"; //lgtm [cs/literal-as-local]
95-
private const string INSERT_RUN = "insert into runs (run_id, file_system, ports, users, services, registry, certificates, type, timestamp, version, platform) values (@run_id, @file_system, @ports, @users, @services, @registry, @certificates, @type, @timestamp, @version, @platform)"; //lgtm [cs/literal-as-local]
9693
private const string SQL_GET_RESULT_TYPES = "select * from runs where run_id = @base_run_id or run_id = @compare_run_id"; //lgtm [cs/literal-as-local]
9794

9895
private const string GET_MONITOR_RESULTS = "select * from file_system_monitored where run_id=@run_id order by timestamp limit @offset,@limit;"; //lgtm [cs/literal-as-local]
@@ -217,12 +214,12 @@ public static bool Setup(string filename = null)
217214
return false;
218215
}
219216

220-
public static List<DataRunModel> GetResultModels(RUN_STATUS cOMPLETED)
217+
public static List<DataRunModel> GetResultModels(RUN_STATUS runStatus)
221218
{
222219
var output = new List<DataRunModel>();
223220
using (var cmd = new SqliteCommand(SQL_QUERY_ANALYZED, Connection, Transaction))
224221
{
225-
cmd.Parameters.AddWithValue("@status", RUN_STATUS.COMPLETED);
222+
cmd.Parameters.AddWithValue("@status", runStatus);
226223

227224
using (var reader = cmd.ExecuteReader())
228225
{
@@ -478,6 +475,10 @@ public static void BeginTransaction()
478475

479476
public static void InsertRun(string runId, Dictionary<RESULT_TYPE, bool> dictionary)
480477
{
478+
if (dictionary == null)
479+
{
480+
return;
481+
}
481482
string INSERT_RUN = "insert into runs (run_id, file_system, ports, users, services, registry, certificates, firewall, comobjects, eventlogs, type, timestamp, version, platform) values (@run_id, @file_system, @ports, @users, @services, @registry, @certificates, @firewall, @comobjects, @eventlogs, @type, @timestamp, @version, @platform)";
482483

483484
using var cmd = new SqliteCommand(INSERT_RUN, Connection, Transaction);
@@ -753,13 +754,17 @@ public static void SetOptOut(bool OptOut)
753754
}
754755
}
755756

756-
public static void WriteFileMonitor(FileMonitorObject obj, string RunId)
757+
public static void WriteFileMonitor(FileMonitorObject fmo, string RunId)
757758
{
759+
if (fmo == null)
760+
{
761+
return;
762+
}
758763
using var cmd = new SqliteCommand(SQL_INSERT, Connection, Transaction);
759764
cmd.Parameters.AddWithValue("@run_id", RunId);
760-
cmd.Parameters.AddWithValue("@path", obj.Path);
761-
cmd.Parameters.AddWithValue("@timestamp", obj.Timestamp);
762-
cmd.Parameters.AddWithValue("@serialized", JsonConvert.SerializeObject(obj));
765+
cmd.Parameters.AddWithValue("@path", fmo.Path);
766+
cmd.Parameters.AddWithValue("@timestamp", fmo.Timestamp);
767+
cmd.Parameters.AddWithValue("@serialized", JsonConvert.SerializeObject(fmo));
763768

764769
cmd.ExecuteNonQuery();
765770
}

0 commit comments

Comments
 (0)