首页 > 其他分享 >如何通过代码混淆绕过苹果机审,解决APP被拒问题

如何通过代码混淆绕过苹果机审,解决APP被拒问题

时间:2023-10-17 17:16:15浏览次数:34  
标签:混淆 end name text APP file new path 苹果机

 

目录

 

iOS代码混淆

功能分析

实现流程

类名修改

方法名修改

生成垃圾代码

替换png等静态资源MD5

info.plist文件添加垃圾字段

功能分析

实现流程

类名修改

方法名修改

生成垃圾代码

替换png等静态资源MD5

info.plist文件添加垃圾字段

混淆前后对比


 

iOS代码混淆

目前公司产品线中存在大量功能类似的APP,按照模块化方式开发项目,核心模块业务代码是复用的,使用同一个开发者账号下iOS上架流程中有些APP在苹果机审过程中惨遭被拒的下场,通过更改部分页面UI效果也无济于事,于是采用代码混淆的方式也就是马甲包方案去绕过机审;

功能分析

  • 二进制不同,图标,包名,工程名,代码,静态资源等的修改。

  • 差异化UI风格,产品功能,页面布局等的修改

实现流程

  • 核心模块类名修改

  • 核心方法名修改

  • 加入垃圾代码

  • 替换png等静态资源MD5

  • info.plist文件添加垃圾字段

     

     

image.png

 

  • 编辑

类名修改

  • 遍历查找需要替换的核心模块目录 (主工程\Pods目录)

  • 找到所有需要替换的类名(项目专用前缀),将其存放到数组中

  • 遍历查找整个工程的所有目录,查找所有.h、.m、.xib、.string文件,逐行扫描文件,找到需要替换的类名关键字替换成别的名字前缀

  • 如发现.h、.m、.xib、.string文件的文件名包含需要替换的类名,替换之(xcodeproj工程需要重新引入文件,通过脚本动态引入)

  • 遇到有"+"号的分类文件,筛选出"+"号前面的类名然后替换之

applescript复制代码#遍历查找所有.h、.m、.xib、.strings文件,逐行扫描文件,找到需要替换的类名关键字替换成别的名字前缀
def do_replace_file_name(dir_path,need_name_list)
	Dir.foreach(dir_path) do |file|
		if file != "." and file != ".."
			file_path = dir_path + "/" + file
		    if File.directory? file_path
		    	do_replace_file_name(file_path,need_name_list)
		    else
		    	if file.end_with?(".h") or file.end_with?(".m") or file.end_with?(".xib") or file.end_with?(".strings") #只查找.h .m .xib .strings文件批量修改
					aFile = File.new(file_path, "r")
		    		if aFile
   						file_content = aFile.read()
   						aFile.close

   						length = need_name_list.length - 1
   						for i in 0..length do

   							need_name = need_name_list[i]
   							file_content = split_file_content(file_content,need_name)

   						end

   						aFile = File.new(file_path, "w")
   						aFile.syswrite(file_content)
   						aFile.rewind
   						
					end
		    	end

		    	#如.h、.m、.xib、.string文件的文件名包含需要替换的类名,替换之
		    	if file.include?".h" or file.include?".m" or file.include?".xib" or file.include?".strings"
		    		file_suffix = file.split(".")[1]
		    		need_name_list.each { |need_name|
		    			need_file_name = need_name + "." + file_suffix
   						if file.start_with?(need_file_name)

   							new_file_name = new_file_name(file)
   							
					    	new_file_path = dir_path + "/" + new_file_name
							File.rename(file_path, new_file_path) #文件名称替换
   						end
   					}

		    	end

		    end
		end
	end
end

 

 

方法名修改

  • 获取系统文件关键字并缓存,主要是获取iOS SDK中Frameworks所有方法名和参数名作为忽略关键字

  • 遍历查找整个工程的所有.h、.m、.mm文件,提取关键字,主要提取方法名和参数名

  • 将系统关键字、IBAction方法的关键字、属性property的关键字(防止懒加载方法名造成冲突)去除

  • 将剩余的关键字进行方法混淆,混淆方案是将名字用#define宏定义方式替换名称,方法不能替换成随机字符串,这样任然不能通过机审,应替换成规律的单词拼接方法名

  • 将替换后方法名关键字宏名称写入到全局pch文件,xcodeproj动态引入

pgsql复制代码    # 生成混淆文件
    @staticmethod
    def create_confuse_file(output_file, confused_dict):
        log_info("Start creating confuse file, file fullpath is {0}".format(os.path.realpath(output_file)), 2, True)
        f = open(output_file, 'wb')
        f.write(bytes('#ifndef NEED_CONFUSE_h\n', encoding='utf-8'))
        f.write(bytes('#define NEED_CONFUSE_h\n', encoding='utf-8'))
        f.write(bytes('// 生成时间: {0}\n'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), encoding='utf-8'))
        for (key, value) in confused_dict.items():
            f.write(bytes('#define {0} {1}\n'.format(key, value), encoding='utf-8'))
        f.write(bytes('#endif', encoding='utf-8'))
        f.close()

 

 

生成垃圾代码

  • 遍历查找整个工程的所有.m、.mm文件

  • 为避免和混淆后的方法重名,添加垃圾方法的时候使用 随机前缀 + "_" + 规律单词 作为方法名,随意在方法中添加日志代码

  • 在文件结尾@end前插入这些方法

haxe复制代码#oc代码以@end结尾,在其前面添加text
def appendTextToOCFile(file_path, text):
    with open(file_path, "r") as fileObj:
        old_text = fileObj.read()
        fileObj.close()
        end_mark_index = old_text.rfind("@end")
        if end_mark_index == -1:
            print "\t非法的结尾格式: " + file_path
            return
        new_text = old_text[:end_mark_index]
        new_text = new_text + text + "\n"
        new_text = new_text + old_text[end_mark_index:]

    with open(file_path, "w") as fileObj:
        fileObj.write(new_text)

#处理单个OC文件,添加垃圾函数。确保其对应头文件存在于相同目录
def dealWithOCFile(filename, file_path):
    global target_ios_folder,create_func_min,create_func_max,funcname_set
    funcname_set.clear()
    end_index = file_path.rfind(".")
    pre_name = file_path[:end_index]
    header_path = pre_name + ".h"
    if not os.path.exists(header_path):
        print "\t相应头文件不存在:" + file_path
        return

    new_func_num = random.randint(create_func_min, create_func_max)
    print "\t给%s添加%d个方法" %(filename, new_func_num)

    prefix_list = ['btt_', 'gym_', 'muut_', 'ora_', 'vend_', 'enyt_', 'qotb_', 'ldt_', 'zndy_', 'tim_', 'yar_', 'toa_', 'rewwy_', 'twof_', 'theg_', 'guis_', 'dui_' ]

    random_index_list = random.sample(range(0,new_func_num), new_func_num)

    for i in range(new_func_num):
        
        prefix = prefix_list[random_index_list[i]]
        header_text = getOCHeaderFuncText(prefix)
        # print "add %s to %s" %(header_text, header_path.replace(target_ios_folder, ""))
        appendTextToOCFile(header_path, header_text + ";\n")
        funcText = getOCFuncText(header_text)
        appendTextToOCFile(file_path, funcText)

 

 

替换png等静态资源MD5

livecodeserver复制代码        if file_type == ".png":
            text = "".join(random.sample(string.ascii_letters, 11))
        elif file_type == ".jpg":
            text = "".join(random.sample(string.ascii_letters, 20))
        elif file_type == ".lua":
            text = "\n--#*" + "".join(random.sample(string.ascii_letters, 10)) + "*#--"
        else:
            text = " "*random.randint(1, 100)
        fileObj.write(text)
        fileObj.close()

 

info.plist文件添加垃圾字段

在info.plist中插入规律英文单词(已排除系统专用字段),值为随机字符串

scss复制代码def addPlistField(plist_file):
    
    global create_field_min,create_field_max,word_name_list
    create_field_num = random.randint(create_field_min, create_field_max)
    random_index_list = random.sample(word_name_list, create_field_num)

    tree = ET.parse(plist_file)
    root = tree.getroot()

    root_dict = root.find("dict")

    for i in range(create_field_num):

        key_node = ET.SubElement(root_dict,"key")
        key_node.text = random_index_list[i]

        string_node = ET.SubElement(root_dict,"string")
        string_node.text = getOneName()

    tree.write(plist_file,"UTF-8")

 

目前公司产品线中存在大量功能类似的APP,按照模块化方式开发项目,核心模块业务代码是复用的,使用同一个开发者账号下iOS上架流程中有些APP在苹果机审过程中惨遭被拒的下场,通过更改部分页面UI效果也无济于事,于是采用代码混淆的方式也就是马甲包方案去绕过机审;

功能分析

  • 二进制不同,图标,包名,工程名,代码,静态资源等的修改。

  • 差异化UI风格,产品功能,页面布局等的修改

实现流程

  • 核心模块类名修改

  • 核心方法名修改

  • 加入垃圾代码

  • 替换png等静态资源MD5

  • info.plist文件添加垃圾字段

     

     

image.png

 

类名修改

  • 遍历查找需要替换的核心模块目录 (主工程\Pods目录)

  • 找到所有需要替换的类名(项目专用前缀),将其存放到数组中

  • 遍历查找整个工程的所有目录,查找所有.h、.m、.xib、.string文件,逐行扫描文件,找到需要替换的类名关键字替换成别的名字前缀

  • 如发现.h、.m、.xib、.string文件的文件名包含需要替换的类名,替换之(xcodeproj工程需要重新引入文件,通过脚本动态引入)

  • 遇到有"+"号的分类文件,筛选出"+"号前面的类名然后替换之

applescript复制代码#遍历查找所有.h、.m、.xib、.strings文件,逐行扫描文件,找到需要替换的类名关键字替换成别的名字前缀
def do_replace_file_name(dir_path,need_name_list)
	Dir.foreach(dir_path) do |file|
		if file != "." and file != ".."
			file_path = dir_path + "/" + file
		    if File.directory? file_path
		    	do_replace_file_name(file_path,need_name_list)
		    else
		    	if file.end_with?(".h") or file.end_with?(".m") or file.end_with?(".xib") or file.end_with?(".strings") #只查找.h .m .xib .strings文件批量修改
					aFile = File.new(file_path, "r")
		    		if aFile
   						file_content = aFile.read()
   						aFile.close

   						length = need_name_list.length - 1
   						for i in 0..length do

   							need_name = need_name_list[i]
   							file_content = split_file_content(file_content,need_name)

   						end

   						aFile = File.new(file_path, "w")
   						aFile.syswrite(file_content)
   						aFile.rewind
   						
					end
		    	end

		    	#如.h、.m、.xib、.string文件的文件名包含需要替换的类名,替换之
		    	if file.include?".h" or file.include?".m" or file.include?".xib" or file.include?".strings"
		    		file_suffix = file.split(".")[1]
		    		need_name_list.each { |need_name|
		    			need_file_name = need_name + "." + file_suffix
   						if file.start_with?(need_file_name)

   							new_file_name = new_file_name(file)
   							
					    	new_file_path = dir_path + "/" + new_file_name
							File.rename(file_path, new_file_path) #文件名称替换
   						end
   					}

		    	end

		    end
		end
	end
end

 

 

方法名修改

  • 获取系统文件关键字并缓存,主要是获取iOS SDK中Frameworks所有方法名和参数名作为忽略关键字

  • 遍历查找整个工程的所有.h、.m、.mm文件,提取关键字,主要提取方法名和参数名

  • 将系统关键字、IBAction方法的关键字、属性property的关键字(防止懒加载方法名造成冲突)去除

  • 将剩余的关键字进行方法混淆,混淆方案是将名字用#define宏定义方式替换名称,方法不能替换成随机字符串,这样任然不能通过机审,应替换成规律的单词拼接方法名

  • 将替换后方法名关键字宏名称写入到全局pch文件,xcodeproj动态引入

pgsql复制代码    # 生成混淆文件
    @staticmethod
    def create_confuse_file(output_file, confused_dict):
        log_info("Start creating confuse file, file fullpath is {0}".format(os.path.realpath(output_file)), 2, True)
        f = open(output_file, 'wb')
        f.write(bytes('#ifndef NEED_CONFUSE_h\n', encoding='utf-8'))
        f.write(bytes('#define NEED_CONFUSE_h\n', encoding='utf-8'))
        f.write(bytes('// 生成时间: {0}\n'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), encoding='utf-8'))
        for (key, value) in confused_dict.items():
            f.write(bytes('#define {0} {1}\n'.format(key, value), encoding='utf-8'))
        f.write(bytes('#endif', encoding='utf-8'))
        f.close()

 

 

生成垃圾代码

  • 遍历查找整个工程的所有.m、.mm文件

  • 为避免和混淆后的方法重名,添加垃圾方法的时候使用 随机前缀 + "_" + 规律单词 作为方法名,随意在方法中添加日志代码

  • 在文件结尾@end前插入这些方法

haxe复制代码#oc代码以@end结尾,在其前面添加text
def appendTextToOCFile(file_path, text):
    with open(file_path, "r") as fileObj:
        old_text = fileObj.read()
        fileObj.close()
        end_mark_index = old_text.rfind("@end")
        if end_mark_index == -1:
            print "\t非法的结尾格式: " + file_path
            return
        new_text = old_text[:end_mark_index]
        new_text = new_text + text + "\n"
        new_text = new_text + old_text[end_mark_index:]

    with open(file_path, "w") as fileObj:
        fileObj.write(new_text)

#处理单个OC文件,添加垃圾函数。确保其对应头文件存在于相同目录
def dealWithOCFile(filename, file_path):
    global target_ios_folder,create_func_min,create_func_max,funcname_set
    funcname_set.clear()
    end_index = file_path.rfind(".")
    pre_name = file_path[:end_index]
    header_path = pre_name + ".h"
    if not os.path.exists(header_path):
        print "\t相应头文件不存在:" + file_path
        return

    new_func_num = random.randint(create_func_min, create_func_max)
    print "\t给%s添加%d个方法" %(filename, new_func_num)

    prefix_list = ['btt_', 'gym_', 'muut_', 'ora_', 'vend_', 'enyt_', 'qotb_', 'ldt_', 'zndy_', 'tim_', 'yar_', 'toa_', 'rewwy_', 'twof_', 'theg_', 'guis_', 'dui_' ]

    random_index_list = random.sample(range(0,new_func_num), new_func_num)

    for i in range(new_func_num):
        
        prefix = prefix_list[random_index_list[i]]
        header_text = getOCHeaderFuncText(prefix)
        # print "add %s to %s" %(header_text, header_path.replace(target_ios_folder, ""))
        appendTextToOCFile(header_path, header_text + ";\n")
        funcText = getOCFuncText(header_text)
        appendTextToOCFile(file_path, funcText)

 

 

替换png等静态资源MD5

livecodeserver复制代码        if file_type == ".png":
            text = "".join(random.sample(string.ascii_letters, 11))
        elif file_type == ".jpg":
            text = "".join(random.sample(string.ascii_letters, 20))
        elif file_type == ".lua":
            text = "\n--#*" + "".join(random.sample(string.ascii_letters, 10)) + "*#--"
        else:
            text = " "*random.randint(1, 100)
        fileObj.write(text)
        fileObj.close()

 

 

info.plist文件添加垃圾字段

在info.plist中插入规律英文单词(已排除系统专用字段),值为随机字符串

scss复制代码def addPlistField(plist_file):
    
    global create_field_min,create_field_max,word_name_list
    create_field_num = random.randint(create_field_min, create_field_max)
    random_index_list = random.sample(word_name_list, create_field_num)

    tree = ET.parse(plist_file)
    root = tree.getroot()

    root_dict = root.find("dict")

    for i in range(create_field_num):

        key_node = ET.SubElement(root_dict,"key")
        key_node.text = random_index_list[i]

        string_node = ET.SubElement(root_dict,"string")
        string_node.text = getOneName()

    tree.write(plist_file,"UTF-8")

 

 

混淆前后对比

代码混淆前

 

 

img

 

 

Hopper查看混淆前

 

 

img

 

 

代码混淆后

 

 

img

 

 

Hopper查看混淆后

 

img

 

 

假如你不知道如何代码混淆和如何创建文件混淆,你可以参考下面这个教程来使用我们平台代码混淆和文件混淆以及重签名:怎么保护苹果手机移动应用程序ios ipa中的代码 | ipaguard使用教程

Ipa Guard是一款功能强大的ipa混淆工具,不需要ios app源码,直接对ipa文件进行混淆加密。可对IOS ipa 文件的代码,代码库,资源文件等进行混淆保护。 可以根据设置对函数名、变量名、类名等关键代码进行重命名和混淆处理,降低代码的可读性,增加ipa破解反编译难度。可以对图片,资源,配置等进行修改名称,修改md5。只要是ipa都可以,不限制OC,Swift,Flutter,React Native,H5类app。

 

 

 

总结

在移动互联网时代,代码混淆越来越受到开发者的重视。 iOS代码混淆可以提高难度,从而防止应用程序被盗用或反编译,保护开发者的权益。但是同时也带来了一些问题,例如混淆后的函数名可能会影响代码的可维护性。因此,在使用代码混淆时需要进行合理规划。

参考资料

  1. IpaGuard文档 - 代码混淆

  2. iOS代码混淆方案

  3. iOS文件混淆方案

  4. iOS重签名与测试

标签:混淆,end,name,text,APP,file,new,path,苹果机
From: https://www.cnblogs.com/sdges/p/17770139.html

相关文章

  • Go - Uploading a File to a Web Application
    Problem: Youwanttouploadafiletoawebapplication. Solution: Usethenet/httppackagetocreateawebapplicationandtheiopackagetoreadthefile. UploadingfilesiscommonlydonethroughHTMLforms.YoulearnedthatHTMLformshaveanencty......
  • 专注二次元的 Niji 模型上线独立 APP;华为整体销量已超越苹果丨 RTE 开发者日报 Vol.68
      开发者朋友们大家好:这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE (RealTimeEngagement) 领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表编辑的个人观点,......
  • iOS代码混淆和加固技术详解
    目录 摘要:本文介绍了iOS开发中常用的代码混淆和加固技术,包括数据加密、应用加壳和代码混淆。其中,重点讨论了代码混淆的实现方法和注意事项,并推荐了一些相关的工具和库。引言代码混淆和加固数据加密应用加壳代码混淆总结参考资料  摘要:本文介绍了iOS开发中常用的......
  • 如何通过代码混淆绕过苹果机审,解决APP被拒问题
     如何通过代码混淆绕过苹果机审,解决APP被拒问题目录 iOS代码混淆功能分析实现流程类名修改方法名修改生成垃圾代码替换png等静态资源MD5info.plist文件添加垃圾字段功能分析实现流程类名修改方法名修改生成垃圾代码替换png等静态资源MD5info.plist文件添加垃......
  • uni-app结合PHP实现单用户登陆demo及解析
    这篇文章主要为大家介绍了uni-app结合PHP实现单用户登陆示例过程详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪单用户登陆uni-appsocket单用户登陆例推送单用户登陆例单用户登陆即在一个应用中,同一个用户只能在线登陆一个,一个用户登陆,在其他设备上会......
  • 开发万岳互联网医院APP:技术要点和关键挑战
    随着移动技术和互联网的飞速发展,互联网医院APP成为医疗领域的一项重要创新。这些应用程序为患者和医生提供了更多便利和互动性,但开发互联网医院APP也伴随着一系列的技术要点和关键挑战。本文将探讨互联网医院APP的技术要点以及在开发过程中需要面对的挑战。一、技术要点1.跨平台开......
  • macOS 如何设置 Finder 打开某种类型的文件时候使用指定的默认 Application 程序 All
    macOS如何设置Finder打开某种类型的文件时候使用指定的默认Application程序AllInOnequestionsolution永久更改用于打开所有特定类型文件的App在Mac上,点按程序坞中的“访达”图标以打开“访达”窗口。选择文件,然后选取“文件”>“显示简介”。还可以按住Contr......
  • 什么是Kappa架构?
    一、简介相当于在Lambda架构上去掉了批处理层(BatchLayer),只留下单独的流处理层(SpeedLayer)。通过消息队列的数据保留功能,来实现上游重放(回溯)能力。当流任务发生代码变动时,或者需要回溯计算时,原先的JobN保持不动,先新启动一个作业JobN+1,从消息队列中获取历史数据,进行计算,计算结......
  • app逆向day03-反编译工具和hook框架
    一反编译工具1.1常见反编译工具常见的反编译工具:jadx(推荐)、jeb、GDA反编译工具依赖于java环境,所以我们按照jdk1.2JDK环境安装#官方地址:(需要注册-最新java21)https://www.oracle.com/java/technologies/downloads/1.2.1win平台安装#1下载jdk-8u371-windows-x64.e......
  • 探究——C# .net 代码混淆/加壳
    背景:保密。过程:先查询一下常见的加壳工具:DotFuscator,官方自带,据说免费版混淆程度不高VirboxProtector,很好很优秀,但是收费NETReactor,可能会被识别为病毒Obfuscar,开源,可以用dotnettool或项目构建的方式进行使用那就先用Obfuscar试试水。方式一:nuget安装(推......