Showing
5 changed files
with
78 additions
and
11 deletions
... | @@ -66,7 +66,7 @@ namespace VulnCrawler | ... | @@ -66,7 +66,7 @@ namespace VulnCrawler |
66 | } | 66 | } |
67 | public static void Run() { | 67 | public static void Run() { |
68 | // Repository 폴더들이 있는 주소를 지정하면 하위 폴더 목록을 가져옴(Repository 목록) | 68 | // Repository 폴더들이 있는 주소를 지정하면 하위 폴더 목록을 가져옴(Repository 목록) |
69 | - | 69 | + Regex.CacheSize = 50; |
70 | 70 | ||
71 | // var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)"); | 71 | // var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)"); |
72 | var c = new VulnC(); | 72 | var c = new VulnC(); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -359,7 +359,6 @@ namespace VulnCrawler | ... | @@ -359,7 +359,6 @@ namespace VulnCrawler |
359 | { | 359 | { |
360 | continue; | 360 | continue; |
361 | } | 361 | } |
362 | - | ||
363 | if (!(trimLine.EndsWith("}") || trimLine.EndsWith(";"))) | 362 | if (!(trimLine.EndsWith("}") || trimLine.EndsWith(";"))) |
364 | { | 363 | { |
365 | continue; | 364 | continue; |
... | @@ -370,7 +369,6 @@ namespace VulnCrawler | ... | @@ -370,7 +369,6 @@ namespace VulnCrawler |
370 | prevStartBlock = true; | 369 | prevStartBlock = true; |
371 | continue; | 370 | continue; |
372 | } | 371 | } |
373 | - | ||
374 | mainLine = true; | 372 | mainLine = true; |
375 | } | 373 | } |
376 | 374 | ||
... | @@ -398,11 +396,7 @@ namespace VulnCrawler | ... | @@ -398,11 +396,7 @@ namespace VulnCrawler |
398 | { | 396 | { |
399 | blockList.Add(new Block { Code = mains, HasCritical = criticalBlock, Num = crNum++ }); | 397 | blockList.Add(new Block { Code = mains, HasCritical = criticalBlock, Num = crNum++ }); |
400 | } | 398 | } |
401 | - | ||
402 | - | ||
403 | } | 399 | } |
404 | - | ||
405 | - | ||
406 | } | 400 | } |
407 | 401 | ||
408 | bool cb = false; | 402 | bool cb = false; |
... | @@ -459,5 +453,75 @@ namespace VulnCrawler | ... | @@ -459,5 +453,75 @@ namespace VulnCrawler |
459 | 453 | ||
460 | return blockList; | 454 | return blockList; |
461 | } | 455 | } |
456 | + | ||
457 | + public override string Abstract(string blockCode, IDictionary<string, string> dict, IDictionary<string, string> methodDict) | ||
458 | + { | ||
459 | + var split = blockCode.Split('\n'); | ||
460 | + var varName = "VAL"; | ||
461 | + var methodName = "FUNC"; | ||
462 | + int varIdx = dict.Count(); | ||
463 | + int methodIdx = methodDict.Count(); | ||
464 | + | ||
465 | + var removes = Regex.Split(blockCode, Environment.NewLine, RegexOptions.Multiline); | ||
466 | + StringBuilder builder = new StringBuilder(); | ||
467 | + Console.ForegroundColor = ConsoleColor.DarkYellow; | ||
468 | + foreach (var item in removes) | ||
469 | + { | ||
470 | + if (string.IsNullOrWhiteSpace(item)) | ||
471 | + { | ||
472 | + continue; | ||
473 | + } | ||
474 | + Console.Write(item); | ||
475 | + builder.Append(item); | ||
476 | + // Console.ReadLine(); | ||
477 | + } | ||
478 | +// Console.WriteLine(builder.ToString()); | ||
479 | + Console.ResetColor(); | ||
480 | + foreach (var line in split) | ||
481 | + { | ||
482 | + var varList = ExtractMethodVariantList(line, skipDefine: false); | ||
483 | + if (varList == null) | ||
484 | + { | ||
485 | + continue; | ||
486 | + } | ||
487 | + foreach (var var in varList.Vars) | ||
488 | + { | ||
489 | + if (!dict.ContainsKey(var)) | ||
490 | + { | ||
491 | + dict[var] = varName + varIdx++; | ||
492 | + } | ||
493 | + } | ||
494 | + | ||
495 | + foreach (var m in varList.Methods) | ||
496 | + { | ||
497 | + if (!methodDict.ContainsKey(m)) | ||
498 | + { | ||
499 | + methodDict[m] = methodName + methodIdx++; | ||
500 | + } | ||
501 | + } | ||
502 | + | ||
503 | + } | ||
504 | + | ||
505 | + var sortVarDict = dict.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, p => p.Value); | ||
506 | + var sortMethodDict = methodDict.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, p => p.Value); | ||
507 | + | ||
508 | + string temp = blockCode; | ||
509 | + foreach (var pair in sortVarDict) | ||
510 | + { | ||
511 | + temp = Regex.Replace(temp, $@"\b{pair.Key}\b", pair.Value); | ||
512 | + } | ||
513 | + | ||
514 | + foreach (var pair in sortMethodDict) | ||
515 | + { | ||
516 | + temp = Regex.Replace(temp, $@"\b{pair.Key}\b", pair.Value); | ||
517 | + | ||
518 | + } | ||
519 | + temp = Regex.Replace(temp, @"\s", "", RegexOptions.Multiline); | ||
520 | + temp = Regex.Replace(temp, @"{|}|;|\)|\(", ""); | ||
521 | + temp = temp.ToUpper(); | ||
522 | + | ||
523 | + | ||
524 | + return temp; | ||
525 | + } | ||
462 | } | 526 | } |
463 | } | 527 | } | ... | ... |
... | @@ -75,5 +75,10 @@ namespace VulnCrawler | ... | @@ -75,5 +75,10 @@ namespace VulnCrawler |
75 | { | 75 | { |
76 | throw new NotImplementedException(); | 76 | throw new NotImplementedException(); |
77 | } | 77 | } |
78 | + | ||
79 | + public override string Abstract(string blockCode, IDictionary<string, string> dict, IDictionary<string, string> methodDict) | ||
80 | + { | ||
81 | + throw new NotImplementedException(); | ||
82 | + } | ||
78 | } | 83 | } |
79 | } | 84 | } | ... | ... |
... | @@ -41,16 +41,13 @@ namespace VulnCrawler | ... | @@ -41,16 +41,13 @@ namespace VulnCrawler |
41 | 41 | ||
42 | 42 | ||
43 | private static void PrintPatchEntrys(IEnumerable<PatchEntryChanges> entrys, VulnAbstractCrawler self, string commitMsg, string cve) { | 43 | private static void PrintPatchEntrys(IEnumerable<PatchEntryChanges> entrys, VulnAbstractCrawler self, string commitMsg, string cve) { |
44 | - | ||
45 | foreach (var entry in entrys) { | 44 | foreach (var entry in entrys) { |
46 | // 기존 소스코드 | 45 | // 기존 소스코드 |
47 | var oldOid = entry.OldOid; | 46 | var oldOid = entry.OldOid; |
48 | - | ||
49 | try | 47 | try |
50 | { | 48 | { |
51 | Blob oldBlob = self.Repository.Lookup<Blob>(oldOid); | 49 | Blob oldBlob = self.Repository.Lookup<Blob>(oldOid); |
52 | string oldContent = oldBlob.GetContentText(); | 50 | string oldContent = oldBlob.GetContentText(); |
53 | - | ||
54 | // 변경된 소스코드 | 51 | // 변경된 소스코드 |
55 | var newOid = entry.Oid; | 52 | var newOid = entry.Oid; |
56 | Blob newBlob = self.Repository.Lookup<Blob>(newOid); | 53 | Blob newBlob = self.Repository.Lookup<Blob>(newOid); |
... | @@ -116,6 +113,7 @@ namespace VulnCrawler | ... | @@ -116,6 +113,7 @@ namespace VulnCrawler |
116 | Console.WriteLine($"=====block({block.Num}, {block.HasCritical.ToString()})"); | 113 | Console.WriteLine($"=====block({block.Num}, {block.HasCritical.ToString()})"); |
117 | Console.WriteLine(block.Code); | 114 | Console.WriteLine(block.Code); |
118 | Console.ResetColor(); | 115 | Console.ResetColor(); |
116 | + Console.WriteLine($"AbsCode = \n{block.AbsCode}"); | ||
119 | Console.WriteLine($"MD5 = {block.Hash}"); | 117 | Console.WriteLine($"MD5 = {block.Hash}"); |
120 | } | 118 | } |
121 | 119 | ||
... | @@ -178,7 +176,7 @@ namespace VulnCrawler | ... | @@ -178,7 +176,7 @@ namespace VulnCrawler |
178 | catch (Exception e) | 176 | catch (Exception e) |
179 | { | 177 | { |
180 | // Console.WriteLine(entry.Patch); | 178 | // Console.WriteLine(entry.Patch); |
181 | - // Console.WriteLine(e.ToString()); | 179 | + // Console.WriteLine(e.ToString()); |
182 | // Console.ReadLine(); | 180 | // Console.ReadLine(); |
183 | continue; | 181 | continue; |
184 | } | 182 | } | ... | ... |
-
Please register or login to post a comment