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
30a35098
Commit
30a35098
authored
Oct 29, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
b2c5d501
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
5 deletions
+57
-5
python/main.py
+6
-0
python/tools/garble/java_garble.py
+50
-4
python/tools/garble/manifest_grable.py
+1
-1
No files found.
python/main.py
View file @
30a35098
...
...
@@ -8,6 +8,7 @@ from tools.garble.package_garble import PackageGarble
from
tools.garble.manifest_grable
import
ManifestGarble
from
tools.garble.img_garble
import
ImageGarble
from
tools.sdk_manager
import
SdkManager
from
tools.garble.java_garble
import
JavaGarble
import
os
import
shutil
import
json
...
...
@@ -52,8 +53,10 @@ print("20、插入Activity")
print
(
"21、reset project"
)
print
(
"22、加固"
)
print
(
"23、插入混淆图片"
)
print
(
"24、插入混淆代码"
)
print
(
"26、启用/禁用代码"
)
command
=
int
(
input
(
"请输入指令编号:"
))
# 命令
...
...
@@ -152,5 +155,8 @@ elif command == 22:
elif
command
==
23
:
ImageGarble
()
.
img_garble
(
config
)
elif
command
==
24
:
JavaGarble
()
.
java_garble
(
config
)
elif
command
==
26
:
SdkManager
()
.
sdk_manage
(
config
)
python/tools/garble/java_garble.py
View file @
30a35098
# -*-coding:utf-8-*-
import
random
import
re
import
os
class
JavaGarble
:
__used_names
=
[]
__variables
=
[]
__functions
=
[]
def
__gen_rand_str
(
self
):
result
=
""
...
...
@@ -13,16 +17,58 @@ class JavaGarble:
self
.
__used_names
.
append
(
result
)
return
result
# 生成变量
def
__generate_variable
(
self
):
var_scope
=
[
"public"
,
"private"
,
"protected"
]
var_types
=
[
"String"
,
"int"
,
"double"
,
"float"
]
var_count
=
random
.
randint
(
3
,
20
)
for
i
in
range
(
0
,
var_count
):
code
=
"
%
s
%
s
%
s = "
%
(
var_scope
[
random
.
randint
(
0
,
2
)],
var_types
[
random
.
randint
(
0
,
3
)],
self
.
__gen_rand_str
()
)
if
" String "
in
code
:
code
+=
"
\"
%
s
\"
"
%
self
.
__gen_rand_str
()
else
:
code
+=
"
%
d"
%
random
.
randint
(
1
,
1000
)
code
+=
";"
self
.
__variables
.
append
(
code
)
#插入代码
def
__garble_java_file
(
self
,
file
):
with
open
(
file
,
"r"
,
encoding
=
"utf-8"
)
as
fin
:
lines
=
fin
.
readlines
()
with
open
(
file
,
"w+"
,
encoding
=
"utf-8"
)
as
fout
:
for
line
in
lines
:
#interface 不混淆
#
interface 不混淆
if
"interface"
in
line
and
"{
\n
"
in
line
:
fout
.
write
(
line
)
continue
#初始化全局变量
self
.
__generate_variable
()
#class下插入全局变量
if
" class "
in
line
and
"{
\n
"
in
line
:
class_re
=
re
.
compile
(
r'\s{0,}class(.*)[{]'
)
result
=
class_re
.
match
(
line
)
if
result
!=
None
:
for
var
in
self
.
__variables
:
line
+=
"
%
s
\n
"
%
var
#只有一个缩进的方法,为类方法,可插入同级方法
func_re
=
re
.
compile
(
r'\s{4}[a-zA-Z](.*)[)]\s{0,}[{]'
)
result
=
func_re
.
match
(
line
)
if
result
!=
None
:
print
(
result
.
group
())
# if :
def
java_garble
(
self
,
config
):
__used_names
=
[]
__variables
=
[]
__functions
=
[]
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
(
".java"
):
self
.
__garble_java_file
(
os
.
path
.
join
(
root
,
file
))
python/tools/garble/manifest_grable.py
View file @
30a35098
...
...
@@ -49,5 +49,5 @@ class ManifestGarble:
activities
=
self
.
__create_activities
(
"
%
s/
%
s/java"
%
(
config
[
"root"
],
main_dir
))
print
(
"inster activity to manifest ..."
)
self
.
__insert_to_manifest
(
"
%
s/
%
s/AndroidManifest.xml"
%
(
config
[
"root"
],
main_dir
),
activities
)
print
(
"done"
)
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