Toggle navigation
Toggle navigation
This project
Loading...
Sign in
노현종
/
2018-1-Capstone1-VulnNotti
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
노현종
2018-05-21 20:58:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
de278e84e64ecb86b349e74d347b1fcf5e52e8b9
de278e84
1 parent
13c7da23
크리티컬 블록 선정 수정중... 중괄호 기반이 아닌 syntax 기반
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
88 deletions
Vulnerablity_DB/VulnCrawler/VulnC.cs
Vulnerablity_DB/VulnCrawler/VulnC.cs
View file @
de278e8
...
...
@@ -240,126 +240,117 @@ namespace VulnCrawler
{
return
null
;
}
bool
hasIf
=
false
;
string
prevLine
=
string
.
Empty
;
bool
mainLine
=
true
;
/* 현재 라인이 메인 코드 라인인지 */
bool
criticalBlock
=
false
;
/* 현재 라인이 크리티컬 블록 라인인지 */
int
blockNum
=
1
;
/* 블록 번호 */
bool
group
=
false
;
Queue
<
string
>
groupQ
=
new
Queue
<
string
>();
var
mainQ
=
new
Queue
<
string
>();
foreach
(
var
line
in
split
)
{
bool
hasRight
=
false
;
bool
hasIf2
=
false
;
string
trim
=
line
.
Trim
();
/* 중괄호 수 세기 */
int
openBracketCount
=
trim
.
Count
(
c
=>
c
==
'{'
);
int
closeBracketCount
=
trim
.
Count
(
c
=>
c
==
'}'
);
bool
criticalBlock
=
false
;
/* 현재 라인이 크리티컬 블록 라인인지 */
int
subtract
=
openBracketCount
-
closeBracketCount
;
bracketCount
+=
subtract
;
string
trim
=
line
.
Trim
();
if
(
trim
.
Equals
(
"}"
))
if
(
Regex
.
IsMatch
(
trim
,
@"^(if|for|while)"
))
{
builder
.
AppendLine
(
line
);
hasRight
=
true
;
group
=
true
;
mainLine
=
false
;
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"{"
))
{
group
=
true
;
}
else
if
(
trim
.
EndsWith
(
"}"
))
{
group
=
false
;
}
else
if
(
trim
.
EndsWith
(
";"
))
{
group
=
false
;
}
continue
;
}
/* 중괄호 연산 결과 1이라는 것은 메인 라인 */
if
(
bracketCount
==
1
)
if
(
group
)
{
if
(!
hasIf
)
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"}"
))
{
if
(
Regex
.
IsMatch
(
trim
,
@"^(if|for|while).+\)$"
))
{
prevLine
=
line
;
hasIf
=
true
;
}
group
=
false
;
}
else
else
if
(
trim
.
EndsWith
(
";"
))
{
if
(!
trim
.
StartsWith
(
"{"
))
{
hasIf2
=
true
;
builder
.
AppendLine
(
line
);
}
hasIf
=
false
;
group
=
false
;
}
/*
* 깊이가 1인데 mainLine이
* false 이면 넘어왔다는 것이니 현재까지 코드
* blockList에 추가
*/
if
(!
mainLine
||
hasIf2
)
continue
;
}
mainQ
.
Enqueue
(
line
);
StringBuilder
mainBuilder
=
new
StringBuilder
();
if
(!
mainLine
)
{
while
(
mainQ
.
Count
>
0
)
{
string
s
=
builder
.
ToString
();
if
(!
string
.
IsNullOrWhiteSpace
(
s
)
)
string
s
=
mainQ
.
Dequeue
();
if
(!
criticalBlock
)
{
blockList
.
Add
(
new
Block
()
{
HasCritical
=
criticalBlock
,
Code
=
s
,
Num
=
blockNum
});
blockNum
++;
criticalBlock
=
false
;
builder
.
Clear
();
foreach
(
var
var
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
var
))
{
criticalBlock
=
true
;
break
;
}
}
}
mainBuilder
.
AppendLine
(
s
);
}
if
(
mainBuilder
.
Length
>
0
)
{
blockList
.
Add
(
new
Block
{
Code
=
mainBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
});
//continue;
}
mainLine
=
true
;
}
/* 2 이상이라는 건 메인 라인 X */
else
if
(
bracketCount
>=
2
)
StringBuilder
groupBuilder
=
new
StringBuilder
();
while
(
groupQ
.
Count
>
0
)
{
/*
* 깊이가 2 이상인데 mainLine이
* true면 넘어왔다는 것이니 현재까지 코드
* blockList에 추가
*/
if
(
mainLine
)
var
s
=
groupQ
.
Dequeue
();
if
(!
criticalBlock
)
{
string
s
=
builder
.
ToString
();
if
(!
string
.
IsNullOrWhiteSpace
(
s
))
foreach
(
var
var
in
ExtractCriticalVariant
(
s
))
{
blockList
.
Add
(
new
Block
()
{
HasCritical
=
criticalBlock
,
Code
=
s
,
Num
=
blockNum
});
blockNum
++;
criticalBlock
=
false
;
builder
.
Clear
();
if
(
crList
.
Contains
(
var
))
{
criticalBlock
=
true
;
break
;
}
}
}
mainLine
=
false
;
groupBuilder
.
AppendLine
(
s
)
;
}
/* 이도 저도 아니면 그냥 넘어감 */
else
if
(
groupBuilder
.
Length
>
0
)
{
blockList
.
Add
(
new
Block
{
Code
=
groupBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
});
continue
;
}
/* 현재 코드 라인에서 변수 추출시켜서 크리티컬 리스트와 대조 */
foreach
(
var
var
in
ExtractCriticalVariant
(
line
))
{
/* 크리티컬 리스트에 추출한 변수가 들어있다면 추가 */
if
(
criticalList
.
Contains
(
var
))
{
criticalBlock
=
true
;
break
;
}
}
if
(!
hasRight
&&
!
hasIf2
)
{
builder
.
AppendLine
(
line
);
}
}
/* 마지막 남은게 있을 수 있으니 추가 */
string
fs
=
builder
.
ToString
();
if
(!
string
.
IsNullOrWhiteSpace
(
fs
))
{
blockList
.
Add
(
new
Block
()
{
HasCritical
=
criticalBlock
,
Code
=
fs
,
Num
=
blockNum
});
blockNum
++;
criticalBlock
=
false
;
builder
.
Clear
();
mainLine
=
true
;
}
Console
.
WriteLine
(
"끝"
);
return
blockList
;
}
}
...
...
Please
register
or
login
to post a comment