Commit 5eb22d61 by sikang

update

parent 6496efd3
...@@ -6,6 +6,7 @@ from tools.garble.package_garble import PackageGarble ...@@ -6,6 +6,7 @@ from tools.garble.package_garble import PackageGarble
from tools.garble.string_garble import StringGarble from tools.garble.string_garble import StringGarble
from tools.garble.img_garble import ImageGarble from tools.garble.img_garble import ImageGarble
from tools.garble.java_garble import JavaGarble from tools.garble.java_garble import JavaGarble
from tools.garble.layout_garble import LayoutGarble
from func import Function from func import Function
import os import os
...@@ -29,6 +30,7 @@ print("4、包路径混淆(支持kotlin 但是kotlin的源码必须在src/main ...@@ -29,6 +30,7 @@ print("4、包路径混淆(支持kotlin 但是kotlin的源码必须在src/main
print("5、字符串插入/加密") print("5、字符串插入/加密")
print("6、插入混淆图片( 体积会增加1-2M )") print("6、插入混淆图片( 体积会增加1-2M )")
print("7、java文件插入乱码(慎用,必须全流程测试)") print("7、java文件插入乱码(慎用,必须全流程测试)")
print("8、layout 混淆")
print("21、还原代码") print("21、还原代码")
print(" ") print(" ")
...@@ -68,6 +70,9 @@ elif command == 6: ...@@ -68,6 +70,9 @@ elif command == 6:
elif command == 7: elif command == 7:
JavaGarble().java_garble(config) JavaGarble().java_garble(config)
elif command == 8:
LayoutGarble().layout_garble(config)
elif command == 21: elif command == 21:
#每行一个shell命令,参考自行修改 #每行一个shell命令,参考自行修改
command = "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ command = "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
......
...@@ -55,7 +55,7 @@ print("21、reset project") ...@@ -55,7 +55,7 @@ print("21、reset project")
print("22、加固") print("22、加固")
print("23、插入混淆图片") print("23、插入混淆图片")
print("24、插入混淆代码") print("24、插入混淆代码")
print("24、插入混淆layout") print("25、插入混淆layout")
print("26、启用/禁用代码") print("26、启用/禁用代码")
...@@ -84,6 +84,8 @@ if command == 1 or command == 111: ...@@ -84,6 +84,8 @@ if command == 1 or command == 111:
JavaGarble().java_garble(config) JavaGarble().java_garble(config)
#图片混淆 #图片混淆
ImageGarble().img_garble(config) ImageGarble().img_garble(config)
#布局文件混淆
LayoutGarble().layout_garble(config)
# 旧版脚本编译(待转移) # 旧版脚本编译(待转移)
if command == 1: if command == 1:
......
...@@ -18,9 +18,11 @@ class LayoutGarble: ...@@ -18,9 +18,11 @@ class LayoutGarble:
self.__used_names.append(result) self.__used_names.append(result)
return result return result
#随机取数组中一个item
def __rand_item(self, values): def __rand_item(self, values):
return values[random.randint(0, len(values)-1)] return values[random.randint(0, len(values)-1)]
#填充属性值
def __set_values(self, attrs): def __set_values(self, attrs):
gravity = ['center_vertical', 'center_horizontal', gravity = ['center_vertical', 'center_horizontal',
'left', 'right', 'bottom', 'top'] 'left', 'right', 'bottom', 'top']
...@@ -42,24 +44,27 @@ class LayoutGarble: ...@@ -42,24 +44,27 @@ class LayoutGarble:
.replace("${orientation}", self.__rand_item(orientation))\ .replace("${orientation}", self.__rand_item(orientation))\
.replace("${scaleType}", self.__rand_item(scale_type)) .replace("${scaleType}", self.__rand_item(scale_type))
#创建随机属性
def __create_attributes(self): def __create_attributes(self):
attrs = self.__layout_model[0].replace("\n","").split("*") attrs = self.__layout_model[0].replace("\n","").split("*")
result = "" result = ""
length = len(attrs) / 2 length = len(attrs) / 2
for i in range(0,random.randint(1, length)): for i in range(0,random.randint(1, length)):
item = attrs[random.randint(0, len(attrs)-1)] item = attrs[random.randint(0, len(attrs)-1)]
result += "%s" % self.__set_values(item) result += "%s\n" % self.__set_values(item)
attrs.remove(item) attrs.remove(item)
return result return "%s$"%result.replace("\n$","")
def __create_views(self): #创建随机数量的View
def __create_views(self,max):
view_model = self.__layout_model[2].split("@---sep---") view_model = self.__layout_model[2].split("@---sep---")
views = "" views = ""
for i in range(1,3): for i in range(1,max):
view = self.__rand_item(view_model) view = self.__rand_item(view_model)
views += self.__set_values(view).replace("${attributes}", self.__create_attributes()) views += self.__set_values(view).replace("${attributes}", self.__create_attributes())
return views return views
#生成一个layout文件
def __create_layout(self, path): def __create_layout(self, path):
layouts = self.__layout_model[1].split("@---sep---") layouts = self.__layout_model[1].split("@---sep---")
root_layout = self.__rand_item(layouts) root_layout = self.__rand_item(layouts)
...@@ -70,17 +75,29 @@ class LayoutGarble: ...@@ -70,17 +75,29 @@ class LayoutGarble:
for i in range(0,random.randint(1,5)): for i in range(0,random.randint(1,5)):
if random.randint(0,10) % random.randint(2,3) == 0: if random.randint(0,10) % random.randint(2,3) == 0:
layout = self.__rand_item(layouts).replace("${attributes}", self.__create_attributes()) layout = self.__rand_item(layouts).replace("${attributes}", self.__create_attributes())
layout = self.__set_values(layout).replace("${childs}",self.__create_views()) layout = self.__set_values(layout).replace("${childs}",self.__create_views(3))
content += layout content += layout
else: else:
content += self.__create_views() content += self.__create_views(3)
root_layout = root_layout.replace("${childs}",content) root_layout = root_layout.replace("${childs}",content)
with open(path,"w+",encoding='utf-8') as fout: with open(path,"w+",encoding='utf-8') as fout:
fout.write(root_layout) fout.write(root_layout)
#混淆已存在的layout
def __rewrite_layout(self,path):
with open(path,"r",encoding='utf-8') as fin:
lines = fin.readlines()
with open(path,"w+",encoding='utf-8') as fin:
for line in lines:
if "<TextView" in line or "<ImageView" in line or "<EditText" in line \
or "<Button" in line or "<ImageButton" in line or "<CheckBox" in line:
view = self.__create_views(1).replace("/>","\n%s/>"%"android:visibility=\"gone\"")
line = "%s\n%s"%(view,line)
fin.write(line)
#开始layout混淆
def layout_garble(self, config): def layout_garble(self, config):
with open("tools/garble/model/layout_model.xml", "r", encoding="utf-8") as fin: with open("tools/garble/model/layout_model.xml", "r", encoding="utf-8") as fin:
self.__layout_model = fin.read().split("@code\n") self.__layout_model = fin.read().split("@code\n")
...@@ -88,12 +105,16 @@ class LayoutGarble: ...@@ -88,12 +105,16 @@ class LayoutGarble:
with open("tools/garble/model/colors.json", "r", encoding="utf-8") as fin: with open("tools/garble/model/colors.json", "r", encoding="utf-8") as fin:
self.__colors = json.loads(fin.read()) self.__colors = json.loads(fin.read())
print("layout inserting ...") print("layout generating ...")
for main_dir in config['lib_main']: for main_dir in config['lib_main']:
for root, dirs, files in os.walk("%s/%s" % (config["root"], "%s/res/layout"%main_dir)): for root, dirs, files in os.walk("%s/%s" % (config["root"], "%s/res/layout"%main_dir)):
for i in range(30,100): for i in range(30,100):
path = os.path.join(root, "%s.xml" % self.__gen_rand_str()) if i % 10 == 0:
print(path) print("layout generating ...")
self.__create_layout(path) self.__create_layout(os.path.join(root, "%s.xml" % self.__gen_rand_str()))
for file in files:
if i % 10 == 0:
print("layout rewriting ...")
self.__rewrite_layout(os.path.join(root, files))
print("done") print("done")
...@@ -45,7 +45,7 @@ class ManifestGarble: ...@@ -45,7 +45,7 @@ class ManifestGarble:
def manifest_garble(self, config): def manifest_garble(self, config):
for main_dir in config['lib_main']: for main_dir in config['lib_main']:
print("generating activity ...") print("activity generating ...")
activities = self.__create_activities("%s/%s/java"%(config["root"], main_dir)) activities = self.__create_activities("%s/%s/java"%(config["root"], main_dir))
print("inster activity to manifest ...") print("inster activity to manifest ...")
self.__insert_to_manifest("%s/%s/AndroidManifest.xml"% (config["root"], main_dir), activities) self.__insert_to_manifest("%s/%s/AndroidManifest.xml"% (config["root"], main_dir), activities)
......
android:id="@+id/${id}"* android:id="@+id/${id}"*
android:background="${color}"* android:background="${color}"*
android:layout_gravity="${gravity}"* android:layout_gravity="${gravity}"*
android:visibility="${visibility}"*
android:longClickable="${boolean}"* android:longClickable="${boolean}"*
android:clickable="${boolean}"* android:clickable="${boolean}"*
android:layout_margin="${number}dp"* android:layout_margin="${number}dp"*
......
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