Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
18778624
Commit
18778624
authored
Mar 29, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update script
parent
c9e37c37
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
22 deletions
+72
-22
script/garble/insert.py
+72
-22
No files found.
script/garble/insert.py
View file @
18778624
...
@@ -15,55 +15,105 @@ def gen_rand_str():
...
@@ -15,55 +15,105 @@ def gen_rand_str():
rand_str
=
''
.
join
(
random
.
choices
(
string
.
ascii_uppercase
+
string
.
ascii_lowercase
,
k
=
8
))
rand_str
=
''
.
join
(
random
.
choices
(
string
.
ascii_uppercase
+
string
.
ascii_lowercase
,
k
=
8
))
used_names
.
append
(
rand_str
)
used_names
.
append
(
rand_str
)
return
rand_str
return
rand_str
+
str
(
random
.
randint
(
0
,
1000
))
def
get_rand_code
():
def
get_rand_code
(
isInFunc
):
indentasi
=
random
.
randint
(
0
,
5
);
indentasi
=
random
.
randint
(
0
,
5
);
indentasiStr
=
""
indentasiStr
=
""
for
num
in
range
(
0
,
indentasi
):
for
num
in
range
(
0
,
indentasi
):
indentasiStr
+=
"
\t
"
indentasiStr
+=
"
\t
"
#随机缩进
#
随机缩进
num
=
random
.
randint
(
0
,
4
);
num
=
random
.
randint
(
0
,
4
);
code
=
";
\n
//-------"
+
str
(
num
)
+
"-------
\n
"
code
=
";
\n
"
#随机代码
filedName
=
gen_rand_str
()
# 随机代码
if
num
==
0
:
if
num
==
0
:
code
+=
indentasiStr
+
"String "
+
gen_rand_str
()
+
"=
\"
"
+
gen_rand_str
()
+
"
\"
;
\n
"
code
+=
indentasiStr
+
"String "
+
filedName
+
"=
\"
"
+
gen_rand_str
()
+
"
\"
;
\n
"
elif
num
==
1
:
elif
num
==
1
:
code
+=
indentasiStr
+
"int "
+
gen_rand_str
()
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
code
+=
indentasiStr
+
"int "
+
filedName
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
elif
num
==
2
:
elif
num
==
2
:
code
+=
indentasiStr
+
"float "
+
gen_rand_str
()
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
code
+=
indentasiStr
+
"float "
+
filedName
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
elif
num
==
3
:
elif
num
==
3
:
code
+=
indentasiStr
+
"double "
+
gen_rand_str
()
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
code
+=
indentasiStr
+
"double "
+
filedName
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
elif
num
==
4
:
elif
num
==
4
:
code
+=
indentasiStr
+
"long "
+
gen_rand_str
()
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
code
+=
indentasiStr
+
"long "
+
filedName
+
"="
+
str
(
random
.
randint
(
0
,
100000
))
+
";
\n
"
# elif num == 2:
# code += ";\nif(\"" + gen_rand_str() + "\".equals(\"" + gen_rand_str() + "\")){}\n"
# if isInFunc:
# elif num == 3:
# if num == 0:
# index = gen_rand_str()
# code += "if(\"" + filedName + "\".equals(\"" + gen_rand_str() + "\")){}//interference code\n"
# code += ";\nfor(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+str(random.randint(11,20))+";"+index+"++){}\n"
# else:
# index = gen_rand_str()
# code += "for(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+filedName+";"+index+"++){}//interference code\n"
return
code
return
code
def
process_file_content
(
path
,
file_name
):
def
process_file_content
(
path
,
file_name
):
print
(
"processing content:
%
s..."
%
path
)
#
print("processing content: %s..." % path)
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
# readlines以列表的形式将文件读出
# readlines以列表的形式将文件读出
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
with
open
(
path
,
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
with
open
(
path
,
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
isReturn
=
False
isErrorIf
=
False
func_level
=
0
for
line
in
lines
:
for
line
in
lines
:
if
";
\n
"
in
line
and
"return"
not
in
line
and
"break"
not
in
line
and
"continue"
not
in
line
and
"import"
not
in
line
and
"package"
not
in
line
:
#没加{}的if else
if
(
"if("
in
line
or
"if ("
in
line
)
and
"{"
not
in
line
:
isErrorIf
=
True
#return后有多行代码
if
"return"
in
line
or
"throw"
in
line
:
isReturn
=
True
func_level
=
0
if
isReturn
:
if
"{"
in
line
:
func_level
+=
1
elif
"}"
in
line
:
func_level
-=
1
if
func_level
<
0
:
func_level
=
0
# if "//interference code" not in line and ")" in line and "{\n" in line and func_level == 0:
# func_level = 1
# elif "//interference code" not in line and "{\n" in line:
# func_level +=1
#
# if "//interference code" not in line and "}\n" in line:
# func_level -=1
#需要忽略的行
if
not
isReturn
and
not
isErrorIf
and
\
";
\n
"
in
line
and
\
"return"
not
in
line
and
\
"break"
not
in
line
and
\
"continue"
not
in
line
and
\
"import"
not
in
line
and
\
"package"
not
in
line
and
\
"throw"
not
in
line
and
\
"};"
not
in
line
and
\
"});"
not
in
line
and
\
"//"
not
in
line
:
if
random
.
randint
(
0
,
20
)
%
2
==
0
:
if
random
.
randint
(
0
,
20
)
%
2
==
0
:
line
=
line
.
replace
(
";
\n
"
,
get_rand_code
())
line
=
line
.
replace
(
";
\n
"
,
get_rand_code
(
func_level
>
0
))
if
";"
in
line
:
isErrorIf
=
False
if
";
\n
"
in
line
and
func_level
==
0
:
isReturn
=
False
f_w
.
write
(
line
)
f_w
.
write
(
line
)
print
(
"done
\n
"
)
#
print("done\n")
return
return
# perform content replace for the files
# perform content replace for the files
for
root
,
dirs
,
files
in
os
.
walk
(
"../../../app/src/main"
):
for
root
,
dirs
,
files
in
os
.
walk
(
"../../../app/src/main"
):
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment