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
aced7181
Commit
aced7181
authored
Oct 29, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
032ffa20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
7 deletions
+119
-7
python/tools/garble/java_garble.py
+78
-7
python/tools/garble/model/logic_string_model.java
+41
-0
No files found.
python/tools/garble/java_garble.py
View file @
aced7181
...
...
@@ -11,9 +11,8 @@ class JavaGarble:
def
__gen_rand_str
(
self
):
result
=
""
while
len
(
result
)
==
0
or
result
in
self
.
__used_names
:
r
andom_str
=
''
.
join
(
random
.
sample
(
r
esult
=
''
.
join
(
random
.
sample
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
,
random
.
randint
(
1
,
2
)))
result
=
"
%
s
%
d"
%
(
random_str
,
random
.
randint
(
1
,
100
))
self
.
__used_names
.
append
(
result
)
return
result
...
...
@@ -22,7 +21,7 @@ class JavaGarble:
def
__generate_variable
(
self
):
var_scope
=
[
"public"
,
"private"
,
"protected"
]
var_types
=
[
"String"
,
"int"
,
"double"
,
"float"
]
var_count
=
random
.
randint
(
3
,
20
)
var_count
=
random
.
randint
(
random
.
randint
(
3
,
10
),
random
.
randint
(
20
,
30
)
)
for
i
in
range
(
0
,
var_count
):
code
=
"
%
s
%
s
%
s = "
%
(
var_scope
[
random
.
randint
(
0
,
2
)],
...
...
@@ -36,6 +35,71 @@ class JavaGarble:
code
+=
";"
self
.
__variables
.
append
(
code
)
# 生成方法
def
__generate_function
(
self
,
model_path
):
func_scope
=
[
"public"
,
"private"
,
"protected"
]
return_type
=
[
"String"
,
"int"
,
"double"
,
"float"
]
fun_content
=
""
with
open
(
model_path
,
"r"
,
encoding
=
"utf-8"
)
as
fin
:
fun_content
=
fin
.
read
()
re_type
=
return_type
[
random
.
randint
(
0
,
3
)]
fun_content
=
fun_content
\
.
replace
(
"${func_scope}"
,
func_scope
[
random
.
randint
(
0
,
2
)])
\
.
replace
(
"${return_type}"
,
re_type
)
\
.
replace
(
"${func_name}"
,
self
.
__gen_rand_str
())
# 方法参数
param_names
=
[]
params_code
=
""
for
i
in
range
(
0
,
random
.
randint
(
1
,
5
)):
parans_name
=
self
.
__gen_rand_str
()
code
=
"
%
s
%
s"
%
(
return_type
[
random
.
randint
(
0
,
3
)],
parans_name
)
params_code
+=
code
+
", "
param_names
.
append
(
parans_name
)
params_code
=
(
"
%
s*"
%
params_code
)
.
replace
(
", *"
,
""
)
fun_content
=
fun_content
.
replace
(
"${params}"
,
params_code
)
# 随机引用全局变量
for
var_code
in
self
.
__variables
:
if
random
.
randint
(
0
,
2
)
%
2
==
0
:
param_names
.
append
(
var_code
.
split
(
" "
)[
2
])
return_value
=
""
for
name
in
param_names
:
return_value
+=
name
+
"+"
# 转string
return_value
+=
"
\"\"
"
if
re_type
in
"int"
:
return_value
=
"(
%
s).length()"
%
return_value
elif
re_type
in
"float"
:
return_value
=
"Float.valueOf((
%
s).length())"
%
return_value
elif
re_type
in
"double"
:
return_value
=
"Double.valueOf((
%
s).length())"
%
return_value
return_value
=
"return
%
s;"
%
return_value
log_code
=
""
for
i
in
range
(
0
,
random
.
randint
(
0
,
5
)):
log_code
+=
"Log.
%
s(
\"
%
s
\"
,
\"
%
s
\"
);
\n
"
%
(
''
.
join
(
random
.
sample
(
"idew"
,
random
.
randint
(
1
,
1
))),
self
.
__name
,
''
.
join
(
random
.
sample
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
,
random
.
randint
(
5
,
15
)))
)
fun_content
=
fun_content
.
replace
(
"${func_content}"
,
log_code
+
return_value
)
self
.
__functions
.
append
(
fun_content
)
if
len
(
self
.
__functions
)
<
random
.
randint
(
3
,
10
):
self
.
__generate_function
(
model_path
)
#插入代码
def
__garble_java_file
(
self
,
file
):
with
open
(
file
,
"r"
,
encoding
=
"utf-8"
)
as
fin
:
...
...
@@ -43,16 +107,23 @@ class JavaGarble:
#初始化全局变量
self
.
__generate_variable
()
ignore
=
False
with
open
(
file
,
"w+"
,
encoding
=
"utf-8"
)
as
fout
:
for
line
in
lines
:
# interface 不混淆
# if "interface" in line and "{\n" in line:
# fout.write(line)
# continue
if
"interface"
in
line
and
"{
\n
"
in
line
:
ignore
=
True
if
ignore
:
fout
.
write
(
line
)
continue
#class下插入全局变量
if
(
line
.
startswith
(
"class "
)
or
" class "
in
line
)
and
"{"
in
line
:
if
(
line
.
startswith
(
"class "
)
or
" class "
in
line
)
and
"{
\n
"
in
line
:
for
var
in
self
.
__variables
:
line
+=
"
%
s
\n
"
%
var
for
fun
in
self
.
__functions
:
line
+=
"
%
s
\n
"
%
fun
#只有一个缩进的方法,为类方法,可插入同级方法
# func_re = re.compile(r'\s{4}[a-zA-Z](.*)[)]\s{0,}[{]')
...
...
python/tools/garble/model/logic_string_model.java
0 → 100644
View file @
aced7181
android
.
util
.
Log
.
d
(
$
{
string
})
//---sep---
android
.
util
.
Log
.
e
(
$
{
string
})
//---sep---
android
.
util
.
Log
.
i
(
$
{
string
})
//---sep---
android
.
util
.
Log
.
v
(
$
{
string
})
//---sep---
while
(
$
{
condition
}){
$
{
content
}
}
//---sep---
for
(
$
{
condition
}){
$
{
content
}
}
//---sep---
if
(
int
$
{
name
};
$
{
condition
};
$
{
name
}++){
$
{
content
}
}
//---sep---
boolean
$
{
name
}
=
$
{
condition
}
if
(
$
{
name
}){
$
{
content
}
}
//---sep---
String
$
{
name
}
=
$
{
string
}
System
.
out
.
println
(
$
{
name
}+
$
{
string
});
//---sep---
float
$
{
name
}
=
$
{
number
}
while
((
int
)
$
{
name
}
<
(
$
{
name
}
-
1
)){
$
{
content
}
}
//---sep---
if
(
android
.
text
.
TextUtils
(
Build
.
BOARD
)){
$
{
content
}
}
//---sep---
if
(
Build
.
DEVICE
.
contains
(
$
{
string
})){
$
{
content
}
}
\ No newline at end of file
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