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
301fb419
Commit
301fb419
authored
Oct 30, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
3a0e61cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
31 deletions
+50
-31
python/tools/garble/java_garble.py
+37
-14
python/tools/garble/model/logic_model.java
+13
-17
No files found.
python/tools/garble/java_garble.py
View file @
301fb419
...
...
@@ -18,8 +18,8 @@ class JavaGarble:
self
.
__used_names
.
append
(
result
)
return
result
# 生成方法
def
__generate_function
(
self
,
model_path
):
func_scope
=
[
"public"
,
"private"
,
"protected"
]
return_type
=
[
"String"
,
"int"
,
"double"
,
"float"
]
...
...
@@ -88,13 +88,39 @@ class JavaGarble:
# 插入代码
def
__insert_code
(
self
):
codes
=
self
.
__logic_model
.
split
(
"@---sep---
\n
"
)
# code = codes[random.randint(0, len(codes)-1)]
# code = code.replace("${string}", self.__gen_rand_str())\
# .replace("${name}", self.__gen_rand_str())\
# .replace("${number}", str(random.randint(1, 10000)))
return
""
insert_code
=
""
codes
=
self
.
__logic_model
.
split
(
"@code
\n
"
)
# 选择一个变量
vars
=
codes
[
0
]
.
replace
(
"
\n
"
,
""
)
.
split
(
"*"
)
index
=
random
.
randint
(
0
,
len
(
vars
)
-
1
)
# 选择一段逻辑代码
models
=
codes
[
2
]
.
split
(
"@---sep---
\n
"
)
insert_code
+=
models
[
random
.
randint
(
0
,
len
(
models
)
-
1
)]
# 选择一个判断条件
condition
=
codes
[
1
]
.
replace
(
"
\n
"
,
""
)
.
split
(
"*"
)[
index
]
insert_code
=
insert_code
.
replace
(
"${vars}"
,
vars
[
index
])
\
.
replace
(
"${condition}"
,
condition
)
insert_code
=
insert_code
.
replace
(
"${string1}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${string2}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${string3}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${string4}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${string5}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${number1}"
,
str
(
random
.
randint
(
1
,
10000
)))
\
.
replace
(
"${number2}"
,
str
(
random
.
randint
(
1
,
10000
)))
\
.
replace
(
"${number3}"
,
str
(
random
.
randint
(
1
,
10000
)))
\
.
replace
(
"${number4}"
,
str
(
random
.
randint
(
1
,
10000
)))
\
.
replace
(
"${number5}"
,
str
(
random
.
randint
(
1
,
10000
)))
\
.
replace
(
"${name1}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${name2}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${name3}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${name4}"
,
self
.
__gen_rand_str
())
\
.
replace
(
"${name5}"
,
self
.
__gen_rand_str
())
\
return
insert_code
def
__garble_java_file
(
self
,
file
):
self
.
__used_names
=
[]
...
...
@@ -125,14 +151,11 @@ class JavaGarble:
for
fun
in
self
.
__functions
:
line
+=
"
%
s
\n
"
%
fun
# 定位1个缩进开头的类方法
if
(
line
.
startswith
(
" "
)
and
not
line
.
startswith
(
" "
))
and
(
"){
\n
"
in
line
or
") {
\n
"
in
line
):
curly_braces
=
line
.
count
(
"{"
)
curly_braces
-=
line
.
count
(
"}"
)
if
curly_braces
>=
1
:
curly_braces
+=
line
.
count
(
"{"
)
curly_braces
-=
line
.
count
(
"}"
)
...
...
@@ -147,10 +170,10 @@ class JavaGarble:
def
java_garble
(
self
,
config
):
self
.
__config
=
config
with
open
(
"tools/garble/model/logic_model.java"
,
"r"
,
encoding
=
"utf-8"
)
as
fin
:
self
.
__logic_model
=
fin
.
read
()
self
.
__logic_model
=
fin
.
read
()
.
replace
(
"
\n\n
"
,
"
\n
"
)
.
replace
(
"
\n\n
"
,
"
\n
"
)
for
main_dir
in
config
[
'lib_main'
]:
for
root
,
dirs
,
files
in
os
.
walk
(
"
%
s/
%
s"
%
(
config
[
"root"
],
main_dir
)):
for
file
in
files
:
if
file
.
endswith
(
"
HomeActicity
.java"
):
if
file
.
endswith
(
".java"
):
self
.
__garble_java_file
(
os
.
path
.
join
(
root
,
file
))
python/tools/garble/model/logic_model.java
View file @
301fb419
@var
String
$
{
name1
}
=
"${string1}"
;
int
$
{
name1
}
=
$
{
number1
};
float
$
{
name1
}
=
$
{
number1
};
double
$
{
name1
}
=
$
{
number1
};
String
$
{
name1
}
=
"${string1}"
;*
int
$
{
name1
}
=
$
{
number1
};*
float
$
{
name1
}
=
$
{
number1
};*
double
$
{
name1
}
=
$
{
number1
};*
long
$
{
name1
}
=
$
{
number1
};
@var
@co
ndition
$
{
name1
}.
contains
(
"${string1}${string1}"
)
$
{
name1
}
>
$
{
number1
}
$
{
name1
}
<
$
{
number1
}
$
{
name1
}
==
$
{
number1
}
+
$
{
number1
}
@condition
@co
de
$
{
name1
}.
contains
(
"${string1}${string1}"
)
*
$
{
name1
}
>
$
{
number1
}
*
$
{
name1
}
<
$
{
number1
}
*
$
{
name1
}
==
$
{
number1
}
+
$
{
number1
}
*
$
{
name1
}
<=
$
{
number1
}
-
$
{
number1
}
@code
android
.
util
.
Log
.
d
(
"${name1}"
,
"${name2}"
);
...
...
@@ -41,7 +38,7 @@ if(${condition}){
@
---
sep
---
$
{
vars
}
boolean
$
{
name2
}
=
$
{
condition
};
if
(
$
{
name
}){
if
(
$
{
name
1
}){
System
.
out
.
println
(
$
{
name1
}
+
"${string2}"
);
}
@
---
sep
---
...
...
@@ -59,5 +56,4 @@ if(android.text.TextUtils.isEmpty(android.os.Build.BOARD)){
@
---
sep
---
if
(
android
.
os
.
Build
.
DEVICE
.
equals
(
"${string1}"
)){
System
.
out
.
println
(
"${string2}"
);
}
@code
\ No newline at end of file
}
\ 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