Commit f258faa7 by sikang

6

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