Added support for marking/unmarking/detecting cracks.

This commit is contained in:
2017-05-18 17:56:28 +01:00
parent fe10000b3c
commit 910c400a21
15 changed files with 296 additions and 51 deletions

View File

@@ -1,3 +1,9 @@
2017-05-18 Natalia Portillo <claunia@claunia.com>
* DBOps.cs:
* Workers.cs:
Added support for marking/unmarking/detecting cracks.
2017-05-18 Natalia Portillo <claunia@claunia.com>
* Workers.cs:

View File

@@ -76,6 +76,7 @@ namespace osrepodbmgr.Core
public DateTime LastAccessTimeUtc;
public DateTime LastWriteTimeUtc;
public FileAttributes Attributes;
public bool Crack;
}
public struct DBFolder
@@ -371,7 +372,7 @@ namespace osrepodbmgr.Core
{
entries = new List<DBFile>();
string sql = string.Format("SELECT * FROM files ORDER BY id LIMIT {0}, {1}", start, count);
string sql = string.Format("SELECT * FROM files ORDER BY sha256 LIMIT {0}, {1}", start, count);
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
@@ -728,6 +729,29 @@ namespace osrepodbmgr.Core
return true;
}
public bool ToggleCrack(string hash, bool crack)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
param1.ParameterName = "@hash";
param1.DbType = DbType.String;
param1.Value = hash;
param2.ParameterName = "@crack";
param2.DbType = DbType.Boolean;
param2.Value = crack;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
dbcmd.CommandText = "UPDATE files SET crack = @crack WHERE sha256 = @hash";
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
}
}

View File

@@ -54,7 +54,7 @@ namespace osrepodbmgr.Core
public delegate void FailedDelegate(string text);
public delegate void FinishedWithoutErrorDelegate();
public delegate void FinishedWithTextDelegate(string text);
public delegate void AddFileForOSDelegate(string filename, string hash, bool known);
public delegate void AddFileForOSDelegate(string filename, string hash, bool known, bool isCrack);
public delegate void AddOSDelegate(DBEntry os, bool existsInRepo, string pathInRepo);
public delegate void AddFileDelegate(DBFile file);
public delegate void AddFilesDelegate(List<DBFile> file);
@@ -401,6 +401,11 @@ public static event AddFilesDelegate AddFiles;
dbFile.Path = relpath;
dbFile.Sha256 = hash;
// TODO: Add common cracker group names?
dbFile.Crack |= (relpath.ToLowerInvariant().Contains("crack") || // Typical crack
relpath.ToLowerInvariant().Contains("crack") || // Typical keygen
relpath.ToLowerInvariant().Contains("[k]"));
Context.hashes.Add(relpath, dbFile);
counter++;
}
@@ -543,7 +548,7 @@ public static event AddFilesDelegate AddFiles;
UpdateProgress(null, "Checking files in database", counter, Context.hashes.Count);
if(AddFileForOS != null)
AddFileForOS(kvp.Key, kvp.Value.Sha256, dbCore.DBOps.ExistsFile(kvp.Value.Sha256));
AddFileForOS(kvp.Key, kvp.Value.Sha256, dbCore.DBOps.ExistsFile(kvp.Value.Sha256), kvp.Value.Crack);
counter++;
}
@@ -627,7 +632,7 @@ public static event AddFilesDelegate AddFiles;
{
DBFile file = new DBFile
{
Sha256 = kvp.Value.Sha256, ClamTime = null, Crack = false,
Sha256 = kvp.Value.Sha256, ClamTime = null, Crack = kvp.Value.Crack,
Length = kvp.Value.Length, Virus = null, HasVirus = null, VirusTotalTime = null
};
dbCore.DBOps.AddFile(file);
@@ -1841,5 +1846,23 @@ public static event AddFilesDelegate AddFiles;
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
}
}
public static void ToggleCrack(string hash, bool crack)
{
try
{
dbCore.DBOps.ToggleCrack(hash, crack);
if(Finished != null)
Finished();
}
catch(Exception ex)
{
if(Debugger.IsAttached)
throw;
if(Failed != null)
Failed(string.Format("Exception {0}\n{1}", ex.Message, ex.InnerException));
}
}
}
}