Commit b9eca053 by sikang

update script

parent 8f3afeb5
......@@ -13,7 +13,6 @@ import chardet
class Function:
# 随机生成包名
def new_appid(self,config):
app_name = config['app_name'].replace(" ", "").lower()
start_name = ["com", "cn", "id", "app", "host", "in"]
......@@ -43,7 +42,6 @@ class Function:
self.update_properties(config,lines)
# 加载shell变量
def load_properties(self,path):
with open(path, "r", encoding="utf-8") as f:
lines = f.readlines()
......@@ -56,8 +54,8 @@ class Function:
config[key] = value
return config
# 创建签名文件
def new_keystore(self,config):
# 只保留最近10个签名
count = 0
......@@ -86,8 +84,8 @@ class Function:
}
self.update_properties(config, reset)
# 更新properties字段
def update_properties(self,config, dict):
file_content = ""
replace_line = {}
......@@ -109,8 +107,8 @@ class Function:
with open(config['properties'], "w", encoding="utf-8") as f_w:
f_w.write(file_content)
# 移动apk
def move_apk(self,config):
file_name = "%s_%s" % (
config['corp_id'], config['app_name'].replace(" ", "_"))
......@@ -125,8 +123,8 @@ class Function:
else:
shutil.copy(apk_local, apk1)
# FB秘钥散列
def getFbSign(self,config):
with open("%s/app/src/main/AndroidManifest.xml" % config['root'], "r") as f:
file_content = f.read()
......@@ -144,8 +142,8 @@ class Function:
.replace("<signing_certificate>", config['signing_certificate'])
os.system(command)
# 更新Gateway
def update_gateway(self,config):
gateway = requests.get(config['gateway_url']).json()
jsonStr = json.dumps(gateway).replace("http://", "https://")
......@@ -168,8 +166,8 @@ class Function:
}
self.update_properties(config, replaces)
# 切换主包马甲包
def cutover(self,config):
print("1、切换到主包")
print("2、切换到马甲包")
......@@ -234,8 +232,8 @@ class Function:
.replace("${address}", config['cus_adress'])
f_w.write(desc)
# 打印checklist
def print_checklist(self,config, just_print):
print(" ")
print("%s %s" % (config['corp_id'], config['app_name']))
......@@ -274,8 +272,8 @@ class Function:
img_path+"/top.png", "/Users/connor/Documents/apks/"+file_name)
print("截图制作完成")
# 更新本地隐私协议
def update_local_privacy(self,config):
path = config['root'] + "/app/src/main/assets/web/"
if not os.path.exists(path):
......@@ -296,8 +294,8 @@ class Function:
fout.write(content)
print("本地KSP协议已更新!" + ksp_url)
# 创建新协议
def new_privacy(self,config):
permissions = "1235"
if config['contact'] != "true":
......@@ -315,8 +313,8 @@ class Function:
fout.write(file_content)
print("privacy done\n")
# 转移出所有素材
def move_resources(self,config):
target = "/Users/connor/Documents/apks"
img_path = "../../app/src/main/res/drawable-xxhdpi"
......
......@@ -2,6 +2,7 @@
from func import Function
from shell import Shell
from tools.garble import Garble
from tools.activity_garble import ActivityGarble
import os
import shutil
......@@ -31,6 +32,7 @@ print("14、生成隐协议文件")
print("15、刷新本地协议")
print("16、api混淆")
print("17、字符串混淆")
print("18、四大组件混淆")
print("21、reset project")
command = int(input("请输入指令编号:"))
......@@ -88,5 +90,8 @@ elif command == 16:
elif command == 17:
Garble().str_grable(config)
elif command == 17:
ActivityGarble().activity_garble(config)
elif command == 21:
Shell().reset_project(config)
# -*-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
# -*-coding:utf-8-*-
import glob, os
import string
import random
......@@ -53,6 +54,7 @@ class Garble:
path = os.path.join(directory, file)
self.__rename_api(path,config)
#字符串混淆
def __string_grable(self,path):
with open(path, "r") as f:
......@@ -76,7 +78,6 @@ class Garble:
print("done\n")
return
def str_grable(self,config):
for root, dirs, files in os.walk("%s/lib_base/src/main/res"% config['root']):
directory = os.path.join(os.getcwd(), root)
......@@ -84,4 +85,5 @@ class Garble:
if file.endswith("strings.xml"):
# get the path of the java file
path = os.path.join(directory, file)
self.__string_grable(path)
\ No newline at end of file
self.__string_grable(path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment