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
b9eca053
Commit
b9eca053
authored
Oct 19, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update script
parent
8f3afeb5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
15 deletions
+126
-15
python/func.py
+10
-12
python/main.py
+5
-0
python/tools/activity_garble.py
+107
-0
python/tools/garble.py
+4
-3
No files found.
python/func.py
View file @
b9eca053
...
@@ -13,7 +13,6 @@ import chardet
...
@@ -13,7 +13,6 @@ import chardet
class
Function
:
class
Function
:
# 随机生成包名
# 随机生成包名
def
new_appid
(
self
,
config
):
def
new_appid
(
self
,
config
):
app_name
=
config
[
'app_name'
]
.
replace
(
" "
,
""
)
.
lower
()
app_name
=
config
[
'app_name'
]
.
replace
(
" "
,
""
)
.
lower
()
start_name
=
[
"com"
,
"cn"
,
"id"
,
"app"
,
"host"
,
"in"
]
start_name
=
[
"com"
,
"cn"
,
"id"
,
"app"
,
"host"
,
"in"
]
...
@@ -43,7 +42,6 @@ class Function:
...
@@ -43,7 +42,6 @@ class Function:
self
.
update_properties
(
config
,
lines
)
self
.
update_properties
(
config
,
lines
)
# 加载shell变量
# 加载shell变量
def
load_properties
(
self
,
path
):
def
load_properties
(
self
,
path
):
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
...
@@ -56,8 +54,8 @@ class Function:
...
@@ -56,8 +54,8 @@ class Function:
config
[
key
]
=
value
config
[
key
]
=
value
return
config
return
config
# 创建签名文件
# 创建签名文件
def
new_keystore
(
self
,
config
):
def
new_keystore
(
self
,
config
):
# 只保留最近10个签名
# 只保留最近10个签名
count
=
0
count
=
0
...
@@ -86,8 +84,8 @@ class Function:
...
@@ -86,8 +84,8 @@ class Function:
}
}
self
.
update_properties
(
config
,
reset
)
self
.
update_properties
(
config
,
reset
)
# 更新properties字段
# 更新properties字段
def
update_properties
(
self
,
config
,
dict
):
def
update_properties
(
self
,
config
,
dict
):
file_content
=
""
file_content
=
""
replace_line
=
{}
replace_line
=
{}
...
@@ -109,8 +107,8 @@ class Function:
...
@@ -109,8 +107,8 @@ class Function:
with
open
(
config
[
'properties'
],
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
with
open
(
config
[
'properties'
],
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
f_w
.
write
(
file_content
)
f_w
.
write
(
file_content
)
# 移动apk
# 移动apk
def
move_apk
(
self
,
config
):
def
move_apk
(
self
,
config
):
file_name
=
"
%
s_
%
s"
%
(
file_name
=
"
%
s_
%
s"
%
(
config
[
'corp_id'
],
config
[
'app_name'
]
.
replace
(
" "
,
"_"
))
config
[
'corp_id'
],
config
[
'app_name'
]
.
replace
(
" "
,
"_"
))
...
@@ -125,8 +123,8 @@ class Function:
...
@@ -125,8 +123,8 @@ class Function:
else
:
else
:
shutil
.
copy
(
apk_local
,
apk1
)
shutil
.
copy
(
apk_local
,
apk1
)
# FB秘钥散列
# FB秘钥散列
def
getFbSign
(
self
,
config
):
def
getFbSign
(
self
,
config
):
with
open
(
"
%
s/app/src/main/AndroidManifest.xml"
%
config
[
'root'
],
"r"
)
as
f
:
with
open
(
"
%
s/app/src/main/AndroidManifest.xml"
%
config
[
'root'
],
"r"
)
as
f
:
file_content
=
f
.
read
()
file_content
=
f
.
read
()
...
@@ -144,8 +142,8 @@ class Function:
...
@@ -144,8 +142,8 @@ class Function:
.
replace
(
"<signing_certificate>"
,
config
[
'signing_certificate'
])
.
replace
(
"<signing_certificate>"
,
config
[
'signing_certificate'
])
os
.
system
(
command
)
os
.
system
(
command
)
# 更新Gateway
# 更新Gateway
def
update_gateway
(
self
,
config
):
def
update_gateway
(
self
,
config
):
gateway
=
requests
.
get
(
config
[
'gateway_url'
])
.
json
()
gateway
=
requests
.
get
(
config
[
'gateway_url'
])
.
json
()
jsonStr
=
json
.
dumps
(
gateway
)
.
replace
(
"http://"
,
"https://"
)
jsonStr
=
json
.
dumps
(
gateway
)
.
replace
(
"http://"
,
"https://"
)
...
@@ -168,8 +166,8 @@ class Function:
...
@@ -168,8 +166,8 @@ class Function:
}
}
self
.
update_properties
(
config
,
replaces
)
self
.
update_properties
(
config
,
replaces
)
# 切换主包马甲包
# 切换主包马甲包
def
cutover
(
self
,
config
):
def
cutover
(
self
,
config
):
print
(
"1、切换到主包"
)
print
(
"1、切换到主包"
)
print
(
"2、切换到马甲包"
)
print
(
"2、切换到马甲包"
)
...
@@ -234,8 +232,8 @@ class Function:
...
@@ -234,8 +232,8 @@ class Function:
.
replace
(
"${address}"
,
config
[
'cus_adress'
])
.
replace
(
"${address}"
,
config
[
'cus_adress'
])
f_w
.
write
(
desc
)
f_w
.
write
(
desc
)
# 打印checklist
# 打印checklist
def
print_checklist
(
self
,
config
,
just_print
):
def
print_checklist
(
self
,
config
,
just_print
):
print
(
" "
)
print
(
" "
)
print
(
"
%
s
%
s"
%
(
config
[
'corp_id'
],
config
[
'app_name'
]))
print
(
"
%
s
%
s"
%
(
config
[
'corp_id'
],
config
[
'app_name'
]))
...
@@ -274,8 +272,8 @@ class Function:
...
@@ -274,8 +272,8 @@ class Function:
img_path
+
"/top.png"
,
"/Users/connor/Documents/apks/"
+
file_name
)
img_path
+
"/top.png"
,
"/Users/connor/Documents/apks/"
+
file_name
)
print
(
"截图制作完成"
)
print
(
"截图制作完成"
)
# 更新本地隐私协议
# 更新本地隐私协议
def
update_local_privacy
(
self
,
config
):
def
update_local_privacy
(
self
,
config
):
path
=
config
[
'root'
]
+
"/app/src/main/assets/web/"
path
=
config
[
'root'
]
+
"/app/src/main/assets/web/"
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
...
@@ -296,8 +294,8 @@ class Function:
...
@@ -296,8 +294,8 @@ class Function:
fout
.
write
(
content
)
fout
.
write
(
content
)
print
(
"本地KSP协议已更新!"
+
ksp_url
)
print
(
"本地KSP协议已更新!"
+
ksp_url
)
# 创建新协议
# 创建新协议
def
new_privacy
(
self
,
config
):
def
new_privacy
(
self
,
config
):
permissions
=
"1235"
permissions
=
"1235"
if
config
[
'contact'
]
!=
"true"
:
if
config
[
'contact'
]
!=
"true"
:
...
@@ -315,8 +313,8 @@ class Function:
...
@@ -315,8 +313,8 @@ class Function:
fout
.
write
(
file_content
)
fout
.
write
(
file_content
)
print
(
"privacy done
\n
"
)
print
(
"privacy done
\n
"
)
# 转移出所有素材
# 转移出所有素材
def
move_resources
(
self
,
config
):
def
move_resources
(
self
,
config
):
target
=
"/Users/connor/Documents/apks"
target
=
"/Users/connor/Documents/apks"
img_path
=
"../../app/src/main/res/drawable-xxhdpi"
img_path
=
"../../app/src/main/res/drawable-xxhdpi"
...
...
python/main.py
View file @
b9eca053
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
func
import
Function
from
func
import
Function
from
shell
import
Shell
from
shell
import
Shell
from
tools.garble
import
Garble
from
tools.garble
import
Garble
from
tools.activity_garble
import
ActivityGarble
import
os
import
os
import
shutil
import
shutil
...
@@ -31,6 +32,7 @@ print("14、生成隐协议文件")
...
@@ -31,6 +32,7 @@ print("14、生成隐协议文件")
print
(
"15、刷新本地协议"
)
print
(
"15、刷新本地协议"
)
print
(
"16、api混淆"
)
print
(
"16、api混淆"
)
print
(
"17、字符串混淆"
)
print
(
"17、字符串混淆"
)
print
(
"18、四大组件混淆"
)
print
(
"21、reset project"
)
print
(
"21、reset project"
)
command
=
int
(
input
(
"请输入指令编号:"
))
command
=
int
(
input
(
"请输入指令编号:"
))
...
@@ -88,5 +90,8 @@ elif command == 16:
...
@@ -88,5 +90,8 @@ elif command == 16:
elif
command
==
17
:
elif
command
==
17
:
Garble
()
.
str_grable
(
config
)
Garble
()
.
str_grable
(
config
)
elif
command
==
17
:
ActivityGarble
()
.
activity_garble
(
config
)
elif
command
==
21
:
elif
command
==
21
:
Shell
()
.
reset_project
(
config
)
Shell
()
.
reset_project
(
config
)
python/tools/activity_garble.py
0 → 100644
View file @
b9eca053
# -*-coding:utf-8-*-
import
glob
,
os
import
string
import
random
class
ActivityGarble
:
target
=
[
"Activity.java"
,
"Bean.java"
,
"Fragmant.java"
,
"Receiver.java"
,
"BaseApplication.java"
,
"ContactEntity.java"
,
"SmsEntity.java"
,
"ActivityCenter.java"
,
"Service.java"
,
"Collector.java"
,
"BannerMessageDto.java"
,
"BasicAck.java"
,
"InviteResult.java"
,
"LoanAppBeanFatherStatusLogs.java"
,
"LoanRange.java"
,
"PhotoInfo.java"
,
"IncomeMessageProto.java"
,
"ResponseErrorBody.java"
,
"RecordFilesResponse.java"
,
"TotalAmount.java"
,
"UserBankInfo.java"
,
"YWUser.java"
,
"TDChannel.java"
]
used_names
=
[]
activity_mapping
=
{}
#随机串
def
__gen_rand_str
(
self
):
rand_str
=
''
.
join
(
random
.
choices
(
string
.
ascii_uppercase
+
string
.
ascii_lowercase
,
k
=
8
))
while
rand_str
in
self
.
used_names
:
rand_str
=
''
.
join
(
random
.
choices
(
string
.
ascii_uppercase
+
string
.
ascii_lowercase
,
k
=
8
))
self
.
used_names
.
append
(
rand_str
)
return
rand_str
#替换文件内容
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
.
activity_mapping
.
items
():
separator
=
[
" "
,
"."
,
"
\"
"
,
"{"
,
"}"
,
"("
,
")"
,
"["
,
"]"
,
"<"
,
">"
,
":"
,
";"
,
","
]
for
sep
in
separator
:
file_content
=
file_content
.
replace
(
src
+
sep
,
dst
+
sep
)
ext
=
os
.
path
.
splitext
(
file_name
)[
1
]
if
ext
==
'.java'
:
comment
=
"// machine renamed:
%
s
\n
"
%
file_name
file_content
=
"
%
s
%
s"
%
(
comment
,
file_content
)
with
open
(
path
,
"wt"
)
as
fout
:
fout
.
write
(
file_content
)
return
#查找所有待混淆类 并重命名
def
__find_activities
(
self
,
path
):
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
for
file
in
files
:
is_activity
=
False
for
file_name
in
self
.
target
:
if
file
.
endswith
(
file_name
):
is_activity
=
True
if
is_activity
:
name
=
os
.
path
.
splitext
(
file
)[
0
]
if
name
not
in
self
.
activity_mapping
.
keys
():
self
.
activity_mapping
[
name
]
=
self
.
__gen_rand_str
()
src
=
os
.
path
.
join
(
directory
,
file
)
dst
=
os
.
path
.
join
(
directory
,
"
%
s.java"
%
self
.
activity_mapping
[
name
])
os
.
rename
(
src
,
dst
)
#遍历混淆文件
def
__process_files
(
self
,
path
):
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
for
file
in
files
:
self
.
__process_file_content
(
os
.
path
.
join
(
directory
,
file
),
file
)
#四大组件混淆
def
activity_garble
(
self
,
config
):
#找到要混淆的java文件
self
.
__find_activities
(
"
%
s/app/src/main"
%
config
[
'root'
])
self
.
__find_activities
(
"
%
s/lib_base/src/main"
%
config
[
'root'
])
#开始混淆
self
.
__process_files
(
"
%
s/app/src/main"
%
config
[
'root'
])
self
.
__process_files
(
"
%
s/lib_base/src/main"
%
config
[
'root'
])
#混淆AndroidManifest.xml
manifest_path
=
os
.
path
.
join
(
"
%
s/app/src/main/"
%
config
[
'root'
],
"AndroidManifest.xml"
)
self
.
__process_file_content
(
manifest_path
,
"AndroidManifest.xml"
)
lib_manifest_path
=
os
.
path
.
join
(
"
%
s/lib_base/src/main/"
%
config
[
'root'
],
"AndroidManifest.xml"
)
self
.
__process_file_content
(
lib_manifest_path
,
"AndroidManifest.xml"
)
\ No newline at end of file
python/tools/garble.py
View file @
b9eca053
# -*-coding:utf-8-*-
import
glob
,
os
import
glob
,
os
import
string
import
string
import
random
import
random
...
@@ -53,6 +54,7 @@ class Garble:
...
@@ -53,6 +54,7 @@ class Garble:
path
=
os
.
path
.
join
(
directory
,
file
)
path
=
os
.
path
.
join
(
directory
,
file
)
self
.
__rename_api
(
path
,
config
)
self
.
__rename_api
(
path
,
config
)
#字符串混淆
#字符串混淆
def
__string_grable
(
self
,
path
):
def
__string_grable
(
self
,
path
):
with
open
(
path
,
"r"
)
as
f
:
with
open
(
path
,
"r"
)
as
f
:
...
@@ -76,7 +78,6 @@ class Garble:
...
@@ -76,7 +78,6 @@ class Garble:
print
(
"done
\n
"
)
print
(
"done
\n
"
)
return
return
def
str_grable
(
self
,
config
):
def
str_grable
(
self
,
config
):
for
root
,
dirs
,
files
in
os
.
walk
(
"
%
s/lib_base/src/main/res"
%
config
[
'root'
]):
for
root
,
dirs
,
files
in
os
.
walk
(
"
%
s/lib_base/src/main/res"
%
config
[
'root'
]):
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
directory
=
os
.
path
.
join
(
os
.
getcwd
(),
root
)
...
@@ -84,4 +85,5 @@ class Garble:
...
@@ -84,4 +85,5 @@ class Garble:
if
file
.
endswith
(
"strings.xml"
):
if
file
.
endswith
(
"strings.xml"
):
# get the path of the java file
# get the path of the java file
path
=
os
.
path
.
join
(
directory
,
file
)
path
=
os
.
path
.
join
(
directory
,
file
)
self
.
__string_grable
(
path
)
self
.
__string_grable
(
path
)
\ 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