노현종

0503

...@@ -10,21 +10,62 @@ namespace VulnCrawler ...@@ -10,21 +10,62 @@ namespace VulnCrawler
10 { 10 {
11 public class VulnC : VulnAbstractCrawler 11 public class VulnC : VulnAbstractCrawler
12 { 12 {
13 + protected override string RegexFuncPattern => $@"@@ \-(?<{OldStart}>\d+),(?<{OldLines}>\d+) \+(?<{NewStart}>\d+),(?<{NewLines}>\d+) @@ (?<{MethodName}>.+)";
13 14
14 - protected override string RegexFuncPattern => throw new NotImplementedException(); 15 + protected override string Extension => ".c";
15 -
16 - protected override string Extension => throw new NotImplementedException();
17 16
18 public override MatchCollection GetMatches(string patchCode) { 17 public override MatchCollection GetMatches(string patchCode) {
19 - throw new NotImplementedException(); 18 + var regs = Regex.Matches(patchCode, RegexFuncPattern);
19 + return regs;
20 } 20 }
21 21
22 public override string RemoveComment(string original) { 22 public override string RemoveComment(string original) {
23 - throw new NotImplementedException(); 23 + string txt = Regex.Replace(original, Environment.NewLine, "");
24 +
25 + //StringBuilder sb = new StringBuilder();
26 + //sb.Append("\"\"\"");
27 + //sb.Append(@".*");
28 + //sb.Append("\"\"\"");
29 + //string replace = txt;
30 + //if (Regex.Match(txt, sb.ToString()).Success) {
31 + // replace = Regex.Replace(txt, sb.ToString(), "");
32 + //}
33 + return replace;
24 } 34 }
25 35
26 protected override string GetOriginalFunc(Stream oldStream, string methodName) { 36 protected override string GetOriginalFunc(Stream oldStream, string methodName) {
27 - throw new NotImplementedException(); 37 + StringBuilder oldBuilder = new StringBuilder();
38 + using (var reader = new StreamReader(oldStream)) {
39 + int defSpace = 0;
40 + while (!reader.EndOfStream) {
41 +
42 + string line = reader.ReadLine();
43 + if (defSpace > 0) {
44 + if (line.Length < defSpace) {
45 + continue;
46 + }
47 + string concat = line.Substring(0, defSpace);
48 + if (string.IsNullOrWhiteSpace(concat)) {
49 + string trim = line.Trim();
50 + // #으로 시작한다면 주석이니 제거
51 + if (trim.StartsWith("#")) {
52 + continue;
53 + }
54 + oldBuilder.AppendLine(line);
55 + } else {
56 + continue;
57 + }
58 + }
59 + if (Regex.Match(line, $@"{methodName}").Success) {
60 +
61 + defSpace = line.IndexOf(methodName);
62 + oldBuilder.AppendLine(line);
63 + }
64 +
65 + }
66 +
67 + }
68 + return oldBuilder.ToString();
28 } 69 }
29 } 70 }
30 } 71 }
......