Code Monkey home page Code Monkey logo

stcobfuscator's Introduction

STCObfuscator

STCObfuscator 是用来进行object-c代码混淆的工具,在模拟器DEBUG环境下运行生成混淆宏,
混淆的宏可以在其他环境下进行编译,支持Cocoapod代码混淆.

怎么使用!

相关博客:https://blog.csdn.net/cating1314/article/details/80189295

如果你的工程支持cocoapod,你可以直接添加!
pod "STCObfuscator"(注:请用最新版本,最好更新下master repo)

把下面的代码加入到Appdelegate didFinishLaunchingWithOptions方法里,

#import "STCObfuscator.h"

#if (DEBUG == 1)
    [[STCObfuscator obfuscatorManager] confuseWithRootPath:[NSString stringWithFormat:@"%s", STRING(ROOT_PATH)] resultFilePath:[NSString stringWithFormat:@"%@/STCDefination.h", [NSString stringWithFormat:@"%s", STRING(ROOT_PATH)]] linkmapPath:[NSString stringWithFormat:@"%s", STRING(LINKMAP_FILE)]];
#endif

然后完成下面步骤的设置

image

步骤1、

在 Build Settings->Preprocessor Macros->DEBUG 中添加环境变量
LINKMAP_FILE=$(TARGET_TEMP_DIR)/$(PRODUCT_NAME)-LinkMap-$(CURRENT_VARIANT)-$(CURRENT_ARCH).txt 
和
ROOT_PATH="${SRCROOT}" 
(注:工程尽量不要放在中文路径下)

image

步骤2、

在 Build Settings 开启Write Link Map File, 设置成 YES

image

步骤3、

将下面的脚本添加到 Build Phases
dir=${SRCROOT}
file_count=0
file_list=`ls -R $dir 2> /dev/null | grep -v '^$'`
for file_name in $file_list
do
temp=`echo $file_name | sed 's/:.*$//g'`
if [ "$file_name" != "$temp" ]; then
cur_dir=$temp
else
if [ ${file_name##*.} = a ]; then
    find -P $dir -name $file_name > tmp.txt
    var=$(cat tmp.txt)
    nm $var > ${file_name}.txt
    rm tmp.txt
fi
if [ ${file_name##*.} = framework ]; then
    find -P $dir -name ${file_name%%.*} > tmp.txt
    var=$(cat tmp.txt)
    nm $var > ${file_name}.txt
    rm tmp.txt
    fi
fi
done

image

步骤4、

在预编译文件最前面中添加以下代码
#if (DEBUG != 1)
#import "STCDefination.h"
#endif

image

步骤5、

在DEBUG环境下用模拟器运行工程,在STCDefination.h头文件中生成混淆的宏。
所有的混淆符号会保留在工程目录下的confuse.json。 

image

可用于bug上报后反混淆的文件

image

步骤6、

把工程目录下STCDefination.h头文件加入工程。
混淆后,如果工程增加代码,需要再次混淆,先清空STCDefination.h里面的内容,不能留任何空格和换行,然后pod update,再次在模拟器DEBUG环境下运行。

image

步骤7、

在 RELEASE 环境下运行工程,实现代码混淆。 
混淆前逆向。 

image

混淆后逆向。 

image

English steps ⬇︎

STCObfuscator is an Objective-C obfuscator for Mach-O executables, 
a runtime utility for obfuscating Objective-C class,it also support cocoapod file confusing!

How to use it!

You can use STCObfuscator with cocoapod!
pod "STCObfuscator"
after you add under code to your project

#import "STCObfuscator.h"

#define STRING(str) _STRING(str)
#define _STRING(str) #str

#if (DEBUG == 1)
    [[STCObfuscator obfuscatorManager] confuseWithRootPath:[NSString stringWithFormat:@"%s", STRING(ROOT_PATH)] resultFilePath:[NSString stringWithFormat:@"%@/STCDefination.h", [NSString stringWithFormat:@"%s", STRING(ROOT_PATH)]] linkmapPath:[NSString stringWithFormat:@"%s", STRING(LINKMAP_FILE)]];
#endif

you should finish steps:

step 1、

add 
LINKMAP_FILE=$(TARGET_TEMP_DIR)/$(PRODUCT_NAME)-LinkMap-$(CURRENT_VARIANT)-$(CURRENT_ARCH).txt 
and 
ROOT_PATH="${SRCROOT}" 
to Build Settings Preprocessor Macros 

step 2、

enable Write Link Map File in Build Settings, set YES

step 3、

add shell script to Build Phases
dir=${SRCROOT}
file_count=0
file_list=`ls -R $dir 2> /dev/null | grep -v '^$'`
for file_name in $file_list
do
temp=`echo $file_name | sed 's/:.*$//g'`
if [ "$file_name" != "$temp" ]; then
cur_dir=$temp
else
if [ ${file_name##*.} = a ]; then
    find -P $dir -name $file_name > tmp.txt
    var=$(cat tmp.txt)
    nm $var > ${file_name}.txt
    rm tmp.txt
fi
if [ ${file_name##*.} = framework ]; then
    find -P $dir -name ${file_name%%.*} > tmp.txt
    var=$(cat tmp.txt)
    nm $var > ${file_name}.txt
    rm tmp.txt
    fi
fi
done

step 4、

import STCDefination.h to PrefixHeader File like this:
#if (DEBUG != 1)
#import "STCDefination.h"
#endif

step 5、

run project in DEBUG environment with iPhone simulator to generate confuse macros in STCDefination.h.
all confused symbols will save to confuse.json in project catalog. 

step 6、

add STCDefination.h.

step 7、

run project in RELEASE environment that class confused. 

技术交流或合作讨论请加QQ群

image

stcobfuscator's People

Contributors

chenxiancai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stcobfuscator's Issues

关于use_frameworks!的问题

因为项目中有swift框架, 所以use_frameworks!注释会打开 .
但混淆后发现, STCDefination.h中混淆的代码很少, 发现是*-LinkMap-normal-x86_64.txt这个文件中的内容会少很多, 对于这种情况改怎么做呢?

_cmd会被confuse

[STCObfuscator obfuscatorManager].unConfuseMethodPrefix = @[@"_cmd"]; 加了这行代码解决

混淆不起作用

STCDefination里有值~#ifndef ViewController
#define ViewController STCB8D9CC63982139C987E74954B9F4E4BA
#endif
#ifndef AppDelegate
#define AppDelegate STC31CD7117D188FA25D36B7A95B78E6771
#endif
#ifndef aaaaaa
#define aaaaaa STC5114205405B2108905EFA301C6B4F623
#endif
#ifndef four
#define four STCD6E08330948E51626287C55DACB50D28
#endif
#ifndef two
#define two STCE2F3AD4F81EC158F9F342DD99CD8503B
#endif
#ifndef andArr
#define andArr STCC733FC5835E3ADB01F5AB9AAA10598E3
#endif
#ifndef three
#define three STC6F8C896E3DF0B3F8B986911131582222
#endif

confuse.json里也有值
{
"STCE2F3AD4F81EC158F9F342DD99CD8503B" : "two",
"STC5114205405B2108905EFA301C6B4F623" : "aaaaaa",
"STCD6E08330948E51626287C55DACB50D28" : "four",
"STC6F8C896E3DF0B3F8B986911131582222" : "three",
"STC31CD7117D188FA25D36B7A95B78E6771" : "AppDelegate",
"STCC733FC5835E3ADB01F5AB9AAA10598E3" : "andArr"
}

但是用class-dump导出头文件还是没有加密的

功能建议

建议改为两种混淆过滤类型,使用者可以指定混淆方式:

  1. 指定不混淆各类型
  2. 指定混淆各类型

报错

Cannot find interface declaration for 'STC136EEDC80207AC54395FE017638F49EC'
这种问题怎么解决啊?

接口返回数据解析问题?

model里面的属性混淆了后导致和接口返回的属性名称不一致,故不能正常将json解析成对应的模型,请问该怎么处理。

STCDefination.h中是空的!!

运行后STCDefination.h中只生成了如下代码。没有对应的宏
#if (DEBUG != 1)

//--------------------Obfuscator--------------------

#endif
//------------------------------------------------------

有一点小问题

脚本写的很棒,但好像对于类似于A和A:B这种前半部分方法名相同的方法无法做到一并混淆。

指定目录混淆

这个工具有指定目录进行混淆吗?
例如:
sources:开发的代码
3rd:开源库
不想混淆3rd里面的代码,指定sources所有代码进行混淆。

问题求助

你给的Demo跑了下 能生成代码,但是编译报错了
"OBJC_CLASS$_STC8D66EE30C77FC994D030F531F686D1CD", referenced from:
objc-class-ref in AppDelegate.o

是由于 混淆后
#ifndef AFHTTPSessionManager
#define AFHTTPSessionManager STC8D66EE30C77FC994D030F531F686D1CD
#endif
找不到对应的类,这种问是要把类名也要搞成“_STC8D66......” 吗?

加入付费群沟通

关于代码混淆、苹果过审是一个经验问题,沟通了很多群,大都没有人解答,建了一个红包群,欢迎大咖过来分享领红包,小咖红包付费咨询。加我wanxsb拉你入群
4171541041309_ pic

cocoapods里的pod支持有问题

我是用cocoapods搭建的项目,其中一个pod用作所有model集合,但是发现总是报错 property xxx not found on object of type xxx。
后来确实没办法了,在pod里的model头文件都加上了混淆的define
才编译通过,想请教下楼主原理。有没有不那么笨拙的方法

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.