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 기반
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
80 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
;
bool
criticalBlock
=
false
;
/* 현재 라인이 크리티컬 블록 라인인지 */
string
trim
=
line
.
Trim
();
/* 중괄호 수 세기 */
int
openBracketCount
=
trim
.
Count
(
c
=>
c
==
'{'
);
int
closeBracketCount
=
trim
.
Count
(
c
=>
c
==
'}'
);
int
subtract
=
openBracketCount
-
closeBracketCount
;
bracketCount
+=
subtract
;
if
(
trim
.
Equals
(
"}"
))
if
(
Regex
.
IsMatch
(
trim
,
@"^(if|for|while)"
))
{
builder
.
AppendLine
(
line
);
hasRight
=
true
;
}
/* 중괄호 연산 결과 1이라는 것은 메인 라인 */
if
(
bracketCount
==
1
)
{
if
(!
hasIf
)
{
if
(
Regex
.
IsMatch
(
trim
,
@"^(if|for|while).+\)$"
))
group
=
true
;
mainLine
=
false
;
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"{"
))
{
prevLine
=
line
;
hasIf
=
true
;
group
=
true
;
}
}
else
else
if
(
trim
.
EndsWith
(
"}"
))
{
if
(!
trim
.
StartsWith
(
"{"
))
group
=
false
;
}
else
if
(
trim
.
EndsWith
(
";"
))
{
hasIf2
=
true
;
builder
.
AppendLine
(
line
);
group
=
false
;
}
hasIf
=
fals
e
;
continu
e
;
}
/*
* 깊이가 1인데 mainLine이
* false 이면 넘어왔다는 것이니 현재까지 코드
* blockList에 추가
*/
if
(!
mainLine
||
hasIf2
)
if
(
group
)
{
string
s
=
builder
.
ToString
(
);
if
(!
string
.
IsNullOrWhiteSpace
(
s
))
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"}"
))
{
blockList
.
Add
(
new
Block
()
{
HasCritical
=
criticalBlock
,
Code
=
s
,
Num
=
blockNum
});
blockNum
++;
criticalBlock
=
false
;
builder
.
Clear
();
group
=
false
;
}
else
if
(
trim
.
EndsWith
(
";"
))
{
group
=
false
;
}
mainLine
=
tr
ue
;
contin
ue
;
}
/* 2 이상이라는 건 메인 라인 X */
else
if
(
bracketCount
>=
2
)
mainQ
.
Enqueue
(
line
);
StringBuilder
mainBuilder
=
new
StringBuilder
();
if
(!
mainLine
)
{
/*
* 깊이가 2 이상인데 mainLine이
* true면 넘어왔다는 것이니 현재까지 코드
* blockList에 추가
*/
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
;
}
}
mainLine
=
false
;
}
/* 이도 저도 아니면 그냥 넘어감 */
else
mainBuilder
.
AppendLine
(
s
);
}
if
(
mainBuilder
.
Length
>
0
)
{
continue
;
blockList
.
Add
(
new
Block
{
Code
=
mainBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
});
//continue;
}
}
/* 현재 코드 라인에서 변수 추출시켜서 크리티컬 리스트와 대조 */
foreach
(
var
var
in
ExtractCriticalVariant
(
line
))
StringBuilder
groupBuilder
=
new
StringBuilder
();
while
(
groupQ
.
Count
>
0
)
{
var
s
=
groupQ
.
Dequeue
();
if
(!
criticalBlock
)
{
/* 크리티컬 리스트에 추출한 변수가 들어있다면 추가 */
if
(
criticalList
.
Contains
(
var
))
foreach
(
var
var
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
var
))
{
criticalBlock
=
true
;
break
;
}
}
if
(!
hasRight
&&
!
hasIf2
)
}
groupBuilder
.
AppendLine
(
s
);
}
if
(
groupBuilder
.
Length
>
0
)
{
b
uilder
.
AppendLine
(
line
);
b
lockList
.
Add
(
new
Block
{
Code
=
groupBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
}
);
continue
;
}
}
/* 마지막 남은게 있을 수 있으니 추가 */
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