Commit f258faa7 by sikang

6

parent d49fc98b
......@@ -53,11 +53,6 @@
"UploadCollectionBean.java"
],
"//conditional_java" : "满足混淆条件的行,匹配方式",
"conditional_java" : [
],
"//jiagu_output" : "360加固输出路径",
"jiagu_output" : "/Users/connor/Documents/apks",
......
......@@ -21,10 +21,10 @@ config.update(properties)
print(" ")
print("------------- 使用帮助 -----------------")
print("0、一条龙混淆")
print("1、activity类名混淆")
print("1、activity类名混淆(只支持java)")
print("2、api混淆(针对 Retrofit 注解)")
print("3、manifest混淆 在包路径中随机插入Activity并注册")
print("4、包路径混淆")
print("3、manifest混淆 在包路径中随机插入Activity并注册 (支持kotlin 但是kotlin的源码必须在src/main/java下)")
print("4、包路径混淆(支持kotlin 但是kotlin的源码必须在src/main/java下)")
print("5、字符串插入/加密")
print("6、插入混淆图片( 体积会增加1-2M )")
print("21、还原代码")
......
......@@ -7,12 +7,14 @@ class JavaGarble:
__used_names = []
__variables = []
__functions = []
__logic_model = ""
__config = {}
def __gen_rand_str(self):
result = ""
while len(result) == 0 or result in self.__used_names:
result = ''.join(random.sample(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", random.randint(1, 2)))
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", random.randint(2, 10)))
self.__used_names.append(result)
return result
......@@ -100,6 +102,31 @@ class JavaGarble:
self.__generate_function(model_path)
#插入代码
def __insert_code(self):
codes = self.__logic_model.split("//sep")
code = codes[random.randint(0,len(codes)-1)]
code.replace("${string}",self.__gen_rand_str())
code.replace("${name}",self.__gen_rand_str())
code.replace("${number}",random.randint(1,10000))
vars_size = len(self.__variables)-1
items = self.__variables[random.randint(0,vars_size)].split(" ")
if "String" in items[1]:
condition = "%s.length()%s%d"%(items[2],random.sample("><", 1), items[4])
else:
condition = "%s%s%d"%(items[2],random.sample("><", 1), items[4])
code.replace("${condition}",condition)
content = ""
for i in range(0,random.randint(0,vars_size)):
var = self.__variables[random.randint(0,vars_size)]
content += "%s + "% var.split(" ")[2]
content = "System.out.println(len(%s+\"\"));"%content
code.replace("${content}",content)
def __garble_java_file(self,file):
self.__used_names = []
self.__variables = []
......@@ -113,32 +140,48 @@ class JavaGarble:
self.__generate_function("tools/garble/model/activity_model.java")
ignore = False
#花括号
curly_braces=[]
with open(file,"w+",encoding="utf-8") as fout:
for line in lines:
# interface 不混淆
if "interface" in line and "{\n" in line:
ignore = True
if ignore:
if "interface" in line and "{\n" in line or ignore:
ignore = True
fout.write(line)
continue
#class下插入全局变量
if (line.startswith("class ") or " class " in line) and "{\n" in line:
#插入全局变量
for var in self.__variables:
line +="%s\n"% var
#插入方法
for fun in self.__functions:
line +="%s\n"% fun
#只有一个缩进的方法,为类方法,可插入同级方法
# func_re = re.compile(r'\s{4}[a-zA-Z](.*)[)]\s{0,}[{]')
# result = func_re.match(line)
# if result != None:
# print(result.group())
# if :
#定位1个缩进开头的类方法
if (line.startswith(" ") and not line.startswith(" ")) and ("){\n" in line or ") {\n" in line):
curly_braces = line.count("{")
curly_braces -= line.count("}")
#一个花括号表示在方法的直接作用域内
if curly_braces == 1:
curly_braces += line.count("{")
curly_braces -= line.count("}")
if "return" in line:
curly_braces = -10000
continue
if ";\n" in line:
line +="\n%s"% self.__insert_code()
fout.write(line)
def java_garble(self,config):
self.__config = config
with open("tools/garble/model/logic_model.java", "r", encoding="utf-8") as fin:
self.__logic_model = fin.read()
for main_dir in config['lib_main']:
for root, dirs, files in os.walk("%s/%s"%(config["root"],main_dir)):
for file in files:
......
android.util.Log.d(${string})
//---sep---
android.util.Log.e(${string})
//---sep---
android.util.Log.i(${string})
//---sep---
android.util.Log.v(${string})
//---sep---
android.util.Log.d("${string}","${string}")
//sep
android.util.Log.e("${string}","${string}")
//sep
android.util.Log.i("${string}","${string}")
//sep
android.util.Log.v("${string}","${string}")
//sep
while(${condition}){
${content}
}
//---sep---
//sep
for(${condition}){
${content}
}
//---sep---
//sep
if(int ${name};${condition};${name}++){
${content}
}
//---sep---
//sep
boolean ${name} = ${condition}
if(${name}){
${content}
}
//---sep---
String ${name} = ${string}
System.out.println(${name}+${string});
//---sep---
//sep
String ${name} = "${string}"
System.out.println(${name}+"${string}");
//sep
float ${name} = ${number}
while((int)${name} < (${name} - 1)){
${content}
}
//---sep---
//sep
if(android.text.TextUtils(Build.BOARD)){
${content}
}
//---sep---
if(Build.DEVICE.contains(${string})){
//sep
if(Build.DEVICE.contains("${string}")){
${content}
}
\ No newline at end of file
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