1. Create a new related file
Create a new file confuse.sh
and func.list
create a file as follows:
$ cd ~/Desktop/ceshi
$ touch confuse.sh
$ touch func.list
The final result is as follows:
2. Import the file into the project
Import the created confuse.sh
files and func.list
files into the project
The final result is as follows
3. Modify project configuration
3.1 Modify the TARGETS configuration
If not RunScript
. Please click in the red box +
to add
RunScript
the text entered in it
$PROJECT_DIR/confuse.sh
3.2 Modify the instruction file
3.2.1 Open confuse.sh
the file, copy and paste the text
#!/usr/bin/env bash
TABLENAME=symbols
SYMBOL_DB_FILE="symbols"
STRING_SYMBOL_FILE="func.list"
HEAD_FILE="$PROJECT_DIR/$PROJECT_NAME/codeObfuscation.h"
export LC_CTYPE=C
#维护数据库方便日后作排重
createTable()
{
echo "create table $TABLENAME(src text, des text);" | sqlite3 $SYMBOL_DB_FILE
}
insertValue()
{
echo "insert into $TABLENAME values('$1' ,'$2');" | sqlite3 $SYMBOL_DB_FILE
}
query()
{
echo "select * from $TABLENAME where src='$1';" | sqlite3 $SYMBOL_DB_FILE
}
ramdomString()
{
openssl rand -base64 64 | tr -cd 'a-zA-Z' |head -c 16
}
rm -f $SYMBOL_DB_FILE
rm -f $HEAD_FILE
createTable
touch $HEAD_FILE
echo '#ifndef Demo_codeObfuscation_h
#define Demo_codeObfuscation_h' >> $HEAD_FILE
echo "//confuse string at `date`" >> $HEAD_FILE
cat "$STRING_SYMBOL_FILE" | while read -ra line; do
if [[ ! -z "$line" ]]; then
ramdom=`ramdomString`
echo $line $ramdom
insertValue $line $ramdom
echo "#define $line $ramdom" >> $HEAD_FILE
fi
done
echo "#endif" >> $HEAD_FILE
sqlite3 $SYMBOL_DB_FILE .dump
3.2.2 Modify command file permissions
$ cd ~/Desktop/ceshi
$ chmod 755 confuse.sh
3.3 Modify the method name file that needs to be confused
Open func.list
the file and enter the method name that needs to be confused with the method name in the file.
The example is as follows:
imageCompress
blurImage
viewDidLoad
3.4 Modify pch
file configuration
1. If there is no PrefixHeader.pch
such file, you need to create a new one
. 2. Open PrefixHeader.pch
the file,
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
// Include any system framework and library headers here that should be included in all compilation units.
#import "CodeObfuscation.h"
#endif /* PrefixHeader_pch */
4. Operation effect
runcom+B