노현종

추상화 정규화 추가

......@@ -66,7 +66,7 @@ namespace VulnCrawler
}
public static void Run() {
// Repository 폴더들이 있는 주소를 지정하면 하위 폴더 목록을 가져옴(Repository 목록)
Regex.CacheSize = 50;
// var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)");
var c = new VulnC();
......
......@@ -359,7 +359,6 @@ namespace VulnCrawler
{
continue;
}
if (!(trimLine.EndsWith("}") || trimLine.EndsWith(";")))
{
continue;
......@@ -370,7 +369,6 @@ namespace VulnCrawler
prevStartBlock = true;
continue;
}
mainLine = true;
}
......@@ -398,11 +396,7 @@ namespace VulnCrawler
{
blockList.Add(new Block { Code = mains, HasCritical = criticalBlock, Num = crNum++ });
}
}
}
bool cb = false;
......@@ -459,5 +453,75 @@ namespace VulnCrawler
return blockList;
}
public override string Abstract(string blockCode, IDictionary<string, string> dict, IDictionary<string, string> methodDict)
{
var split = blockCode.Split('\n');
var varName = "VAL";
var methodName = "FUNC";
int varIdx = dict.Count();
int methodIdx = methodDict.Count();
var removes = Regex.Split(blockCode, Environment.NewLine, RegexOptions.Multiline);
StringBuilder builder = new StringBuilder();
Console.ForegroundColor = ConsoleColor.DarkYellow;
foreach (var item in removes)
{
if (string.IsNullOrWhiteSpace(item))
{
continue;
}
Console.Write(item);
builder.Append(item);
// Console.ReadLine();
}
// Console.WriteLine(builder.ToString());
Console.ResetColor();
foreach (var line in split)
{
var varList = ExtractMethodVariantList(line, skipDefine: false);
if (varList == null)
{
continue;
}
foreach (var var in varList.Vars)
{
if (!dict.ContainsKey(var))
{
dict[var] = varName + varIdx++;
}
}
foreach (var m in varList.Methods)
{
if (!methodDict.ContainsKey(m))
{
methodDict[m] = methodName + methodIdx++;
}
}
}
var sortVarDict = dict.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
var sortMethodDict = methodDict.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
string temp = blockCode;
foreach (var pair in sortVarDict)
{
temp = Regex.Replace(temp, $@"\b{pair.Key}\b", pair.Value);
}
foreach (var pair in sortMethodDict)
{
temp = Regex.Replace(temp, $@"\b{pair.Key}\b", pair.Value);
}
temp = Regex.Replace(temp, @"\s", "", RegexOptions.Multiline);
temp = Regex.Replace(temp, @"{|}|;|\)|\(", "");
temp = temp.ToUpper();
return temp;
}
}
}
......
......@@ -75,5 +75,10 @@ namespace VulnCrawler
{
throw new NotImplementedException();
}
public override string Abstract(string blockCode, IDictionary<string, string> dict, IDictionary<string, string> methodDict)
{
throw new NotImplementedException();
}
}
}
......
......@@ -41,16 +41,13 @@ namespace VulnCrawler
private static void PrintPatchEntrys(IEnumerable<PatchEntryChanges> entrys, VulnAbstractCrawler self, string commitMsg, string cve) {
foreach (var entry in entrys) {
// 기존 소스코드
var oldOid = entry.OldOid;
try
{
Blob oldBlob = self.Repository.Lookup<Blob>(oldOid);
string oldContent = oldBlob.GetContentText();
// 변경된 소스코드
var newOid = entry.Oid;
Blob newBlob = self.Repository.Lookup<Blob>(newOid);
......@@ -116,6 +113,7 @@ namespace VulnCrawler
Console.WriteLine($"=====block({block.Num}, {block.HasCritical.ToString()})");
Console.WriteLine(block.Code);
Console.ResetColor();
Console.WriteLine($"AbsCode = \n{block.AbsCode}");
Console.WriteLine($"MD5 = {block.Hash}");
}
......@@ -178,7 +176,7 @@ namespace VulnCrawler
catch (Exception e)
{
// Console.WriteLine(entry.Patch);
// Console.WriteLine(e.ToString());
// Console.WriteLine(e.ToString());
// Console.ReadLine();
continue;
}
......