Commit 66ce41d4 by sikang

test

parent 4e6ce064
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import glob, os import glob, os
import string import string
import random import random
import re
class ActivityGarble: class ActivityGarble:
__config = {} __config = {}
...@@ -21,20 +22,23 @@ class ActivityGarble: ...@@ -21,20 +22,23 @@ class ActivityGarble:
#替换文件内容 #替换文件内容
def __process_file_content(self, path, file_name): def __process_file_content(self, path, file_name):
# print("processing content: %s..."%path) # print("processing content: %s..."%path)
chars = "_.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z".split('.')
with open(path, "rt") as fin: with open(path, "rt") as fin:
file_content = fin.read() file_content = fin.read()
# replace the file content based on mangle settings # replace the file content based on mangle settings
for (src, dst) in self.activity_mapping.items(): for (src, dst) in self.activity_mapping.items():
#避免命名重复,确保要替换的部分前后没有合法的命名字符,如果有则还原 #避免命名重复,确保要替换的部分前后没有合法的命名字符,如果有则还原
file_content = file_content.replace(src, dst) file_content = file_content.replace(src, dst)
for char in chars: before = re.findall(r'[0-9a-zA-Z_]'+dst,file_content)
if char + dst in file_content: if before != None:
file_content = file_content.replace(char + dst, char + src) for name in before:
elif dst + char in file_content: char = name.split(dst)[0]
file_content = file_content.replace(dst + char, src + char) file_content = file_content.replace(name, char + src)
after = re.findall(r''+ "%s[0-9a-zA-Z_]"% dst,file_content)
if after != None:
for name in after:
char = name.split(dst)[0]
file_content = file_content.replace(name, char + src)
ext = os.path.splitext(file_name)[1] ext = os.path.splitext(file_name)[1]
if ext == '.java': if ext == '.java':
...@@ -84,10 +88,4 @@ class ActivityGarble: ...@@ -84,10 +88,4 @@ class ActivityGarble:
for main_dir in config['lib_main']: for main_dir in config['lib_main']:
self.__process_files("%s/%s"% (config['root'],main_dir)) self.__process_files("%s/%s"% (config['root'],main_dir))
#混淆AndroidManifest.xml
# print("start garble 混淆AndroidManifest.xml ...")
# for main_dir in config['lib_main']:
# manifest_path = os.path.join("%s/%s"% (config['root'],main_dir), "AndroidManifest.xml")
# self.__process_file_content(manifest_path,"AndroidManifest.xml")
print("done") print("done")
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