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
7e003684
Commit
7e003684
authored
Oct 23, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update script
parent
9a7e2ee7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
26 deletions
+22
-26
python/tools/garbel/package_garble.py
+22
-26
No files found.
python/tools/garbel/package_garble.py
View file @
7e003684
...
...
@@ -17,17 +17,15 @@ class PackageGarble:
return
"
%
s_
%
s"
%
(
random_str1
,
random_str2
)
# 替换文件内容
def
__process_file_content
(
self
,
path
,
file_name
):
# print("processing content: %s..."%path)
with
open
(
path
,
"rt"
)
as
fin
:
file_content
=
fin
.
read
()
# replace the file content based on mangle settings
for
(
src
,
dst
)
in
self
.
pkg_mapping
.
items
():
separator
=
[
" "
,
"."
,
"
\"
"
,
"{"
,
"}"
,
"("
,
")"
,
"["
,
"]"
,
"<"
,
">"
,
":"
,
";"
,
","
]
for
sep
in
separator
:
file_content
=
file_content
.
replace
(
src
+
sep
,
dst
+
sep
)
# 必须先替换长路径
keys
=
sorted
(
self
.
pkg_mapping
.
keys
(),
key
=
lambda
i
:
len
(
i
.
split
(
"."
)),
reverse
=
True
)
for
pkg
in
self
.
pkg_mapping
.
keys
():
file_content
=
file_content
.
replace
(
pkg
,
self
.
pkg_mapping
[
pkg
])
ext
=
os
.
path
.
splitext
(
file_name
)[
1
]
if
ext
==
'.java'
:
...
...
@@ -99,38 +97,36 @@ class PackageGarble:
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
for
file
in
files
:
if
file
.
endswith
(
".java"
):
if
file
.
endswith
(
".java"
)
or
file
.
endswith
(
".kt"
)
or
file
.
endswith
(
".xml"
)
:
self
.
__process_file_content
(
os
.
path
.
join
(
directory
,
file
),
file
)
# 四大组件混淆
def
pkg_garble
(
self
,
config
):
# 遍历包
print
(
"find activity..."
)
print
(
"find pkgs..."
)
#生成混淆字典
self
.
__find_pkgs
(
"
%
s/app/src/main/java"
%
config
[
'root'
])
self
.
__find_pkgs
(
"
%
s/lib_base/src/main/java"
%
config
[
'root'
])
keys
=
sorted
(
self
.
pkg_mapping
.
keys
(),
key
=
lambda
i
:
len
(
i
.
split
(
"."
)),
reverse
=
True
)
for
key
in
keys
:
print
(
key
+
" -> "
+
self
.
pkg_mapping
[
key
])
#
keys = sorted(self.pkg_mapping.keys(),
#
key=lambda i: len(i.split(".")), reverse=True)
#
for key in keys:
#
print(key+" -> " + self.pkg_mapping[key])
#重命名路径
self
.
__rename_pkg
(
"
%
s/app/src/main/java"
%
config
[
'root'
])
self
.
__rename_pkg
(
"
%
s/lib_base/src/main/java"
%
config
[
'root'
])
# self.__find_pkgs("%s/lib_base/src/main/java"% config['root'])
# #开始混淆
# print("start garble .java...")
# self.__process_files("%s/app/src/main"% config['root'])
# self.__process_files("%s/lib_base/src/main"% config['root'])
#先删除3级以下路径(例如com com.common),避免干扰到三方SDK
for
(
key
,
value
)
in
self
.
pkg_mapping
.
items
():
path_level
=
len
(
key
.
split
(
"."
))
if
path_level
<
3
:
self
.
pkg_mapping
.
pop
(
key
)
# #混淆AndroidManifest.xml
# print("start garble 混淆AndroidManifest.xml ...")
# manifest_path = os.path.join("%s/app/src/main/"% config['root'], "AndroidManifest.xml")
# self.__process_file_content(manifest_path,"AndroidManifest.xml")
#全局替换
self
.
__process_files
(
"
%
s/app/src/main"
%
config
[
'root'
])
self
.
__process_files
(
"
%
s/lib_base/src/main"
%
config
[
'root'
])
# lib_manifest_path = os.path.join("%s/lib_base/src/main/"% config['root'], "AndroidManifest.xml")
# self.__process_file_content(lib_manifest_path,"AndroidManifest.xml")
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