Swift_code obfuscation

1. Create a new related file

Create a new file confuse.shand func.list
create a file as follows:

$ cd ~/Desktop/ceshi
$ touch confuse.sh
$ touch func.list

The final result is as follows:
insert image description here

2. Import the file into the project

Import the created confuse.shfiles and func.listfiles into the project
The final result is as follows
insert image description here

3. Modify project configuration

3.1 Modify the TARGETS configuration

If not RunScript. Please click in the red box +to add
insert image description here
RunScriptthe text entered in it

$PROJECT_DIR/confuse.sh

3.2 Modify the instruction file

3.2.1 Open confuse.shthe 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.listthe 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 pchfile configuration

1. If there is no PrefixHeader.pchsuch file, you need to create a new one
. 2. Open PrefixHeader.pchthe 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
insert image description here

Guess you like

Origin blog.csdn.net/FlyingKuiKui/article/details/121518553