Showing
4 changed files
with
68 additions
and
55 deletions
1 | -auto | ||
2 | -bool | ||
3 | -break | ||
4 | -case | ||
5 | -char | ||
6 | -const | ||
7 | -continue | ||
8 | -default | ||
9 | -defined | ||
10 | -do | ||
11 | -double | ||
12 | -else | ||
13 | -enum | ||
14 | -extern | ||
15 | -float | ||
16 | -for | ||
17 | -goto | ||
18 | -if | ||
19 | -int | ||
20 | -long | ||
21 | -register | ||
22 | -return | ||
23 | -short | ||
24 | -signed | ||
25 | -sizeof | ||
26 | -static | ||
27 | -struct | ||
28 | -switch | ||
29 | -typedef | ||
30 | -union | ||
31 | -unsigned | ||
32 | -void | ||
33 | -volatile | ||
34 | -while | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -69,7 +69,7 @@ namespace VulnCrawler | ... | @@ -69,7 +69,7 @@ namespace VulnCrawler |
69 | 69 | ||
70 | // var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)"); | 70 | // var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)"); |
71 | var c = new VulnC(); | 71 | var c = new VulnC(); |
72 | - var fields = c.GetCriticalVariant(@"if(i + inl < bl) {"); | 72 | + var fields = c.GetCriticalVariant(@"cs64_chunk.chunkSize64 = 12345678;"); |
73 | foreach (var item in fields) | 73 | foreach (var item in fields) |
74 | { | 74 | { |
75 | Console.WriteLine(item); | 75 | Console.WriteLine(item); | ... | ... |
... | @@ -46,13 +46,14 @@ namespace VulnCrawler | ... | @@ -46,13 +46,14 @@ namespace VulnCrawler |
46 | var lines = File.ReadLines(ReservedFileName, Encoding.Default); | 46 | var lines = File.ReadLines(ReservedFileName, Encoding.Default); |
47 | foreach (var item in lines) | 47 | foreach (var item in lines) |
48 | { | 48 | { |
49 | + | ||
49 | if (string.IsNullOrWhiteSpace(item)) | 50 | if (string.IsNullOrWhiteSpace(item)) |
50 | { | 51 | { |
51 | continue; | 52 | continue; |
52 | } | 53 | } |
53 | ReservedList.Add(item); | 54 | ReservedList.Add(item); |
55 | + | ||
54 | } | 56 | } |
55 | - | ||
56 | } | 57 | } |
57 | catch(FileNotFoundException) | 58 | catch(FileNotFoundException) |
58 | { | 59 | { |
... | @@ -169,13 +170,36 @@ namespace VulnCrawler | ... | @@ -169,13 +170,36 @@ namespace VulnCrawler |
169 | /// <returns></returns> | 170 | /// <returns></returns> |
170 | public IEnumerable<string> GetCriticalVariant(string line) | 171 | public IEnumerable<string> GetCriticalVariant(string line) |
171 | { | 172 | { |
172 | - | 173 | + line = line.Trim(); |
174 | + if (line.StartsWith("//")) | ||
175 | + { | ||
176 | + yield break; | ||
177 | + } | ||
178 | + string declarePattern = @"(?<Declare>[a-zA-Z0-9_\.]+) [a-zA-Z0-9_\.]+ ="; | ||
173 | // 메서드 정규식 패턴 | 179 | // 메서드 정규식 패턴 |
174 | - string methodPattern = @"(\w+)\("; | 180 | + string methodPattern = @"(\w+)\s*\("; |
175 | // 변수 정규식 패턴 | 181 | // 변수 정규식 패턴 |
176 | - string fieldPattern = @"\w+"; | 182 | + string fieldPattern = @"^*?[a-zA-Z0-9_\.]+"; |
183 | + | ||
184 | + string invalidPattern = @"^[\d\.]+"; | ||
185 | + | ||
186 | + string commentPattern = @"("".*"")"; | ||
187 | + | ||
188 | + line = Regex.Replace(line, commentPattern, ""); | ||
177 | // 메서드 목록 | 189 | // 메서드 목록 |
178 | var methodSets = new HashSet<string>(); | 190 | var methodSets = new HashSet<string>(); |
191 | + | ||
192 | + // 선언 타입명 추출 | ||
193 | + var declareMatch = Regex.Match(line, declarePattern); | ||
194 | + string declareName = string.Empty; | ||
195 | + if (declareMatch.Success) | ||
196 | + { | ||
197 | + declareName = declareMatch.Groups["Declare"]?.Value ?? string.Empty; | ||
198 | + | ||
199 | + } | ||
200 | + //Console.WriteLine($"선언 : {declareName}"); | ||
201 | + | ||
202 | + | ||
179 | var methods = Regex.Matches(line, methodPattern); | 203 | var methods = Regex.Matches(line, methodPattern); |
180 | // 현재 코드 라인에서 메서드 목록 추가 | 204 | // 현재 코드 라인에서 메서드 목록 추가 |
181 | foreach (var met in methods) | 205 | foreach (var met in methods) |
... | @@ -188,24 +212,37 @@ namespace VulnCrawler | ... | @@ -188,24 +212,37 @@ namespace VulnCrawler |
188 | } | 212 | } |
189 | } | 213 | } |
190 | Console.WriteLine("----"); | 214 | Console.WriteLine("----"); |
191 | - var vars = Regex.Matches(line, fieldPattern); | 215 | + var vars = Regex.Matches(line, fieldPattern) |
192 | - // 변수 목록에서 메서드 목록에 있는 것 제외하고 반환 | 216 | + .Cast<Match>() |
217 | + .Where(m => { | ||
218 | + if (m.Value.Equals(declareName)) | ||
219 | + { | ||
220 | + return false; | ||
221 | + } | ||
222 | + /* 제일 앞자리가 숫자로 시작하면 넘어감 */ | ||
223 | + if (Regex.IsMatch(m.Value, invalidPattern)) | ||
224 | + { | ||
225 | + return false; | ||
226 | + } | ||
227 | + /* 전 단계에서 구한 메서드 목록에 있으면 넘어감 */ | ||
228 | + if (methodSets.Contains(m.Value)) | ||
229 | + { | ||
230 | + return false; | ||
231 | + } | ||
232 | + /* 예약어 목록에 있으면 넘어감 */ | ||
233 | + if (ReservedList.Contains(m.Value)) | ||
234 | + { | ||
235 | + return false; | ||
236 | + } | ||
237 | + return true; | ||
238 | + }) | ||
239 | + .Distinct(new MatchComparer()); | ||
240 | + | ||
193 | foreach (var x in vars) | 241 | foreach (var x in vars) |
194 | { | 242 | { |
195 | var field = x as Match; | 243 | var field = x as Match; |
196 | if (field.Success) | 244 | if (field.Success) |
197 | { | 245 | { |
198 | - /* 전 단계에서 구한 메서드 목록에 있으면 넘어감 */ | ||
199 | - if (methodSets.Contains(field.Value)) | ||
200 | - { | ||
201 | - continue; | ||
202 | - } | ||
203 | - /* 예약어 목록에 있으면 넘어감 */ | ||
204 | - if (ReservedList.Contains(field.Value)) | ||
205 | - { | ||
206 | - continue; | ||
207 | - } | ||
208 | - | ||
209 | yield return field.Value; | 246 | yield return field.Value; |
210 | } | 247 | } |
211 | } | 248 | } |
... | @@ -227,4 +264,17 @@ namespace VulnCrawler | ... | @@ -227,4 +264,17 @@ namespace VulnCrawler |
227 | } | 264 | } |
228 | 265 | ||
229 | } | 266 | } |
267 | + | ||
268 | + class MatchComparer : IEqualityComparer<Match> | ||
269 | + { | ||
270 | + public bool Equals(Match x, Match y) | ||
271 | + { | ||
272 | + return x.Value.Equals(y.Value); | ||
273 | + } | ||
274 | + | ||
275 | + public int GetHashCode(Match obj) | ||
276 | + { | ||
277 | + return obj.Value.GetHashCode(); | ||
278 | + } | ||
279 | + } | ||
230 | } | 280 | } | ... | ... |
... | @@ -66,9 +66,6 @@ | ... | @@ -66,9 +66,6 @@ |
66 | <None Include="App.config" /> | 66 | <None Include="App.config" /> |
67 | <None Include="packages.config" /> | 67 | <None Include="packages.config" /> |
68 | </ItemGroup> | 68 | </ItemGroup> |
69 | - <ItemGroup> | ||
70 | - <Content Include="CReserved.txt" /> | ||
71 | - </ItemGroup> | ||
72 | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | 69 | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
73 | <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | 70 | <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
74 | <PropertyGroup> | 71 | <PropertyGroup> | ... | ... |
-
Please register or login to post a comment